@openmrs/esm-form-engine-lib 4.3.1-pre.2715 → 4.3.1-pre.2717
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.
|
@@ -17,7 +17,9 @@ export const ObsAdapter = {
|
|
|
17
17
|
async getPreviousValue (field, sourceObject, context) {
|
|
18
18
|
const encounter = sourceObject ?? context.previousDomainObjectValue;
|
|
19
19
|
if (encounter) {
|
|
20
|
-
|
|
20
|
+
// the previous encounter's obs must not become this field's obs to edit or void;
|
|
21
|
+
// an obs already loaded for this encounter stays bound to the field
|
|
22
|
+
const value = extractFieldValue(field, findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field), false);
|
|
21
23
|
if (!isEmpty(value)) {
|
|
22
24
|
return {
|
|
23
25
|
value,
|
|
@@ -63,6 +65,11 @@ export const ObsAdapter = {
|
|
|
63
65
|
if (!isEmpty(value) && hasPreviousObsValueChanged(field, value)) {
|
|
64
66
|
return gracefullySetSubmission(field, editObs(field, value), undefined);
|
|
65
67
|
}
|
|
68
|
+
if (!isEmpty(value) && field.meta.initialValue?.omrsObject) {
|
|
69
|
+
// unchanged value on a stored obs: leave it alone, as falling through
|
|
70
|
+
// to constructObs would submit a uuid-less duplicate
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
66
73
|
if (field.meta.initialValue?.omrsObject && isEmpty(value)) {
|
|
67
74
|
return gracefullySetSubmission(field, undefined, voidObs(field.meta.initialValue.omrsObject));
|
|
68
75
|
}
|
|
@@ -91,7 +98,9 @@ export const ObsAdapter = {
|
|
|
91
98
|
if (obsList.length) {
|
|
92
99
|
if (rendering == 'checkbox') {
|
|
93
100
|
assignedObsIds.push(...obsList.map((obs)=>obs.uuid));
|
|
94
|
-
|
|
101
|
+
if (makeFieldDirty) {
|
|
102
|
+
field.meta.initialValue.omrsObject = obsList;
|
|
103
|
+
}
|
|
95
104
|
return obsList.map((o)=>o.value.uuid);
|
|
96
105
|
}
|
|
97
106
|
const obs = obsList[0];
|
|
@@ -155,19 +164,18 @@ export function editObs(field, newValue) {
|
|
|
155
164
|
};
|
|
156
165
|
}
|
|
157
166
|
function formatDateByPickerType(field, value) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
// fields that skip the schema transformer can arrive without a datePickerFormat,
|
|
168
|
+
// so fall back to the defaults the transformer applies per rendering
|
|
169
|
+
const datePickerFormat = field.datePickerFormat ?? (hasRendering(field, 'datetime') ? 'both' : 'calendar');
|
|
170
|
+
switch(datePickerFormat){
|
|
171
|
+
case 'timer':
|
|
172
|
+
return dayjs(value).format('HH:mm');
|
|
173
|
+
case 'both':
|
|
174
|
+
return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
|
|
175
|
+
case 'calendar':
|
|
176
|
+
default:
|
|
177
|
+
return dayjs(value).format('YYYY-MM-DD');
|
|
169
178
|
}
|
|
170
|
-
return value;
|
|
171
179
|
}
|
|
172
180
|
export function hasPreviousObsValueChanged(field, newValue) {
|
|
173
181
|
const previousObs = field.meta.initialValue?.omrsObject;
|
|
@@ -177,11 +185,9 @@ export function hasPreviousObsValueChanged(field, newValue) {
|
|
|
177
185
|
if (codedTypes.includes(field.questionOptions.rendering)) {
|
|
178
186
|
return previousObs.value.uuid !== newValue;
|
|
179
187
|
}
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (hasRendering(field, 'datetime') || field.datePickerFormat === 'both') {
|
|
184
|
-
return dayjs(newValue).diff(dayjs(previousObs.value), 'minute') !== 0;
|
|
188
|
+
if (field.questionOptions.rendering.startsWith('date')) {
|
|
189
|
+
// compare what would be submitted, at the precision of the date picker
|
|
190
|
+
return formatDateByPickerType(field, previousObs.value) !== formatDateByPickerType(field, newValue);
|
|
185
191
|
}
|
|
186
192
|
if (hasRendering(field, 'toggle')) {
|
|
187
193
|
return previousObs.value.uuid === ConceptTrue !== newValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obs-adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/obs-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EAGd,KAAK,qBAAqB,EAC3B,MAAM,UAAU,CAAC;AAelB,eAAO,IAAI,cAAc,EAAE,MAAM,EAAO,CAAC;AAEzC,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"obs-adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/obs-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EAGd,KAAK,qBAAqB,EAC3B,MAAM,UAAU,CAAC;AAelB,eAAO,IAAI,cAAc,EAAE,MAAM,EAAO,CAAC;AAEzC,eAAO,MAAM,UAAU,EAAE,qBAgFxB,CAAC;AAuDF,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAgB9E;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,UAAU;;;EAEtC;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG;;;;;EAWtD;AAiBD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,WAgBzE;AA+CD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,EAC1B,aAAa,EAAE,MAAM,EAAE,EACvB,KAAK,EAAE,SAAS,GACf,UAAU,EAAE,CAmBd"}
|
package/package.json
CHANGED
|
@@ -36,10 +36,12 @@ export const ObsAdapter: FormFieldValueAdapter = {
|
|
|
36
36
|
async getPreviousValue(field: FormField, sourceObject: any, context: FormContextProps): Promise<ValueAndDisplay> {
|
|
37
37
|
const encounter = sourceObject ?? (context.previousDomainObjectValue as OpenmrsEncounter);
|
|
38
38
|
if (encounter) {
|
|
39
|
+
// the previous encounter's obs must not become this field's obs to edit or void;
|
|
40
|
+
// an obs already loaded for this encounter stays bound to the field
|
|
39
41
|
const value = extractFieldValue(
|
|
40
42
|
field,
|
|
41
43
|
findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field),
|
|
42
|
-
|
|
44
|
+
false,
|
|
43
45
|
);
|
|
44
46
|
if (!isEmpty(value)) {
|
|
45
47
|
return {
|
|
@@ -86,6 +88,11 @@ export const ObsAdapter: FormFieldValueAdapter = {
|
|
|
86
88
|
if (!isEmpty(value) && hasPreviousObsValueChanged(field, value)) {
|
|
87
89
|
return gracefullySetSubmission(field, editObs(field, value), undefined);
|
|
88
90
|
}
|
|
91
|
+
if (!isEmpty(value) && field.meta.initialValue?.omrsObject) {
|
|
92
|
+
// unchanged value on a stored obs: leave it alone, as falling through
|
|
93
|
+
// to constructObs would submit a uuid-less duplicate
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
89
96
|
if (field.meta.initialValue?.omrsObject && isEmpty(value)) {
|
|
90
97
|
return gracefullySetSubmission(field, undefined, voidObs(field.meta.initialValue.omrsObject as OpenmrsObs));
|
|
91
98
|
}
|
|
@@ -117,7 +124,9 @@ function extractFieldValue(field: FormField, obsList: OpenmrsObs[] = [], makeFie
|
|
|
117
124
|
if (obsList.length) {
|
|
118
125
|
if (rendering == 'checkbox') {
|
|
119
126
|
assignedObsIds.push(...obsList.map((obs) => obs.uuid));
|
|
120
|
-
|
|
127
|
+
if (makeFieldDirty) {
|
|
128
|
+
field.meta.initialValue.omrsObject = obsList;
|
|
129
|
+
}
|
|
121
130
|
return obsList.map((o) => o.value.uuid);
|
|
122
131
|
}
|
|
123
132
|
const obs = obsList[0];
|
|
@@ -185,20 +194,19 @@ export function editObs(field: FormField, newValue: any) {
|
|
|
185
194
|
};
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
function formatDateByPickerType(field: FormField, value: Date) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
function formatDateByPickerType(field: FormField, value: Date | string) {
|
|
198
|
+
// fields that skip the schema transformer can arrive without a datePickerFormat,
|
|
199
|
+
// so fall back to the defaults the transformer applies per rendering
|
|
200
|
+
const datePickerFormat = field.datePickerFormat ?? (hasRendering(field, 'datetime') ? 'both' : 'calendar');
|
|
201
|
+
switch (datePickerFormat) {
|
|
202
|
+
case 'timer':
|
|
203
|
+
return dayjs(value).format('HH:mm');
|
|
204
|
+
case 'both':
|
|
205
|
+
return dayjs(value).format('YYYY-MM-DDTHH:mmZ');
|
|
206
|
+
case 'calendar':
|
|
207
|
+
default:
|
|
208
|
+
return dayjs(value).format('YYYY-MM-DD');
|
|
200
209
|
}
|
|
201
|
-
return value;
|
|
202
210
|
}
|
|
203
211
|
|
|
204
212
|
export function hasPreviousObsValueChanged(field: FormField, newValue: any) {
|
|
@@ -209,11 +217,9 @@ export function hasPreviousObsValueChanged(field: FormField, newValue: any) {
|
|
|
209
217
|
if (codedTypes.includes(field.questionOptions.rendering)) {
|
|
210
218
|
return previousObs.value.uuid !== newValue;
|
|
211
219
|
}
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (hasRendering(field, 'datetime') || field.datePickerFormat === 'both') {
|
|
216
|
-
return dayjs(newValue).diff(dayjs(previousObs.value), 'minute') !== 0;
|
|
220
|
+
if (field.questionOptions.rendering.startsWith('date')) {
|
|
221
|
+
// compare what would be submitted, at the precision of the date picker
|
|
222
|
+
return formatDateByPickerType(field, previousObs.value) !== formatDateByPickerType(field, newValue);
|
|
217
223
|
}
|
|
218
224
|
if (hasRendering(field, 'toggle')) {
|
|
219
225
|
return (previousObs.value.uuid === ConceptTrue) !== newValue;
|