@openmrs/esm-form-engine-lib 5.0.1-pre.2750 → 5.0.1-pre.2759
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/adapters/obs-adapter.js +32 -5
- package/dist/processors/encounter/encounter-processor-helper.js +15 -0
- package/dist/src/adapters/obs-adapter.d.ts +3 -2
- package/dist/src/adapters/obs-adapter.d.ts.map +1 -1
- package/dist/src/processors/encounter/encounter-processor-helper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/obs-adapter.ts +37 -4
- package/src/processors/encounter/encounter-processor-helper.ts +18 -0
|
@@ -8,7 +8,7 @@ export let assignedObsIds = [];
|
|
|
8
8
|
export const ObsAdapter = {
|
|
9
9
|
async getInitialValue (field, sourceObject, context) {
|
|
10
10
|
const encounter = sourceObject ?? context.domainObjectValue;
|
|
11
|
-
const matchingObs = findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field);
|
|
11
|
+
const matchingObs = findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field, context.formFields);
|
|
12
12
|
if (hasRendering(field, 'file') && matchingObs?.length) {
|
|
13
13
|
return resolveAttachmentsFromObs(field, matchingObs);
|
|
14
14
|
}
|
|
@@ -19,7 +19,7 @@ export const ObsAdapter = {
|
|
|
19
19
|
if (encounter) {
|
|
20
20
|
// the previous encounter's obs must not become this field's obs to edit or void;
|
|
21
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);
|
|
22
|
+
const value = extractFieldValue(field, findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field, context.formFields), false);
|
|
23
23
|
if (!isEmpty(value)) {
|
|
24
24
|
return {
|
|
25
25
|
value,
|
|
@@ -229,8 +229,9 @@ function handleAttachments(field, attachments = []) {
|
|
|
229
229
|
*
|
|
230
230
|
* Notes:
|
|
231
231
|
* If the query by field-path returns an empty list, the function falls back to querying
|
|
232
|
-
* by concept and uses `claimedObsIds` to exclude already assigned observations.
|
|
233
|
-
|
|
232
|
+
* by concept and uses `claimedObsIds` to exclude already assigned observations. Given the
|
|
233
|
+
* form's fields, it also leaves out obs whose path names another of them or a repeat of one.
|
|
234
|
+
*/ export function findObsByFormField(obsList, claimedObsIds, field, formFields) {
|
|
234
235
|
const obs = obsList.filter((candidate)=>{
|
|
235
236
|
// we ignore the concept for attachments because they're managed from the backend
|
|
236
237
|
if (hasRendering(field, 'file') && candidate.formFieldPath == `rfe-forms-${field.id}`) {
|
|
@@ -241,11 +242,37 @@ function handleAttachments(field, attachments = []) {
|
|
|
241
242
|
// We shall fall back to mapping by the associated concept
|
|
242
243
|
// That being said, we shall find all matching obs and pick the one that wasn't previously claimed.
|
|
243
244
|
if (!obs?.length) {
|
|
244
|
-
const obsByConcept = obsList.filter((obs)=>obs.concept.uuid == field.questionOptions.concept);
|
|
245
|
+
const obsByConcept = obsList.filter((obs)=>obs.concept.uuid == field.questionOptions.concept && !isBoundToAnotherField(obs, field, formFields));
|
|
245
246
|
return claimedObsIds?.length ? obsByConcept.filter((obs)=>!claimedObsIds.includes(obs.uuid)) : obsByConcept;
|
|
246
247
|
}
|
|
247
248
|
return obs;
|
|
248
249
|
}
|
|
250
|
+
const repeatedFieldId = (fieldId)=>fieldId.match(/^(.+)_\d+$/)?.[1];
|
|
251
|
+
/**
|
|
252
|
+
* Whether the obs's form field path names another field of the form, or a repeat of one such as `dateStopped_1`,
|
|
253
|
+
* which hydrates it by that path. The concept fallback leaves such an obs to it, as a field that recorded nothing
|
|
254
|
+
* would otherwise take a value from a repeat of itself or from another question on the same concept.
|
|
255
|
+
* A repeat still takes an obs saved under its question's path or that of any repeat of it: it is hydrated from its
|
|
256
|
+
* own group's obs only, and as repeats are numbered in order on hydration, one saved as `dateStopped_2` reopens as
|
|
257
|
+
* `dateStopped_1` once the row before it is deleted. A field of the form whose id only reads like a repeat, such as
|
|
258
|
+
* `item_1` beside `item`, is not one.
|
|
259
|
+
* A repeat of the field itself is told by its path alone, so the field never takes one even without the form's fields.
|
|
260
|
+
*/ function isBoundToAnotherField(obs, field, formFields = []) {
|
|
261
|
+
const path = obs.formFieldPath;
|
|
262
|
+
if (!path?.startsWith('rfe-forms-')) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
const fieldId = path.slice('rfe-forms-'.length);
|
|
266
|
+
if (repeatedFieldId(fieldId) === field.id) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
// Repeats are cloned while the encounter is hydrated, so they are not yet among the form's fields
|
|
270
|
+
const repeated = formFields.some((one)=>one.id === field.id) ? undefined : repeatedFieldId(field.id);
|
|
271
|
+
if (repeated && (fieldId === repeated || repeatedFieldId(fieldId) === repeated)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
return formFields.some((one)=>one.id && (one.id === fieldId || one.id === repeatedFieldId(fieldId)));
|
|
275
|
+
}
|
|
249
276
|
async function resolveAttachmentsFromObs(field, obs) {
|
|
250
277
|
const abortController = new AbortController();
|
|
251
278
|
const attachments = await Promise.all(obs.map((obs)=>getAttachmentByUuid(obs.uuid, abortController).then((response)=>response.data).catch((error)=>{
|
|
@@ -200,10 +200,25 @@ function processObsGroup(obsForSubmission, groupField, fields) {
|
|
|
200
200
|
addObsToList(obsGroup.groupMembers, member.meta.submission.voidedValue);
|
|
201
201
|
}
|
|
202
202
|
});
|
|
203
|
+
if (obsGroup.uuid && obsGroup.groupMembers.length) {
|
|
204
|
+
keepUntouchedMembers(obsGroup, groupField.meta.initialValue.omrsObject);
|
|
205
|
+
}
|
|
203
206
|
if (obsGroup.groupMembers?.length || obsGroup.voided) {
|
|
204
207
|
addObsToList(obsForSubmission, obsGroup);
|
|
205
208
|
}
|
|
206
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* The REST API replaces a stored group's members with the ones submitted. When the server saves the group as a new
|
|
212
|
+
* version, because one of its own fields changed (such as the formFieldPath of a repeat instance renumbered on reload),
|
|
213
|
+
* that version holds only those, and every stored member not submitted is voided with the old version. Each one is
|
|
214
|
+
* referenced by uuid so it is carried into the new version; when the group is not versioned, the references change
|
|
215
|
+
* nothing.
|
|
216
|
+
*/ function keepUntouchedMembers(obsGroup, storedGroup) {
|
|
217
|
+
const submitted = new Set(obsGroup.groupMembers.map((member)=>member.uuid).filter(Boolean));
|
|
218
|
+
storedGroup.groupMembers?.filter((member)=>!member.voided && !submitted.has(member.uuid)).forEach((member)=>obsGroup.groupMembers.push({
|
|
219
|
+
uuid: member.uuid
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
207
222
|
function voidStoredObs(obsList, field) {
|
|
208
223
|
const storedObs = field.meta.initialValue?.omrsObject;
|
|
209
224
|
if (!storedObs) {
|
|
@@ -18,7 +18,8 @@ export declare function hasPreviousObsValueChanged(field: FormField, newValue: a
|
|
|
18
18
|
*
|
|
19
19
|
* Notes:
|
|
20
20
|
* If the query by field-path returns an empty list, the function falls back to querying
|
|
21
|
-
* by concept and uses `claimedObsIds` to exclude already assigned observations.
|
|
21
|
+
* by concept and uses `claimedObsIds` to exclude already assigned observations. Given the
|
|
22
|
+
* form's fields, it also leaves out obs whose path names another of them or a repeat of one.
|
|
22
23
|
*/
|
|
23
|
-
export declare function findObsByFormField(obsList: Array<OpenmrsObs>, claimedObsIds: string[], field: FormField): OpenmrsObs[];
|
|
24
|
+
export declare function findObsByFormField(obsList: Array<OpenmrsObs>, claimedObsIds: string[], field: FormField, formFields?: Array<FormField>): OpenmrsObs[];
|
|
24
25
|
//# sourceMappingURL=obs-adapter.d.ts.map
|
|
@@ -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,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
|
|
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;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,EAC1B,aAAa,EAAE,MAAM,EAAE,EACvB,KAAK,EAAE,SAAS,EAChB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,GAC5B,UAAU,EAAE,CAqBd"}
|
|
@@ -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,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;
|
|
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;AAmID,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
|
@@ -27,7 +27,7 @@ export let assignedObsIds: string[] = [];
|
|
|
27
27
|
export const ObsAdapter: FormFieldValueAdapter = {
|
|
28
28
|
async getInitialValue(field: FormField, sourceObject: any, context: FormContextProps) {
|
|
29
29
|
const encounter = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
|
|
30
|
-
const matchingObs = findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field);
|
|
30
|
+
const matchingObs = findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field, context.formFields);
|
|
31
31
|
if (hasRendering(field, 'file') && matchingObs?.length) {
|
|
32
32
|
return resolveAttachmentsFromObs(field, matchingObs);
|
|
33
33
|
}
|
|
@@ -40,7 +40,7 @@ export const ObsAdapter: FormFieldValueAdapter = {
|
|
|
40
40
|
// an obs already loaded for this encounter stays bound to the field
|
|
41
41
|
const value = extractFieldValue(
|
|
42
42
|
field,
|
|
43
|
-
findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field),
|
|
43
|
+
findObsByFormField(flattenObsList(encounter.obs), assignedObsIds, field, context.formFields),
|
|
44
44
|
false,
|
|
45
45
|
);
|
|
46
46
|
if (!isEmpty(value)) {
|
|
@@ -277,12 +277,14 @@ function handleAttachments(field: FormField, attachments: Attachment[] = []) {
|
|
|
277
277
|
*
|
|
278
278
|
* Notes:
|
|
279
279
|
* If the query by field-path returns an empty list, the function falls back to querying
|
|
280
|
-
* by concept and uses `claimedObsIds` to exclude already assigned observations.
|
|
280
|
+
* by concept and uses `claimedObsIds` to exclude already assigned observations. Given the
|
|
281
|
+
* form's fields, it also leaves out obs whose path names another of them or a repeat of one.
|
|
281
282
|
*/
|
|
282
283
|
export function findObsByFormField(
|
|
283
284
|
obsList: Array<OpenmrsObs>,
|
|
284
285
|
claimedObsIds: string[],
|
|
285
286
|
field: FormField,
|
|
287
|
+
formFields?: Array<FormField>,
|
|
286
288
|
): OpenmrsObs[] {
|
|
287
289
|
const obs = obsList.filter((candidate) => {
|
|
288
290
|
// we ignore the concept for attachments because they're managed from the backend
|
|
@@ -297,13 +299,44 @@ export function findObsByFormField(
|
|
|
297
299
|
// We shall fall back to mapping by the associated concept
|
|
298
300
|
// That being said, we shall find all matching obs and pick the one that wasn't previously claimed.
|
|
299
301
|
if (!obs?.length) {
|
|
300
|
-
const obsByConcept = obsList.filter(
|
|
302
|
+
const obsByConcept = obsList.filter(
|
|
303
|
+
(obs) => obs.concept.uuid == field.questionOptions.concept && !isBoundToAnotherField(obs, field, formFields),
|
|
304
|
+
);
|
|
301
305
|
return claimedObsIds?.length ? obsByConcept.filter((obs) => !claimedObsIds.includes(obs.uuid)) : obsByConcept;
|
|
302
306
|
}
|
|
303
307
|
|
|
304
308
|
return obs;
|
|
305
309
|
}
|
|
306
310
|
|
|
311
|
+
const repeatedFieldId = (fieldId: string) => fieldId.match(/^(.+)_\d+$/)?.[1];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Whether the obs's form field path names another field of the form, or a repeat of one such as `dateStopped_1`,
|
|
315
|
+
* which hydrates it by that path. The concept fallback leaves such an obs to it, as a field that recorded nothing
|
|
316
|
+
* would otherwise take a value from a repeat of itself or from another question on the same concept.
|
|
317
|
+
* A repeat still takes an obs saved under its question's path or that of any repeat of it: it is hydrated from its
|
|
318
|
+
* own group's obs only, and as repeats are numbered in order on hydration, one saved as `dateStopped_2` reopens as
|
|
319
|
+
* `dateStopped_1` once the row before it is deleted. A field of the form whose id only reads like a repeat, such as
|
|
320
|
+
* `item_1` beside `item`, is not one.
|
|
321
|
+
* A repeat of the field itself is told by its path alone, so the field never takes one even without the form's fields.
|
|
322
|
+
*/
|
|
323
|
+
function isBoundToAnotherField(obs: OpenmrsObs, field: FormField, formFields: Array<FormField> = []) {
|
|
324
|
+
const path = obs.formFieldPath;
|
|
325
|
+
if (!path?.startsWith('rfe-forms-')) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
const fieldId = path.slice('rfe-forms-'.length);
|
|
329
|
+
if (repeatedFieldId(fieldId) === field.id) {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
// Repeats are cloned while the encounter is hydrated, so they are not yet among the form's fields
|
|
333
|
+
const repeated = formFields.some((one) => one.id === field.id) ? undefined : repeatedFieldId(field.id);
|
|
334
|
+
if (repeated && (fieldId === repeated || repeatedFieldId(fieldId) === repeated)) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
return formFields.some((one) => one.id && (one.id === fieldId || one.id === repeatedFieldId(fieldId)));
|
|
338
|
+
}
|
|
339
|
+
|
|
307
340
|
async function resolveAttachmentsFromObs(field: FormField, obs: OpenmrsObs[]) {
|
|
308
341
|
const abortController = new AbortController();
|
|
309
342
|
const attachments = await Promise.all(
|
|
@@ -272,11 +272,29 @@ function processObsGroup(obsForSubmission: OpenmrsObs[], groupField: FormField,
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
|
|
275
|
+
if (obsGroup.uuid && obsGroup.groupMembers.length) {
|
|
276
|
+
keepUntouchedMembers(obsGroup, groupField.meta.initialValue.omrsObject as OpenmrsObs);
|
|
277
|
+
}
|
|
278
|
+
|
|
275
279
|
if (obsGroup.groupMembers?.length || obsGroup.voided) {
|
|
276
280
|
addObsToList(obsForSubmission, obsGroup);
|
|
277
281
|
}
|
|
278
282
|
}
|
|
279
283
|
|
|
284
|
+
/**
|
|
285
|
+
* The REST API replaces a stored group's members with the ones submitted. When the server saves the group as a new
|
|
286
|
+
* version, because one of its own fields changed (such as the formFieldPath of a repeat instance renumbered on reload),
|
|
287
|
+
* that version holds only those, and every stored member not submitted is voided with the old version. Each one is
|
|
288
|
+
* referenced by uuid so it is carried into the new version; when the group is not versioned, the references change
|
|
289
|
+
* nothing.
|
|
290
|
+
*/
|
|
291
|
+
function keepUntouchedMembers(obsGroup: Partial<OpenmrsObs>, storedGroup: OpenmrsObs) {
|
|
292
|
+
const submitted = new Set(obsGroup.groupMembers.map((member) => member.uuid).filter(Boolean));
|
|
293
|
+
storedGroup.groupMembers
|
|
294
|
+
?.filter((member) => !member.voided && !submitted.has(member.uuid))
|
|
295
|
+
.forEach((member) => obsGroup.groupMembers.push({ uuid: member.uuid }));
|
|
296
|
+
}
|
|
297
|
+
|
|
280
298
|
function voidStoredObs(obsList: Array<Partial<OpenmrsObs>>, field: FormField) {
|
|
281
299
|
const storedObs = field.meta.initialValue?.omrsObject;
|
|
282
300
|
if (!storedObs) {
|