Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-2872: Fix inconsistent data when editing obsGroups in an encounter #125

Merged
merged 15 commits into from
Mar 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,9 @@ describe('Obs Value Adapter Helper: ', () => {
groupMembers: [
{
uuid: 'some inner uuid',
concept: {
uuid: 'a899e5f2-1350-11df-a1f1-0026b9348838'
},
value: moment('2016-04-21T16:17:46.000+0300').format(
'YYYY-MM-DD HH:mm:ss'
),
Expand All @@ -1112,7 +1115,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
uuid: 'some uuid',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
});

// CASE 3: New group
Expand All @@ -1139,7 +1143,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
concept: 'a8afdb8c-1350-11df-a1f1-0026b9348838',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
});
});

Expand Down Expand Up @@ -1256,16 +1261,31 @@ describe('Obs Value Adapter Helper: ', () => {
expect(payload).toEqual([
{
groupMembers: [
{
uuid: 'uuid 1',
concept: {
uuid: 'a899e444-1350-11df-a1f1-0026b9348838'
},
value: {
uuid: 'a899f51a-1350-11df-a1f1-0026b9348838'
},
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
},
{
value: 21,
uuid: 'uuid 2',
concept: {
uuid: 'a8a07386-1350-11df-a1f1-0026b9348838'
},
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
}
],
uuid: 'some uuid 1',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
},
{
groupMembers: [
Expand All @@ -1278,7 +1298,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
concept: 'a8afdb8c-1350-11df-a1f1-0026b9348838',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
},
{
uuid: 'some uuid 3',
Expand Down Expand Up @@ -1309,7 +1330,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
concept: 'a8afdb8c-1350-11df-a1f1-0026b9348838',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
}
]);
});
Expand Down Expand Up @@ -1369,7 +1391,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
concept: 'a8afdb8c-1350-11df-a1f1-0026b9348838',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
},
{
groupMembers: [
Expand All @@ -1382,7 +1405,8 @@ describe('Obs Value Adapter Helper: ', () => {
],
concept: 'a8afdb8c-1350-11df-a1f1-0026b9348838',
formFieldNamespace: jasmine.stringMatching(/\w+/),
formFieldPath: jasmine.stringMatching(/\w+/)
formFieldPath: jasmine.stringMatching(/\w+/),
voided: false
},
{
concept: 'a8982474-1350-11df-a1f1-0026b9348838',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,39 @@ export class ObsAdapterHelper {
getGroupPayload(node: NodeBase) {
const nodeAsGroup: GroupNode = node as GroupNode;

let childrenPayload = [];
// Get existing obs
let childrenPayload =
ibacher marked this conversation as resolved.
Show resolved Hide resolved
nodeAsGroup?.initialValue?.groupMembers?.map((node) =>
icrc-loliveira marked this conversation as resolved.
Show resolved Hide resolved
this.getOldObsPayload(node)
icrc-loliveira marked this conversation as resolved.
Show resolved Hide resolved
) || [];

let isGroupChanged: boolean = false;
_.each(nodeAsGroup.children, (child) => {
const payload = this.getObsNodePayload(child);
if (payload.length > 0) {
childrenPayload = childrenPayload.concat(payload);
isGroupChanged = true;
if (payload[0].uuid) {
icrc-loliveira marked this conversation as resolved.
Show resolved Hide resolved
if (payload[0].voided) {
childrenPayload.find(
(obs) => obs.uuid == payload[0].uuid
).voided = true;
} else {
childrenPayload.find((obs) => obs.uuid == payload[0].uuid).value =
payload[0].value;
}
} else {
childrenPayload = childrenPayload.concat(payload);
}
}
});

if (childrenPayload.length === 0) {
if (!isGroupChanged) {
return null;
}

const groupPayload: any = {
icrc-loliveira marked this conversation as resolved.
Show resolved Hide resolved
groupMembers: childrenPayload
groupMembers: childrenPayload,
voided: childrenPayload?.every((member) => member.voided === true)
};

if (nodeAsGroup.initialValue) {
Expand Down Expand Up @@ -551,6 +570,15 @@ export class ObsAdapterHelper {
return childrenPayload;
}

getOldObsPayload(oldObs) {
return {
uuid: oldObs.uuid,
concept: oldObs.concept,
value: oldObs.value,
formFieldNamespace: oldObs.formFieldNamespace,
formFieldPath: oldObs.formFieldPath
};
}
icrc-loliveira marked this conversation as resolved.
Show resolved Hide resolved
getObsNodePayload(node: NodeBase): Array<any> {
let payload = [];
switch (this.getObsNodeType(node)) {
Expand Down
Loading