@kenyaemr/esm-care-panel-app 5.4.2-pre.2777 → 5.4.2-pre.2788
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/267.js +1 -1
- package/dist/267.js.map +1 -1
- package/dist/{661.js → 574.js} +1 -1
- package/dist/574.js.map +1 -0
- package/dist/648.js +1 -0
- package/dist/648.js.map +1 -0
- package/dist/kenyaemr-esm-care-panel-app.js +3 -3
- package/dist/kenyaemr-esm-care-panel-app.js.buildmanifest.json +40 -40
- package/dist/main.js +19 -19
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/care-programs/care-program.resource.ts +69 -1
- package/src/care-programs/care-programs.component.tsx +44 -46
- package/src/care-programs/kvp-patient-peer-form.scss +36 -0
- package/src/care-programs/kvp-peer-linkage-form.workspace.tsx +183 -0
- package/src/care-programs/kvp-program-actions.resource.ts +91 -0
- package/src/care-programs/link-patient-to-peer-action.component.tsx +70 -0
- package/src/care-programs/program-form-overflow-menu-item.component.tsx +108 -0
- package/src/care-programs/useCareProgramForms.ts +9 -1
- package/src/config-schema.ts +295 -45
- package/src/index.ts +2 -0
- package/src/routes.json +8 -2
- package/dist/324.js +0 -1
- package/dist/324.js.map +0 -1
- package/dist/661.js.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { InlineLoading, OverflowMenuItem } from '@carbon/react';
|
|
2
|
+
import { launchWorkspace, showSnackbar, useConfig, Visit } from '@openmrs/esm-framework';
|
|
3
|
+
import { launchStartVisitPrompt } from '@openmrs/esm-patient-common-lib';
|
|
4
|
+
import React, { FC, useEffect, useMemo } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { CarePanelConfig } from '../config-schema';
|
|
7
|
+
import { useFormsFilled, usePatientFormEncounter } from './care-program.resource';
|
|
8
|
+
import KvpLinkPatientToPeerEducator from './link-patient-to-peer-action.component';
|
|
9
|
+
|
|
10
|
+
type ProgramFormOverflowMenuItemProps = {
|
|
11
|
+
patientUuid: string;
|
|
12
|
+
form: CarePanelConfig['careProgramForms'][0]['forms'][0];
|
|
13
|
+
mutate?: () => void;
|
|
14
|
+
visit?: Visit;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ProgramFormOverflowMenuItem: FC<ProgramFormOverflowMenuItemProps> = ({
|
|
18
|
+
form,
|
|
19
|
+
patientUuid,
|
|
20
|
+
mutate,
|
|
21
|
+
visit: currentVisit,
|
|
22
|
+
}) => {
|
|
23
|
+
const {
|
|
24
|
+
formEncounters,
|
|
25
|
+
error,
|
|
26
|
+
isLoading,
|
|
27
|
+
mutate: mutateFormEncounters,
|
|
28
|
+
} = usePatientFormEncounter(patientUuid, form.formUuId);
|
|
29
|
+
const { hideFilledProgramForm, peerCalendarOutreactForm } = useConfig<CarePanelConfig>();
|
|
30
|
+
const { t } = useTranslation();
|
|
31
|
+
const {
|
|
32
|
+
error: formFilledError,
|
|
33
|
+
formsFilled: areAllDependancyFormsFilled,
|
|
34
|
+
isLoading: isLoadingDependancyStatus,
|
|
35
|
+
mutate: mutateDependancyStatus,
|
|
36
|
+
} = useFormsFilled(patientUuid, form.dependancies);
|
|
37
|
+
|
|
38
|
+
const latestFormEncounter = useMemo(() => formEncounters.at(0)?.encounter?.uuid, [formEncounters]);
|
|
39
|
+
// Show form if
|
|
40
|
+
// 1. Form is not yet filled AND (Form Has no dependancies OR Form has dependancies that are all filled)
|
|
41
|
+
// 2. Form is filled already AND hideFilledProgramForm is configured to false (else launch in edit mode)
|
|
42
|
+
const showForm = useMemo(() => {
|
|
43
|
+
// !latestFormEncounter -> current form is not yet filled
|
|
44
|
+
if (!latestFormEncounter && (!form?.dependancies?.length || areAllDependancyFormsFilled)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (latestFormEncounter && !hideFilledProgramForm) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}, [areAllDependancyFormsFilled, form?.dependancies?.length, hideFilledProgramForm, latestFormEncounter]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (error || formFilledError) {
|
|
55
|
+
showSnackbar({ kind: 'error', title: t('error', 'Error'), subtitle: (error ?? formFilledError)?.message });
|
|
56
|
+
}
|
|
57
|
+
}, [error, formFilledError, t]);
|
|
58
|
+
|
|
59
|
+
if (isLoading || isLoadingDependancyStatus) {
|
|
60
|
+
return <InlineLoading />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!showForm) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (form.formUuId === peerCalendarOutreactForm) {
|
|
68
|
+
return (
|
|
69
|
+
<KvpLinkPatientToPeerEducator
|
|
70
|
+
form={form}
|
|
71
|
+
patientUuid={patientUuid}
|
|
72
|
+
visit={currentVisit}
|
|
73
|
+
mutate={() => {
|
|
74
|
+
mutate?.();
|
|
75
|
+
mutateDependancyStatus();
|
|
76
|
+
mutateFormEncounters();
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<OverflowMenuItem
|
|
84
|
+
key={form.formUuId}
|
|
85
|
+
itemText={form.formName}
|
|
86
|
+
onClick={() => {
|
|
87
|
+
if (currentVisit) {
|
|
88
|
+
return launchWorkspace('patient-form-entry-workspace', {
|
|
89
|
+
workspaceTitle: form.formName,
|
|
90
|
+
mutateForm: () => {
|
|
91
|
+
mutate?.();
|
|
92
|
+
mutateDependancyStatus();
|
|
93
|
+
mutateFormEncounters();
|
|
94
|
+
},
|
|
95
|
+
formInfo: {
|
|
96
|
+
encounterUuid: latestFormEncounter ?? '',
|
|
97
|
+
formUuid: form.formUuId,
|
|
98
|
+
// additionalProps: { enrollmenrDetails: careProgram.enrollmentDetails ?? {} },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
launchStartVisitPrompt();
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default ProgramFormOverflowMenuItem;
|
|
@@ -14,7 +14,15 @@ const useCareProgramForms = () => {
|
|
|
14
14
|
},
|
|
15
15
|
[careProgramForms],
|
|
16
16
|
);
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
const getProgramEnrollmentForm = useCallback(
|
|
19
|
+
(programUuid: string) => {
|
|
20
|
+
const forms = getProgramForms(programUuid);
|
|
21
|
+
return forms.find((form) => form.isEnrollment);
|
|
22
|
+
},
|
|
23
|
+
[getProgramForms],
|
|
24
|
+
);
|
|
25
|
+
return { careProgramForms, getProgramForms, getProgramEnrollmentForm };
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
export default useCareProgramForms;
|