@kenyaemr/esm-care-panel-app 5.4.2 → 5.4.3-pre.2919

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/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"kenyaemr":"^19.0.0"},"pages":[],"extensions":[{"name":"care-panel-patient-summary","component":"carePanelPatientSummary","slot":"patient-chart-care-panel-dashboard-slot","order":10,"meta":{"columnSpan":4}},{"name":"care-panel-summary-dashboard-link","component":"carePanelSummaryDashboardLink","order":3,"meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-care-panel-dashboard-slot","layoutMode":"anchored","path":"Care panel"}},{"name":"delete-regimen-confirmation-dialog","component":"deleteRegimenConfirmationDialog"},{"name":"hiv-patient-visit-summary-dashboard-link","component":"hivPatientSummaryDashboardLink","slot":"hiv-care-and-treatment-slot","meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-hiv-patient-summary-slot","path":"HIV Patient Summary","layoutMode":"anchored"}},{"name":"hiv-patient-visit-summary","slot":"hiv-patient-summary-slot","component":"hivPatientSummary","order":3,"online":true,"offline":false},{"name":"dispensing-patient-vitals","component":"dispensingPaentientVitals","slot":"dispensing-condition-and-diagnoses","order":1,"online":true,"offline":true},{"name":"patient-discharge-side-rail-icon","component":"patientDischargeSideRailIcon","slot":"action-menu-ward-patient-items-slot"}],"workspaces":[{"name":"patient-regimen-workspace","title":"Patient Regimen","component":"regimenFormWorkspace","type":"form","canMaximize":true,"canHide":true,"width":"wider"},{"name":"patient-care-discharge-workspace","title":"Patient Discharge","component":"patientDischargeWorkspace","type":"workspace","canMaximize":true,"canHide":true,"width":"extra-wide","groups":["ward-patient"]},{"name":"mch-program-form-workspace","component":"mchProgramForm","title":"Program Form","type":"workspace"},{"name":"kvp-peer-linkage-form-workspace","component":"kvpPeerLinkageForm","title":"Program Form","type":"workspace"}],"version":"5.4.2"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"kenyaemr":"^19.0.0"},"pages":[],"extensions":[{"name":"care-panel-patient-summary","component":"carePanelPatientSummary","slot":"patient-chart-care-panel-dashboard-slot","order":10,"meta":{"columnSpan":4}},{"name":"care-panel-summary-dashboard-link","component":"carePanelSummaryDashboardLink","order":3,"meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-care-panel-dashboard-slot","layoutMode":"anchored","path":"Care panel"}},{"name":"delete-regimen-confirmation-dialog","component":"deleteRegimenConfirmationDialog"},{"name":"hiv-patient-visit-summary-dashboard-link","component":"hivPatientSummaryDashboardLink","slot":"hiv-care-and-treatment-slot","meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-hiv-patient-summary-slot","path":"HIV Patient Summary","layoutMode":"anchored"}},{"name":"hiv-patient-visit-summary","slot":"hiv-patient-summary-slot","component":"hivPatientSummary","order":3,"online":true,"offline":false},{"name":"dispensing-patient-vitals","component":"dispensingPaentientVitals","slot":"dispensing-condition-and-diagnoses","order":1,"online":true,"offline":true},{"name":"patient-discharge-side-rail-icon","component":"patientDischargeSideRailIcon","slot":"action-menu-ward-patient-items-slot"}],"workspaces":[{"name":"patient-regimen-workspace","title":"Patient Regimen","component":"regimenFormWorkspace","type":"form","canMaximize":true,"canHide":true,"width":"wider"},{"name":"patient-care-discharge-workspace","title":"Patient Discharge","component":"patientDischargeWorkspace","type":"workspace","canMaximize":true,"canHide":true,"width":"extra-wide","groups":["ward-patient"]},{"name":"mch-program-form-workspace","component":"mchProgramForm","title":"Program Form","type":"workspace"},{"name":"kvp-peer-linkage-form-workspace","component":"kvpPeerLinkageForm","title":"Program Form","type":"workspace"}],"version":"5.4.3-pre.2919"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenyaemr/esm-care-panel-app",
3
- "version": "5.4.2",
3
+ "version": "5.4.3-pre.2919",
4
4
  "description": "Patient care panels microfrontend for the OpenMRS SPA",
5
5
  "keywords": [
6
6
  "openmrs"
@@ -47,5 +47,6 @@
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
50
- }
50
+ },
51
+ "stableVersion": "5.4.2"
51
52
  }
@@ -6,6 +6,7 @@ import {
6
6
  restBaseUrl,
7
7
  showModal,
8
8
  useConfig,
9
+ Visit,
9
10
  } from '@openmrs/esm-framework';
10
11
  import dayjs from 'dayjs';
11
12
  import useSWR, { mutate } from 'swr';
@@ -74,7 +75,9 @@ export const usePatientEnrolledPrograms = (patientUuid: string) => {
74
75
  const { data, error, isLoading, mutate } = useSWR<FetchResponse<{ results: Array<Enrollement> }>>(url, openmrsFetch);
75
76
  const enrollments = useMemo(() => {
76
77
  const allEnrollments = data?.data?.results ?? [];
77
- return allEnrollments.filter((enrollment) => !excludedCarePrograms.includes(enrollment.program.uuid));
78
+ return allEnrollments.filter(
79
+ (enrollment) => !excludedCarePrograms.includes(enrollment.program.uuid) && !enrollment.dateCompleted,
80
+ );
78
81
  }, [data, excludedCarePrograms]);
79
82
  return {
80
83
  isLoading,
@@ -110,14 +113,23 @@ type FormEncounter = {
110
113
  };
111
114
  };
112
115
 
113
- export const usePatientFormEncounter = (patientUuid: string, formUuid: string) => {
116
+ type UsePatientFormEncountersOptions = { scope: 'all-visits' } | { scope: 'current-visit'; currentVisit?: Visit };
117
+
118
+ export const usePatientFormEncounter = (
119
+ patientUuid: string,
120
+ formUuid: string,
121
+ options: UsePatientFormEncountersOptions = { scope: 'all-visits' },
122
+ ) => {
114
123
  const url = `${restBaseUrl}/kenyaemr/encountersByPatientAndForm?patientUuid=${patientUuid}&formUuid=${formUuid}`;
115
124
  const { data, error, isLoading, mutate } = useSWR<FetchResponse<{ results: Array<FormEncounter> }>>(
116
- url,
125
+ options?.scope === 'current-visit' ? null : url,
117
126
  openmrsFetch,
118
127
  );
119
- return {
120
- formEncounters: (data?.data?.results ?? [])
128
+ const formEncounters = useMemo(() => {
129
+ if (options.scope !== 'all-visits') {
130
+ return [];
131
+ }
132
+ return (data?.data?.results ?? [])
121
133
  .map((data) => ({
122
134
  ...data,
123
135
  encounter: {
@@ -125,7 +137,32 @@ export const usePatientFormEncounter = (patientUuid: string, formUuid: string) =
125
137
  encounterDatetime: parseDate(data.encounter.encounterDatetime),
126
138
  },
127
139
  }))
128
- .sort((a, b) => dayjs(b.encounter.encounterDatetime).diff(dayjs(a.encounter.encounterDatetime))),
140
+ .sort((a, b) => dayjs(b.encounter.encounterDatetime).diff(dayjs(a.encounter.encounterDatetime)));
141
+ }, [data, options]);
142
+ const formEncountersInCurrentVisit = useMemo(() => {
143
+ if (options.scope !== 'current-visit') {
144
+ return [];
145
+ }
146
+ return (options.currentVisit?.encounters ?? [])
147
+ .filter((encounter) => encounter.form?.uuid === formUuid)
148
+ .map((encounter) => ({
149
+ encounter: {
150
+ encounterDatetime: parseDate(encounter.encounterDatetime),
151
+ uuid: encounter.uuid!,
152
+ id: encounter.id!,
153
+ encounterType: encounter.encounterType!.uuid,
154
+ dateCreated: encounter.dateCreated!,
155
+ },
156
+ form: {
157
+ uuid: encounter.form!.uuid,
158
+ name: encounter.form!.name,
159
+ },
160
+ }))
161
+ .sort((a, b) => dayjs(b.encounter.encounterDatetime).diff(dayjs(a.encounter.encounterDatetime)));
162
+ }, [options, formUuid]);
163
+
164
+ return {
165
+ formEncounters: options.scope === 'all-visits' ? formEncounters : formEncountersInCurrentVisit,
129
166
  error,
130
167
  isLoading,
131
168
  mutate,
@@ -133,23 +170,26 @@ export const usePatientFormEncounter = (patientUuid: string, formUuid: string) =
133
170
  };
134
171
 
135
172
  export const useFormsFilled = (patientUuid: string, formUuids: Array<string> = []) => {
136
- const url = `${restBaseUrl}/kenyaemr/encountersByPatientAndForm?patientUuid=${patientUuid}&formUuid=${formUuids.join(
137
- ',',
138
- )}`;
139
-
140
- const { data, error, mutate, isLoading } = useSWR(url, async (uri) => {
141
- const tasks = await Promise.allSettled(
142
- formUuids.map((formUuid) =>
143
- openmrsFetch<{ results: Array<FormEncounter> }>(
144
- `${restBaseUrl}/kenyaemr/encountersByPatientAndForm?patientUuid=${patientUuid}&formUuid=${formUuid}`,
173
+ const shouldFetch = patientUuid && formUuids.length > 0;
174
+
175
+ const { data, error, mutate, isLoading } = useSWR<boolean>(
176
+ shouldFetch ? ['forms-filled', patientUuid, formUuids] : null,
177
+ async () => {
178
+ const tasks = await Promise.allSettled(
179
+ formUuids.map((formUuid) =>
180
+ openmrsFetch<{ results: Array<FormEncounter> }>(
181
+ `${restBaseUrl}/kenyaemr/encountersByPatientAndForm?patientUuid=${patientUuid}&formUuid=${formUuid}`,
182
+ ),
145
183
  ),
146
- ),
147
- );
148
- // Return true if all tasks are fullfilled and have related encounter (visit doesnt matter)
149
- return tasks.every((task) => task.status === 'fulfilled' && task.value.data?.results?.length);
150
- });
184
+ );
185
+
186
+ // true only if ALL forms have at least one encounter
187
+ return tasks.every((task) => task.status === 'fulfilled' && task.value.data?.results?.length > 0);
188
+ },
189
+ );
190
+
151
191
  return {
152
- formsFilled: data,
192
+ formsFilled: data ?? false,
153
193
  isLoading,
154
194
  mutate,
155
195
  error,
@@ -93,7 +93,8 @@ const CarePrograms: React.FC<CareProgramsProps> = ({ patientUuid }) => {
93
93
  const rows = useMemo(
94
94
  () => [
95
95
  ...enrollments.map((enrollment) => {
96
- const forms = getProgramForms(enrollment.program.uuid).filter((form) => !form.isEnrollment);
96
+ const forms = getProgramForms(enrollment.program.uuid).filter((form) => !form.tags.includes('enrollment'));
97
+
97
98
  return {
98
99
  id: enrollment.program.uuid,
99
100
  programName: enrollment.program.name,
@@ -25,7 +25,10 @@ const ProgramFormOverflowMenuItem: FC<ProgramFormOverflowMenuItemProps> = ({
25
25
  error,
26
26
  isLoading,
27
27
  mutate: mutateFormEncounters,
28
- } = usePatientFormEncounter(patientUuid, form.formUuId);
28
+ } = usePatientFormEncounter(patientUuid, form.formUuId, {
29
+ scope: form.tags.includes('bound-to-current-visit') ? 'current-visit' : 'all-visits',
30
+ currentVisit: currentVisit,
31
+ });
29
32
  const { hideFilledProgramForm, peerCalendarOutreactForm } = useConfig<CarePanelConfig>();
30
33
  const { t } = useTranslation();
31
34
  const {
@@ -18,7 +18,7 @@ const useCareProgramForms = () => {
18
18
  const getProgramEnrollmentForm = useCallback(
19
19
  (programUuid: string) => {
20
20
  const forms = getProgramForms(programUuid);
21
- return forms.find((form) => form.isEnrollment);
21
+ return forms.find((form) => form.tags.includes('enrollment'));
22
22
  },
23
23
  [getProgramForms],
24
24
  );