@openmrs/esm-form-engine-lib 3.1.3-pre.1735 → 3.1.3-pre.1740
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@openmrs/esm-form-engine-lib",
|
3
|
-
"version": "3.1.3-pre.
|
3
|
+
"version": "3.1.3-pre.1740",
|
4
4
|
"description": "React Form Engine for O3",
|
5
5
|
"browser": "dist/openmrs-esm-form-engine-lib.js",
|
6
6
|
"main": "src/index.ts",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"coverage": "yarn test --coverage",
|
17
17
|
"analyze": "webpack --mode=production --env.analyze=true",
|
18
18
|
"prepare": "husky install",
|
19
|
-
"extract-translations": "i18next 'src/**/*.component.tsx' --config './tools/i18next-parser.config.js'"
|
19
|
+
"extract-translations": "i18next 'src/**/*.component.tsx' 'src/**/*.ts' --config './tools/i18next-parser.config.js'"
|
20
20
|
},
|
21
21
|
"browserslist": [
|
22
22
|
"extends browserslist-config-openmrs"
|
@@ -1,15 +1,25 @@
|
|
1
|
-
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
1
|
+
import { openmrsFetch, OpenmrsResource, restBaseUrl } from '@openmrs/esm-framework';
|
2
2
|
import { BaseOpenMRSDataSource } from './data-source';
|
3
3
|
|
4
4
|
export class SelectConceptAnswersDatasource extends BaseOpenMRSDataSource {
|
5
5
|
constructor() {
|
6
|
-
super(
|
6
|
+
super(
|
7
|
+
`${restBaseUrl}/concept/:conceptUuid?v=custom:(uuid,display,setMembers:(uuid,display),answers:(uuid,display))`,
|
8
|
+
);
|
9
|
+
}
|
10
|
+
|
11
|
+
fetchSingleItem(uuid: string): Promise<OpenmrsResource | null> {
|
12
|
+
return openmrsFetch(this.buildUrl(uuid)).then(({ data }) => data);
|
7
13
|
}
|
8
14
|
|
9
15
|
fetchData(searchTerm: string, config?: Record<string, any>): Promise<any[]> {
|
10
|
-
const apiUrl = this.
|
16
|
+
const apiUrl = this.buildUrl(config.referencedValue || config.concept);
|
11
17
|
return openmrsFetch(apiUrl).then(({ data }) => {
|
12
18
|
return data['setMembers'].length ? data['setMembers'] : data['answers'];
|
13
19
|
});
|
14
20
|
}
|
21
|
+
|
22
|
+
private buildUrl(conceptUuid: string): string {
|
23
|
+
return this.url.replace(':conceptUuid', conceptUuid);
|
24
|
+
}
|
15
25
|
}
|
@@ -4,12 +4,14 @@ import { getPatientEnrolledPrograms, saveProgramEnrollment } from '../api';
|
|
4
4
|
import { type PostSubmissionAction, type PatientProgramPayload } from '../types';
|
5
5
|
import { formEngineAppName } from '../globals';
|
6
6
|
import { extractErrorMessagesFromResponse } from '../utils/error-utils';
|
7
|
+
import { TOptions } from 'i18next';
|
7
8
|
|
8
9
|
export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
9
10
|
applyAction: async function ({ patient, encounters, sessionMode }, config) {
|
10
11
|
const encounter = encounters[0];
|
11
12
|
const encounterLocation = encounter.location['uuid'];
|
12
|
-
const
|
13
|
+
const t = (key: string, defaultValue: string, options?: Omit<TOptions, 'ns' | 'defaultValue'>) =>
|
14
|
+
translateFrom(formEngineAppName, key, defaultValue, options);
|
13
15
|
const programUuid = config.programUuid;
|
14
16
|
|
15
17
|
if (sessionMode === 'view') {
|
@@ -49,8 +51,8 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
|
49
51
|
};
|
50
52
|
} else {
|
51
53
|
showSnackbar({
|
52
|
-
title:
|
53
|
-
subtitle:
|
54
|
+
title: t('enrollmentDiscontinuationNotAllowed', 'Enrollment discontinuation not allowed'),
|
55
|
+
subtitle: t('cannotDiscontinueEnrollment', 'Cannot discontinue an enrollment that does not exist'),
|
54
56
|
kind: 'error',
|
55
57
|
isLowContrast: false,
|
56
58
|
});
|
@@ -63,8 +65,8 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
|
63
65
|
// The patient is already enrolled in the program and there is no completion date provided.
|
64
66
|
if (sessionMode === 'enter') {
|
65
67
|
showSnackbar({
|
66
|
-
title:
|
67
|
-
subtitle:
|
68
|
+
title: t('enrollmentNotAllowed', 'Enrollment not allowed'),
|
69
|
+
subtitle: t(
|
68
70
|
'alreadyEnrolledDescription',
|
69
71
|
'This patient is already enrolled in the selected program and cannot be enrolled again.',
|
70
72
|
),
|
@@ -77,8 +79,8 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
|
77
79
|
// The enrollment has already been completed
|
78
80
|
if (sessionMode === 'enter') {
|
79
81
|
showSnackbar({
|
80
|
-
title:
|
81
|
-
subtitle:
|
82
|
+
title: t('enrollmentAlreadyDiscontinued', 'Enrollment already discontinued'),
|
83
|
+
subtitle: t(
|
82
84
|
'alreadyDiscontinuedDescription',
|
83
85
|
'This patient is already enrolled in the selected program and has already been discontinued.',
|
84
86
|
),
|
@@ -93,13 +95,13 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
|
93
95
|
(response) => {
|
94
96
|
showSnackbar({
|
95
97
|
kind: 'success',
|
96
|
-
title: getSnackTitle(
|
98
|
+
title: getSnackTitle(t, response),
|
97
99
|
isLowContrast: true,
|
98
100
|
});
|
99
101
|
},
|
100
102
|
(err) => {
|
101
103
|
showSnackbar({
|
102
|
-
title:
|
104
|
+
title: t('errorSavingEnrollment', 'Error saving enrollment'),
|
103
105
|
subtitle: extractErrorMessagesFromResponse(err).join(', '),
|
104
106
|
kind: 'error',
|
105
107
|
isLowContrast: false,
|
@@ -109,14 +111,11 @@ export const ProgramEnrollmentSubmissionAction: PostSubmissionAction = {
|
|
109
111
|
},
|
110
112
|
};
|
111
113
|
|
112
|
-
function getSnackTitle(
|
114
|
+
function getSnackTitle(t, response) {
|
113
115
|
if (response.data.dateCompleted) {
|
114
|
-
return
|
115
|
-
'enrollmentDiscontinued',
|
116
|
-
"The patient's program enrollment has been successfully discontinued.",
|
117
|
-
);
|
116
|
+
return t('enrollmentDiscontinued', "The patient's program enrollment has been successfully discontinued.");
|
118
117
|
}
|
119
|
-
return
|
118
|
+
return t('enrolledToProgram', 'The patient has been successfully enrolled in the program.');
|
120
119
|
}
|
121
120
|
|
122
121
|
function updateTimeToNow(dateString) {
|
@@ -31,6 +31,7 @@ import { type FormContextProps } from '../../provider/form-provider';
|
|
31
31
|
import { useEncounter } from '../../hooks/useEncounter';
|
32
32
|
import { useEncounterRole } from '../../hooks/useEncounterRole';
|
33
33
|
import { usePatientPrograms } from '../../hooks/usePatientPrograms';
|
34
|
+
import { TOptions } from 'i18next';
|
34
35
|
|
35
36
|
function useCustomHooks(context: Partial<FormProcessorContextProps>) {
|
36
37
|
const [isLoading, setIsLoading] = useState(true);
|
@@ -110,7 +111,8 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
110
111
|
|
111
112
|
async processSubmission(context: FormContextProps, abortController: AbortController) {
|
112
113
|
const { encounterRole, encounterProvider, encounterDate, encounterLocation } = getMutableSessionProps(context);
|
113
|
-
const
|
114
|
+
const t = (key: string, defaultValue: string, options?: Omit<TOptions, 'ns' | 'defaultValue'>) =>
|
115
|
+
translateFrom(formEngineAppName, key, defaultValue, options);
|
114
116
|
const patientIdentifiers = preparePatientIdentifiers(context.formFields, encounterLocation);
|
115
117
|
const encounter = prepareEncounter(context, encounterDate, encounterRole, encounterProvider, encounterLocation);
|
116
118
|
|
@@ -119,7 +121,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
119
121
|
await Promise.all(savePatientIdentifiers(context.patient, patientIdentifiers));
|
120
122
|
if (patientIdentifiers?.length) {
|
121
123
|
showSnackbar({
|
122
|
-
title:
|
124
|
+
title: t('patientIdentifiersSaved', 'Patient identifier(s) saved successfully'),
|
123
125
|
kind: 'success',
|
124
126
|
isLowContrast: true,
|
125
127
|
});
|
@@ -127,7 +129,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
127
129
|
} catch (error) {
|
128
130
|
const errorMessages = extractErrorMessagesFromResponse(error);
|
129
131
|
return Promise.reject({
|
130
|
-
title:
|
132
|
+
title: t('errorSavingPatientIdentifiers', 'Error saving patient identifiers'),
|
131
133
|
description: errorMessages.join(', '),
|
132
134
|
kind: 'error',
|
133
135
|
critical: true,
|
@@ -144,7 +146,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
144
146
|
const savedPrograms = await await savePatientPrograms(programs);
|
145
147
|
if (savedPrograms?.length) {
|
146
148
|
showSnackbar({
|
147
|
-
title:
|
149
|
+
title: t('patientProgramsSaved', 'Patient program(s) saved successfully'),
|
148
150
|
kind: 'success',
|
149
151
|
isLowContrast: true,
|
150
152
|
});
|
@@ -152,7 +154,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
152
154
|
} catch (error) {
|
153
155
|
const errorMessages = extractErrorMessagesFromResponse(error);
|
154
156
|
return Promise.reject({
|
155
|
-
title:
|
157
|
+
title: t('errorSavingPatientPrograms', 'Error saving patient program(s)'),
|
156
158
|
description: errorMessages.join(', '),
|
157
159
|
kind: 'error',
|
158
160
|
critical: true,
|
@@ -166,7 +168,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
166
168
|
const savedDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
|
167
169
|
if (savedOrders.length) {
|
168
170
|
showSnackbar({
|
169
|
-
title:
|
171
|
+
title: t('ordersSaved', 'Order(s) saved successfully'),
|
170
172
|
subtitle: savedOrders.join(', '),
|
171
173
|
kind: 'success',
|
172
174
|
isLowContrast: true,
|
@@ -175,7 +177,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
175
177
|
// handle diagnoses
|
176
178
|
if (savedDiagnoses.length) {
|
177
179
|
showSnackbar({
|
178
|
-
title:
|
180
|
+
title: t('diagnosisSaved', 'Diagnosis(es) saved successfully'),
|
179
181
|
subtitle: savedDiagnoses.join(', '),
|
180
182
|
kind: 'success',
|
181
183
|
isLowContrast: true,
|
@@ -188,7 +190,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
188
190
|
);
|
189
191
|
if (attachmentsResponse?.length) {
|
190
192
|
showSnackbar({
|
191
|
-
title:
|
193
|
+
title: t('attachmentsSaved', 'Attachment(s) saved successfully'),
|
192
194
|
kind: 'success',
|
193
195
|
isLowContrast: true,
|
194
196
|
});
|
@@ -196,7 +198,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
196
198
|
} catch (error) {
|
197
199
|
const errorMessages = extractErrorMessagesFromResponse(error);
|
198
200
|
return Promise.reject({
|
199
|
-
title:
|
201
|
+
title: t('errorSavingAttachments', 'Error saving attachment(s)'),
|
200
202
|
description: errorMessages.join(', '),
|
201
203
|
kind: 'error',
|
202
204
|
critical: true,
|
@@ -206,7 +208,7 @@ export class EncounterFormProcessor extends FormProcessor {
|
|
206
208
|
} catch (error) {
|
207
209
|
const errorMessages = extractErrorMessagesFromResponse(error);
|
208
210
|
return Promise.reject({
|
209
|
-
title:
|
211
|
+
title: t('errorSavingEncounter', 'Error saving encounter'),
|
210
212
|
description: errorMessages.join(', '),
|
211
213
|
kind: 'error',
|
212
214
|
critical: true,
|