@openmrs/esm-form-engine-lib 4.2.1-pre.2438 → 4.2.1-pre.2441
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/processors/encounter/encounter-processor-helper.js +14 -8
- package/dist/src/processors/encounter/encounter-processor-helper.d.ts +9 -7
- package/dist/src/processors/encounter/encounter-processor-helper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/processors/encounter/encounter-processor-helper.ts +25 -10
|
@@ -32,7 +32,9 @@ export function prepareEncounter(context, encounterDate, encounterRole, encounte
|
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
34
|
// TODO: Question: Should we be editing the location, form and visit here?
|
|
35
|
-
|
|
35
|
+
if (encounterDate) {
|
|
36
|
+
encounterForSubmission.encounterDatetime = encounterDate;
|
|
37
|
+
}
|
|
36
38
|
encounterForSubmission.location = location;
|
|
37
39
|
encounterForSubmission.form = {
|
|
38
40
|
uuid: formJson.uuid
|
|
@@ -46,7 +48,6 @@ export function prepareEncounter(context, encounterDate, encounterRole, encounte
|
|
|
46
48
|
} else {
|
|
47
49
|
encounterForSubmission = {
|
|
48
50
|
patient: patient.id,
|
|
49
|
-
encounterDatetime: encounterDate,
|
|
50
51
|
location: location,
|
|
51
52
|
encounterType: formJson.encounterType,
|
|
52
53
|
encounterProviders: [
|
|
@@ -63,6 +64,9 @@ export function prepareEncounter(context, encounterDate, encounterRole, encounte
|
|
|
63
64
|
orders: ordersForSubmission,
|
|
64
65
|
diagnoses: diagnosesForSubmission
|
|
65
66
|
};
|
|
67
|
+
if (encounterDate) {
|
|
68
|
+
encounterForSubmission.encounterDatetime = encounterDate;
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
return encounterForSubmission;
|
|
68
72
|
}
|
|
@@ -134,20 +138,22 @@ export function saveAttachments(fields, encounter, abortController) {
|
|
|
134
138
|
return Promise.all(allPromises);
|
|
135
139
|
}
|
|
136
140
|
export function getMutableSessionProps(context) {
|
|
137
|
-
const { formFields, location, currentProvider, customDependencies, sessionDate, domainObjectValue: encounter } = context;
|
|
141
|
+
const { formFields, location, currentProvider, customDependencies, sessionDate, domainObjectValue: encounter, visit } = context;
|
|
138
142
|
const { defaultEncounterRole } = customDependencies;
|
|
139
143
|
const encounterRole = formFields.find((field)=>field.type === 'encounterRole')?.meta.submission?.newValue || defaultEncounterRole?.uuid;
|
|
140
144
|
const encounterProvider = formFields.find((field)=>field.type === 'encounterProvider')?.meta.submission?.newValue || currentProvider.uuid;
|
|
141
145
|
const explicitEncounterDate = formFields.find((field)=>field.type === 'encounterDatetime')?.meta.submission?.newValue;
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
+
// Stopped visits need an explicit datetime because the backend defaults omitted
|
|
147
|
+
// encounter datetimes to server "now", which can be outside the visit window.
|
|
148
|
+
// Active visits should use the backend default so client clock skew does not
|
|
149
|
+
// submit future encounter datetimes.
|
|
150
|
+
const defaultEncounterDate = visit?.stopDatetime ? sessionDate : undefined;
|
|
151
|
+
const encounterDate = explicitEncounterDate ?? (encounter?.encounterDatetime ? new Date(encounter.encounterDatetime) : defaultEncounterDate);
|
|
146
152
|
const encounterLocation = formFields.find((field)=>field.type === 'encounterLocation')?.meta.submission?.newValue || encounter?.location?.uuid || location.uuid;
|
|
147
153
|
return {
|
|
148
154
|
encounterRole: encounterRole,
|
|
149
155
|
encounterProvider: encounterProvider,
|
|
150
|
-
encounterDate
|
|
156
|
+
encounterDate,
|
|
151
157
|
encounterLocation: encounterLocation
|
|
152
158
|
};
|
|
153
159
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type FormField, type FormProcessorContextProps, type OpenmrsEncounter, type PatientIdentifier, type PatientProgram, type PatientProgramPayload, type PersonAttribute } from '../../types';
|
|
2
2
|
import { type FormContextProps } from '../../provider/form-provider';
|
|
3
|
-
|
|
3
|
+
type MutableSessionProps = {
|
|
4
|
+
encounterRole: string;
|
|
5
|
+
encounterProvider: string;
|
|
6
|
+
encounterDate?: Date;
|
|
7
|
+
encounterLocation: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function prepareEncounter(context: FormContextProps, encounterDate: Date | undefined, encounterRole: string, encounterProvider: string, location: string): OpenmrsEncounter;
|
|
4
10
|
export declare function preparePatientIdentifiers(fields: FormField[], encounterLocation: string): PatientIdentifier[];
|
|
5
11
|
export declare function savePatientIdentifiers(patient: fhir.Patient, identifiers: PatientIdentifier[]): Promise<import("@openmrs/esm-api").FetchResponse<any>>[];
|
|
6
12
|
export declare function preparePersonAttributes(fields: FormField[]): PersonAttribute[];
|
|
@@ -8,12 +14,8 @@ export declare function savePersonAttributes(patient: fhir.Patient, attributes:
|
|
|
8
14
|
export declare function preparePatientPrograms(fields: FormField[], patient: fhir.Patient, currentPatientPrograms: Array<PatientProgram>): Array<PatientProgramPayload>;
|
|
9
15
|
export declare function savePatientPrograms(patientPrograms: PatientProgramPayload[]): Promise<import("@openmrs/esm-api").FetchResponse<any>[]>;
|
|
10
16
|
export declare function saveAttachments(fields: FormField[], encounter: OpenmrsEncounter, abortController: AbortController): any[] | Promise<import("@openmrs/esm-api").FetchResponse<any>[]>;
|
|
11
|
-
export declare function getMutableSessionProps(context: FormContextProps):
|
|
12
|
-
encounterRole: string;
|
|
13
|
-
encounterProvider: string;
|
|
14
|
-
encounterDate: Date;
|
|
15
|
-
encounterLocation: string;
|
|
16
|
-
};
|
|
17
|
+
export declare function getMutableSessionProps(context: FormContextProps): MutableSessionProps;
|
|
17
18
|
export declare function inferInitialValueFromDefaultFieldValue(field: FormField): any;
|
|
18
19
|
export declare function hydrateRepeatField(field: FormField, encounter: OpenmrsEncounter, initialValues: Record<string, any>, context: FormProcessorContextProps): Promise<FormField[]>;
|
|
20
|
+
export {};
|
|
19
21
|
//# sourceMappingURL=encounter-processor-helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encounter-processor-helper.d.ts","sourceRoot":"","sources":["../../../../src/processors/encounter/encounter-processor-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EAErB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAQrE,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"encounter-processor-helper.d.ts","sourceRoot":"","sources":["../../../../src/processors/encounter/encounter-processor-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EAErB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAQrE,KAAK,mBAAmB,GAAG;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAAE,IAAI,GAAG,SAAS,EAC/B,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,QAAQ,EAAE,MAAM,oBAiEjB;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAI7G;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,4DAI7F;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,eAAe,EAAE,CAI9E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,4DAIxF;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,sBAAsB,EAAE,KAAK,CAAC,cAAc,CAAC,GAC5C,KAAK,CAAC,qBAAqB,CAAC,CA+B9B;AAED,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,EAAE,4DAG3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,oEAcjH;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,GAAG,mBAAmB,CAmCrF;AA4FD,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,SAAS,OAetE;AAED,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,gBAAgB,EAC3B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,SAAS,EAAE,CAAC,CAwEtB"}
|
package/package.json
CHANGED
|
@@ -21,9 +21,16 @@ import { assignedOrderIds } from '../../adapters/orders-adapter';
|
|
|
21
21
|
import { type OpenmrsResource } from '@openmrs/esm-framework';
|
|
22
22
|
import { assignedDiagnosesIds } from '../../adapters/encounter-diagnosis-adapter';
|
|
23
23
|
|
|
24
|
+
type MutableSessionProps = {
|
|
25
|
+
encounterRole: string;
|
|
26
|
+
encounterProvider: string;
|
|
27
|
+
encounterDate?: Date;
|
|
28
|
+
encounterLocation: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
24
31
|
export function prepareEncounter(
|
|
25
32
|
context: FormContextProps,
|
|
26
|
-
encounterDate: Date,
|
|
33
|
+
encounterDate: Date | undefined,
|
|
27
34
|
encounterRole: string,
|
|
28
35
|
encounterProvider: string,
|
|
29
36
|
location: string,
|
|
@@ -54,7 +61,9 @@ export function prepareEncounter(
|
|
|
54
61
|
];
|
|
55
62
|
}
|
|
56
63
|
// TODO: Question: Should we be editing the location, form and visit here?
|
|
57
|
-
|
|
64
|
+
if (encounterDate) {
|
|
65
|
+
encounterForSubmission.encounterDatetime = encounterDate;
|
|
66
|
+
}
|
|
58
67
|
encounterForSubmission.location = location;
|
|
59
68
|
encounterForSubmission.form = {
|
|
60
69
|
uuid: formJson.uuid,
|
|
@@ -68,7 +77,6 @@ export function prepareEncounter(
|
|
|
68
77
|
} else {
|
|
69
78
|
encounterForSubmission = {
|
|
70
79
|
patient: patient.id,
|
|
71
|
-
encounterDatetime: encounterDate,
|
|
72
80
|
location: location,
|
|
73
81
|
encounterType: formJson.encounterType,
|
|
74
82
|
encounterProviders: [
|
|
@@ -85,6 +93,9 @@ export function prepareEncounter(
|
|
|
85
93
|
orders: ordersForSubmission,
|
|
86
94
|
diagnoses: diagnosesForSubmission,
|
|
87
95
|
};
|
|
96
|
+
if (encounterDate) {
|
|
97
|
+
encounterForSubmission.encounterDatetime = encounterDate;
|
|
98
|
+
}
|
|
88
99
|
}
|
|
89
100
|
return encounterForSubmission;
|
|
90
101
|
}
|
|
@@ -171,7 +182,7 @@ export function saveAttachments(fields: FormField[], encounter: OpenmrsEncounter
|
|
|
171
182
|
return Promise.all(allPromises);
|
|
172
183
|
}
|
|
173
184
|
|
|
174
|
-
export function getMutableSessionProps(context: FormContextProps) {
|
|
185
|
+
export function getMutableSessionProps(context: FormContextProps): MutableSessionProps {
|
|
175
186
|
const {
|
|
176
187
|
formFields,
|
|
177
188
|
location,
|
|
@@ -179,6 +190,7 @@ export function getMutableSessionProps(context: FormContextProps) {
|
|
|
179
190
|
customDependencies,
|
|
180
191
|
sessionDate,
|
|
181
192
|
domainObjectValue: encounter,
|
|
193
|
+
visit,
|
|
182
194
|
} = context;
|
|
183
195
|
const { defaultEncounterRole } = customDependencies;
|
|
184
196
|
const encounterRole =
|
|
@@ -186,12 +198,15 @@ export function getMutableSessionProps(context: FormContextProps) {
|
|
|
186
198
|
const encounterProvider =
|
|
187
199
|
formFields.find((field) => field.type === 'encounterProvider')?.meta.submission?.newValue || currentProvider.uuid;
|
|
188
200
|
const explicitEncounterDate = formFields.find((field) => field.type === 'encounterDatetime')?.meta.submission
|
|
189
|
-
?.newValue;
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
201
|
+
?.newValue as Date | undefined;
|
|
202
|
+
// Stopped visits need an explicit datetime because the backend defaults omitted
|
|
203
|
+
// encounter datetimes to server "now", which can be outside the visit window.
|
|
204
|
+
// Active visits should use the backend default so client clock skew does not
|
|
205
|
+
// submit future encounter datetimes.
|
|
206
|
+
const defaultEncounterDate = visit?.stopDatetime ? sessionDate : undefined;
|
|
193
207
|
const encounterDate =
|
|
194
|
-
explicitEncounterDate ??
|
|
208
|
+
explicitEncounterDate ??
|
|
209
|
+
(encounter?.encounterDatetime ? new Date(encounter.encounterDatetime) : defaultEncounterDate);
|
|
195
210
|
const encounterLocation =
|
|
196
211
|
formFields.find((field) => field.type === 'encounterLocation')?.meta.submission?.newValue ||
|
|
197
212
|
encounter?.location?.uuid ||
|
|
@@ -199,7 +214,7 @@ export function getMutableSessionProps(context: FormContextProps) {
|
|
|
199
214
|
return {
|
|
200
215
|
encounterRole: encounterRole as string,
|
|
201
216
|
encounterProvider: encounterProvider as string,
|
|
202
|
-
encounterDate
|
|
217
|
+
encounterDate,
|
|
203
218
|
encounterLocation: encounterLocation as string,
|
|
204
219
|
};
|
|
205
220
|
}
|