From 797b7d11aca1075de5c872c0fa706c299022df3f Mon Sep 17 00:00:00 2001 From: GenaRazmakhnin Date: Mon, 17 Jul 2023 20:26:41 +0200 Subject: [PATCH] workflow demo --- examples/apps/workflow-ui/src/app.tsx | 151 +++++++++++++--------- examples/apps/workflow-ui/src/context.tsx | 8 +- examples/index.ts | 10 ++ examples/zen-project/zen-package.edn | 3 +- examples/zen-project/zrc/system.edn | 2 +- 5 files changed, 105 insertions(+), 69 deletions(-) create mode 100644 examples/index.ts diff --git a/examples/apps/workflow-ui/src/app.tsx b/examples/apps/workflow-ui/src/app.tsx index 3a7cf75..84ad322 100644 --- a/examples/apps/workflow-ui/src/app.tsx +++ b/examples/apps/workflow-ui/src/app.tsx @@ -1,50 +1,50 @@ -import { Container, Link, Text } from "@nextui-org/react"; -import { Client } from "aidbox-sdk"; -import { useState } from "react"; -import { io } from "socket.io-client"; +import { Container, Link, Text } from '@nextui-org/react' +import { Client } from 'aidbox-sdk' +import { useEffect, useState } from 'react' +import { Socket, io } from 'socket.io-client' -import { SampleDesc } from "./SampleDesc"; -import { Tasks } from "./Tasks"; -import { WorkflowSchema } from "./WorkflowSchema"; -import { AppContext } from "./context"; +import { AppContext } from './context' +import { SampleDesc } from './SampleDesc' +import { Tasks } from './Tasks' +import { WorkflowSchema } from './WorkflowSchema' const appointmentData = { - resourceType: "Appointment", - status: "booked", - description: "Discussion on the results of your recent MRI", - start: "2030-12-10T09:00:00Z", - end: "2030-12-10T11:00:00Z", - created: "2023-10-10", + resourceType: 'Appointment', + status: 'booked', + description: 'Discussion on the results of your recent MRI', + start: '2030-12-10T09:00:00Z', + end: '2030-12-10T11:00:00Z', + created: '2023-10-10', participant: [ { actor: { - reference: "Patient/03cb8799-bfbd-40fa-9ea8-96114cf1fec1", - display: "Peter James Chalmers", + reference: 'Patient/03cb8799-bfbd-40fa-9ea8-96114cf1fec1', + display: 'Peter James Chalmers' }, - status: "accepted", - }, - ], -}; + status: 'accepted' + } + ] +} const patientData = { name: [ { - given: ["Peter", "James"], - family: "Chalmers", - }, + given: ['Peter', 'James'], + family: 'Chalmers' + } ], telecom: [ { - value: "", - system: "email", - }, + value: '', + system: 'email' + } ], - id: "03cb8799-bfbd-40fa-9ea8-96114cf1fec1", - resourceType: "Patient", -}; + id: '03cb8799-bfbd-40fa-9ea8-96114cf1fec1', + resourceType: 'Patient' +} -export function App({ - config, +export function App ({ + config }: { config: { app_url: string; @@ -53,18 +53,26 @@ export function App({ aidbox_secret: string; }; }) { - const [appointmentId, setAppointmentId] = useState(null); + const [appointmentId, setAppointmentId] = useState(null) + const [aidboxClient, setClient] = useState() + const [socketIo, setSocket] = useState() - const aidboxClient = new Client(config.aidbox_url, { - username: config.aidbox_client, - password: config.aidbox_secret, - }); + useEffect(() => { + const aidboxClient = new Client(config.aidbox_url, { + username: config.aidbox_client, + password: config.aidbox_secret + }) - const socketIo = io(config.app_url, { - auth: { - token: "json-web-token", - }, - }); + setClient(aidboxClient) + + const socketIo = io(config.app_url, { + auth: { + token: 'json-web-token' + } + }) + + setSocket(socketIo) + }, []) const createAppointment = async (email: string) => { const patient = { @@ -72,43 +80,57 @@ export function App({ telecom: [ { value: email, - system: "email", - }, - ], - }; + system: 'email' + } + ] + } - await aidboxClient.client.put(`/Patient/${patient.id}`, patient); - const data = await aidboxClient.createResource( - "Appointment", - appointmentData - ); + if (aidboxClient) { + await aidboxClient.client.put(`/Patient/${patient.id}`, patient) + const data = await aidboxClient.createResource( + 'Appointment', + appointmentData + ) - if (data.id) { - setAppointmentId(data.id); + if (data.id) { + setAppointmentId(data.id) + } } - }; + } + + if (!aidboxClient || !socketIo) return null return ( - - + + Aidbox Workflow Engine - + Workflow allows orchestrating a series of  tasks . Workflow in Aidbox is implemented through a special  decision - {" "} + {' '} task, an instance of which is created on every event of workflow, thus a logic behind workflow could be implemented as an executor for this task. @@ -121,10 +143,13 @@ export function App({ {appointmentId && ( <> - + )} - ); + ) } diff --git a/examples/apps/workflow-ui/src/context.tsx b/examples/apps/workflow-ui/src/context.tsx index d033ee8..f6b6c54 100644 --- a/examples/apps/workflow-ui/src/context.tsx +++ b/examples/apps/workflow-ui/src/context.tsx @@ -1,10 +1,10 @@ -import { Client } from "aidbox-sdk"; -import { createContext } from "react"; -import { Socket } from "socket.io-client"; +import { Client } from 'aidbox-sdk' +import { createContext } from 'react' +import { Socket } from 'socket.io-client' export type AppContextType = { client: Client; socketIo: Socket; }; -export const AppContext = createContext({} as AppContextType); +export const AppContext = createContext({} as AppContextType) diff --git a/examples/index.ts b/examples/index.ts new file mode 100644 index 0000000..43cf9f9 --- /dev/null +++ b/examples/index.ts @@ -0,0 +1,10 @@ +import { Client } from 'aidbox-sdk' + +const aidbox = new Client( + 'https://genaproject.aidbox.app/', + { username: 'client-name', password: 'secret' } +) + +const patient = await aidbox.getResource('Patient', '03cb8799-bfbd-40fa-9ea8-96114cf1fec1') + +console.log(patient) diff --git a/examples/zen-project/zen-package.edn b/examples/zen-project/zen-package.edn index f9dfe8d..d982d51 100644 --- a/examples/zen-project/zen-package.edn +++ b/examples/zen-project/zen-package.edn @@ -1,2 +1,3 @@ {:deps {hl7-fhir-r4-core "https://github.com/zen-fhir/hl7-fhir-r4-core.git" - sdc "https://github.com/Aidbox/sdc-forms-library.git"}} \ No newline at end of file + sdc "https://github.com/Aidbox/sdc-forms-library.git" + loinc "git@github.com:zen-fhir/loinc.git"}} \ No newline at end of file diff --git a/examples/zen-project/zrc/system.edn b/examples/zen-project/zrc/system.edn index 0604e8f..403cd13 100644 --- a/examples/zen-project/zrc/system.edn +++ b/examples/zen-project/zrc/system.edn @@ -1,5 +1,5 @@ {:ns system - import #{aidbox appointment-trigger notification hl7-fhir-r4-core aidbox.forms awf.workflow awf.task} + import #{aidbox loinc appointment-trigger notification hl7-fhir-r4-core aidbox.forms awf.workflow awf.task} admin-user-seed {:zen/tags #{aidbox/service}