Skip to content

Commit

Permalink
workflow demo
Browse files Browse the repository at this point in the history
  • Loading branch information
GenaRazmakhnin committed Jul 17, 2023
1 parent 5b55f44 commit 797b7d1
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 69 deletions.
151 changes: 88 additions & 63 deletions examples/apps/workflow-ui/src/app.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -53,62 +53,84 @@ export function App({
aidbox_secret: string;
};
}) {
const [appointmentId, setAppointmentId] = useState<string | null>(null);
const [appointmentId, setAppointmentId] = useState<string | null>(null)
const [aidboxClient, setClient] = useState<Client>()
const [socketIo, setSocket] = useState<Socket>()

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 = {
...patientData,
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 (
<AppContext.Provider value={{ client: aidboxClient, socketIo }}>
<Container display="flex" direction="column" alignContent="center">
<Text h1 css={{ "text-align": "center" }}>
<Container
display='flex'
direction='column'
alignContent='center'
>
<Text
h1
css={{ 'text-align': 'center' }}
>
Aidbox Workflow Engine
</Text>
<Text css={{ "text-align": "center", px: "60px" }} size="$xl">
<Text
css={{ 'text-align': 'center', 'px': '60px' }}
size='$xl'
>
Workflow allows orchestrating a series of&nbsp;
<Link
href="https://docs.aidbox.app/modules-1/workflow-engine/task"
target="_blank"
href='https://docs.aidbox.app/modules-1/workflow-engine/task'
target='_blank'
>
tasks
</Link>
. Workflow in Aidbox is implemented through a special&nbsp;
<Link
href="https://docs.aidbox.app/modules-1/workflow-engine/task/aidbox-predefined-tasks#awf.workflow-decision-task"
target="_blank"
href='https://docs.aidbox.app/modules-1/workflow-engine/task/aidbox-predefined-tasks#awf.workflow-decision-task'
target='_blank'
>
decision
</Link>{" "}
</Link>{' '}
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.
Expand All @@ -121,10 +143,13 @@ export function App({
{appointmentId && (
<>
<WorkflowSchema />
<Tasks appointmentId={appointmentId} config={config} />
<Tasks
appointmentId={appointmentId}
config={config}
/>
</>
)}
</Container>
</AppContext.Provider>
);
)
}
8 changes: 4 additions & 4 deletions examples/apps/workflow-ui/src/context.tsx
Original file line number Diff line number Diff line change
@@ -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<AppContextType>({} as AppContextType);
export const AppContext = createContext<AppContextType>({} as AppContextType)
10 changes: 10 additions & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion examples/zen-project/zen-package.edn
Original file line number Diff line number Diff line change
@@ -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"}}
sdc "https://github.com/Aidbox/sdc-forms-library.git"
loinc "git@github.com:zen-fhir/loinc.git"}}
2 changes: 1 addition & 1 deletion examples/zen-project/zrc/system.edn
Original file line number Diff line number Diff line change
@@ -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}
Expand Down

0 comments on commit 797b7d1

Please sign in to comment.