@openmrs/ngx-formentry 5.0.1-pre.339 → 5.0.1-pre.342

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.
@@ -13743,6 +13743,7 @@ class DiagnosisValueAdapter {
13743
13743
  _createDiagnosesPayload(diagnosisNodes, existingDiagnoses) {
13744
13744
  const payload = [];
13745
13745
  let deletedDiagnoses = [];
13746
+ // Add new diagnosis to payload
13746
13747
  diagnosisNodes?.forEach((node) => {
13747
13748
  if (node instanceof ArrayNode) {
13748
13749
  node.control.value
@@ -13750,8 +13751,12 @@ class DiagnosisValueAdapter {
13750
13751
  .forEach((value) => {
13751
13752
  // Create Payload
13752
13753
  const payloadDiagnosis = this._createPayloadDiagnosis(value[node.question.key], node.question.extras);
13753
- // Validate if is new value
13754
- payload.push(payloadDiagnosis);
13754
+ const isNewDiagnosis = existingDiagnoses.every((d) => d.diagnosis.coded.uuid !== value[node.question.key] ||
13755
+ d.certainty !== "CONFIRMED" ||
13756
+ d.rank !== node.question.extras.questionOptions.rank);
13757
+ if (isNewDiagnosis) {
13758
+ payload.push(payloadDiagnosis);
13759
+ }
13755
13760
  });
13756
13761
  }
13757
13762
  if (node instanceof ArrayNode) {
@@ -13805,19 +13810,19 @@ class DiagnosisValueAdapter {
13805
13810
  };
13806
13811
  return diagnosis;
13807
13812
  }
13808
- _getDeletedDiagnoses(payloadDiagnoses, existingDiagnoses) {
13809
- return existingDiagnoses
13810
- ?.filter((e) => {
13811
- return !payloadDiagnoses.find((p) => {
13812
- let isSame = !e.voided && p.diagnosis.coded === e.diagnosis.coded.uuid;
13813
- return isSame;
13813
+ _getDeletedDiagnoses(diagnosisNodes, existingDiagnoses) {
13814
+ return existingDiagnoses.filter(existingDiagnosis => {
13815
+ return !diagnosisNodes?.some(node => {
13816
+ if (node instanceof ArrayNode) {
13817
+ return node.control.value.some(value => {
13818
+ return value[node.question.key] === existingDiagnosis.diagnosis.coded.uuid &&
13819
+ existingDiagnosis.rank === node.question.extras.questionOptions.rank &&
13820
+ existingDiagnosis.certainty === 'CONFIRMED';
13821
+ });
13822
+ }
13823
+ return false;
13814
13824
  });
13815
- })
13816
- .map((d) => {
13817
- let diagnosisPayload = this._convert(d);
13818
- diagnosisPayload.voided = true;
13819
- return diagnosisPayload;
13820
- });
13825
+ }).map(existingDiagnosis => ({ uuid: existingDiagnosis.uuid, voided: true }));
13821
13826
  }
13822
13827
  _updatedOldDiagnoses(payloadDiagnoses, existingDiagnoses) {
13823
13828
  payloadDiagnoses.forEach((p) => {
@@ -13933,7 +13938,7 @@ class DiagnosisValueAdapter {
13933
13938
  hasDiagnosisNodeChanged(nodeAsGroup) {
13934
13939
  const childrenNodes = Object.values(nodeAsGroup.children);
13935
13940
  for (let childNode of childrenNodes) {
13936
- if (childNode.control.value !== childNode.initialValue) {
13941
+ if (childNode.control.value !== nodeAsGroup.initialValue?.primaryDiagnosisId) {
13937
13942
  return true;
13938
13943
  }
13939
13944
  }