Skip to content

Commit

Permalink
(feat) Add session and cohort identifiers for group sessions (#72)
Browse files Browse the repository at this point in the history
* (feat) Add session and cohort identifiers for group sessions)

* (chore) session identifiers refactor
  • Loading branch information
icrc-jofrancisco authored Mar 25, 2024
1 parent 0443a9e commit e901873
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ export const configSchema = {
_description: "UUID of concept for Session Notes",
_default: "fa8fedc0-c066-4da3-8dc1-2ad8621fc480",
},
cohortId: {
_type: Type.UUID,
_description: "UUID of concept for cohort identifier",
_default: "5461f231-7e59-4be8-93a4-6d49fd13c00a",
},
cohortName: {
_type: Type.UUID,
_description: "UUID of concept for cohort name",
_default: "6029f289-92a6-4a68-80f1-3078d0152449",
},
sessionUuid: {
_type: Type.UUID,
_description: "UUID of concept for session identifier",
_default: "6a803908-8a5b-4598-adea-19358c83529a",
},
},
specificQuestions: {
_type: Type.Array,
Expand Down
4 changes: 4 additions & 0 deletions src/context/GroupFormWorkflowContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const initialWorkflowState = {
workflowState: null, // pseudo field from state[activeFormUuid].workflowState
activePatientUuid: null, // pseudo field from state[activeFormUuid].activePatientUuid
activeEncounterUuid: null, // pseudo field from state[activeFormUuid].activeEncounterUuid
activeSessionUuid: null, // pseudo field from state[activeFormUuid].activeSessionUuid
activeVisitUuid: null, // pseudo field from state[activeFormUuid].activeVisitUuid
patientUuids: [], // pseudo field from state[activeFormUuid].patientUuids
encounters: {}, // pseudo field from state[activeFormUuid].encounters
Expand Down Expand Up @@ -138,6 +139,9 @@ const GroupFormWorkflowProvider = ({ children }) => {
workflowState:
state.forms?.[state.activeFormUuid]?.workflowState ??
initialWorkflowState.workflowState,
activeSessionUuid:
state.forms?.[state.activeFormUuid]?.activeSessionUuid ??
initialWorkflowState.activeSessionUuid,
activePatientUuid:
state.forms?.[state.activeFormUuid]?.activePatientUuid ??
initialWorkflowState.activePatientUuid,
Expand Down
10 changes: 10 additions & 0 deletions src/context/GroupFormWorkflowReducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { navigate } from "@openmrs/esm-framework";
import { initialWorkflowState } from "./FormWorkflowContext";
import { v4 as uuid } from "uuid";

export const fdeGroupWorkflowStorageVersion = "1.0.5";
export const fdeGroupWorkflowStorageName =
Expand All @@ -19,6 +20,7 @@ const initialFormState = {
activePatientUuid: null,
activeEncounterUuid: null,
activeVisitUuid: null,
activeSessionUuid: null,
patientUuids: [],
encounters: {},
visits: {},
Expand All @@ -45,6 +47,7 @@ const reducer = (state, action) => {
thisSavedForm?.patientUuids?.[0] ||
// something probably went wrong...
null;
const activeSessionUuid = thisSavedForm?.activeSessionUuid || uuid();
newState = {
...savedDataObject,
// set current form to this one
Expand All @@ -60,6 +63,7 @@ const reducer = (state, action) => {
thisSavedForm?.encounters?.[activePatientUuid] || null,
activeVisitUuid:
thisSavedForm?.visits?.[activePatientUuid] || null,
activeSessionUuid: activeSessionUuid,
},
},
};
Expand Down Expand Up @@ -102,6 +106,7 @@ const reducer = (state, action) => {
activePatientUuid: null,
activeEncounterUuid: null,
activeVisitUuid: null,
activeSessionUuid: null,
},
},
};
Expand All @@ -122,6 +127,7 @@ const reducer = (state, action) => {
activePatientUuid: null,
activeEncounterUuid: null,
activeVisitUuid: null,
activeSessionUuid: null,
},
},
};
Expand All @@ -147,6 +153,7 @@ const reducer = (state, action) => {
state.forms[state.activeFormUuid].visits[
state.forms[state.activeFormUuid].patientUuids?.[0]
] || null,
activeSessionUuid: uuid(),
workflowState: "EDIT_FORM",
},
},
Expand Down Expand Up @@ -230,6 +237,7 @@ const reducer = (state, action) => {
activePatientUuid: nextPatientUuid,
activeEncounterUuid: thisForm.encounters[nextPatientUuid] || null,
activeVisitUuid: thisForm.visits[nextPatientUuid] || null,
activeSessionUuid: thisForm.activeSessionUuid,
workflowState: "EDIT_FORM",
},
},
Expand All @@ -250,6 +258,7 @@ const reducer = (state, action) => {
activeVisitUuid:
state.forms[state.activeFormUuid].visits[action.patientUuid],
activePatientUuid: action.patientUuid,
activeSessionUuid: action.activeSessionUuid,
workflowState: "EDIT_FORM",
},
},
Expand Down Expand Up @@ -393,6 +402,7 @@ const reducer = (state, action) => {
activeEncounterUuid: null,
activVisitUuid: null,
activePatientUuid: null,
activeSessionUuid: null,
workflowState: "REVIEW",
},
},
Expand Down
26 changes: 22 additions & 4 deletions src/group-form-entry-workflow/GroupSessionWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const GroupSessionWorkspace = () => {
activeEncounterUuid,
activeVisitUuid,
activeFormUuid,
activeGroupUuid,
activeGroupName,
activeSessionUuid,
saveEncounter,
activeSessionMeta,
groupVisitTypeUuid,
Expand Down Expand Up @@ -125,11 +128,23 @@ const GroupSessionWorkspace = () => {
const visitUuid = activeVisitUuid ? activeVisitUuid : uuid();
if (!activeVisitUuid) {
Object.entries(groupSessionConcepts).forEach(([field, uuid]) => {
payload.obs.push({
concept: uuid,
value: activeSessionMeta?.[field],
});
if (activeSessionMeta?.[field] != null) {
payload.obs.push({
concept: uuid,
value: activeSessionMeta[field],
});
}
});

const otherIdentifiers = [
{ concept: groupSessionConcepts.cohortId, value: activeGroupUuid },
{ concept: groupSessionConcepts.cohortName, value: activeGroupName },
{
concept: groupSessionConcepts.sessionUuid,
value: activeSessionUuid,
},
];
payload.obs.push(...otherIdentifiers);
// If this is a newly created encounter and visit, add session concepts to encounter payload.
const visitInfo = {
startDatetime: activeSessionMeta.sessionDate,
Expand All @@ -156,6 +171,9 @@ const GroupSessionWorkspace = () => {
activeVisitUuid,
sessionLocation?.uuid,
groupSessionConcepts,
activeGroupUuid,
activeGroupName,
activeSessionUuid,
activePatientUuid,
groupVisitTypeUuid,
updateVisitUuid,
Expand Down

0 comments on commit e901873

Please sign in to comment.