openchs-models 1.33.66 → 1.33.68

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.
@@ -270,10 +270,6 @@ class AbstractEncounter extends _BaseEntity.default {
270
270
  const inCancelObservations = new _ObservationsHolder.default(this.cancelObservations).replaceMediaObservation(originalValue, newValue, conceptUUID);
271
271
  return inObservations || inCancelObservations;
272
272
  }
273
- replaceObservation(originalValue, newValue) {
274
- new _ObservationsHolder.default(this.observations).updateObservationBasedOnValue(originalValue, newValue);
275
- new _ObservationsHolder.default(this.cancelObservations).updateObservationBasedOnValue(originalValue, newValue);
276
- }
277
273
  getEntityTypeName() {
278
274
  return this.encounterType.name;
279
275
  }
@@ -642,9 +642,6 @@ class Individual extends _BaseEntity.default {
642
642
  replaceMediaObservation(originalValue, newValue, conceptUUID) {
643
643
  return new _ObservationsHolder.default(this.observations).replaceMediaObservation(originalValue, newValue, conceptUUID);
644
644
  }
645
- replaceObservation(originalValue, newValue) {
646
- new _ObservationsHolder.default(this.observations).updateObservationBasedOnValue(originalValue, newValue);
647
- }
648
645
 
649
646
  //TODO use polymorphism to avoid if checks based on this
650
647
  isPerson() {
@@ -24,46 +24,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
24
24
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
25
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
26
26
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
- // Helper function to find media observation by value
28
- const findMediaObservationByValue = (observations, targetValue) => {
29
- if (!observations || !Array.isArray(observations)) return null;
30
- return _lodash.default.find(observations, obs => {
31
- // Check direct value
32
- if (obs.getValue && obs.getValue() === targetValue) return true;
33
-
34
- // Check coded values (for MultipleCodedValues)
35
- const valueJSON = obs.valueJSON;
36
- if (valueJSON && valueJSON.answer && Array.isArray(valueJSON.answer)) {
37
- return valueJSON.answer.includes(targetValue);
38
- }
39
- return false;
40
- });
41
- };
42
-
43
- // Helper function to update media value
44
- const updateMediaValue = (mediaObs, oldVal, newVal) => {
45
- if (!mediaObs) return false;
46
-
47
- // For coded values, we need to update the array content
48
- if (mediaObs.valueJSON && mediaObs.valueJSON.answer && Array.isArray(mediaObs.valueJSON.answer)) {
49
- const answerIndex = mediaObs.valueJSON.answer.indexOf(oldVal);
50
- if (answerIndex >= 0) {
51
- mediaObs.valueJSON.answer[answerIndex] = newVal;
52
- return true;
53
- }
54
- } else {
55
- // Regular value update
56
- mediaObs.setValue(mediaObs.concept.getValueWrapperFor(newVal));
57
- return true;
58
- }
59
- return false;
60
- };
61
-
62
- // Process each question group observation
63
- const processQuestionGroupObservations = (observations, oldVal, newVal) => {
64
- const mediaObs = findMediaObservationByValue(observations, oldVal);
65
- return mediaObs ? updateMediaValue(mediaObs, oldVal, newVal) : false;
66
- };
67
27
  class ObservationsHolder {
68
28
  constructor(observations) {
69
29
  this.observations = observations;
@@ -84,9 +44,6 @@ class ObservationsHolder {
84
44
  getObservation(concept) {
85
45
  return this.findObservation(concept);
86
46
  }
87
- findObservationByValue(value) {
88
- return _lodash.default.find(this.observations, observation => observation.getValue() === value);
89
- }
90
47
 
91
48
  /*
92
49
  Called from the wizard on changes done by the user for primitive fields (including Date)
@@ -431,49 +388,6 @@ class ObservationsHolder {
431
388
  }
432
389
  }
433
390
 
434
- //private
435
- updateObservationBasedOnValue(oldValue, newValue) {
436
- // Try to find at top level first
437
- const observation = this.findObservationByValue(oldValue);
438
- if (observation) {
439
- observation.setValue(observation.concept.getValueWrapperFor(newValue));
440
- return true;
441
- }
442
-
443
- // Search in nested structures if not found at top level
444
- let updated = false;
445
-
446
- // Iterate through all observations
447
- _lodash.default.forEach(this.observations, obs => {
448
- // Skip non-question group observations
449
- if (obs.concept.datatype !== _Concept.default.dataType.QuestionGroup) return;
450
- const valueWrapper = obs.getValueWrapper && obs.getValueWrapper();
451
- if (!valueWrapper) return;
452
-
453
- // Handle RepeatableQuestionGroup
454
- if (valueWrapper.isRepeatable && valueWrapper.isRepeatable()) {
455
- const allGroups = valueWrapper.getAllQuestionGroupObservations && valueWrapper.getAllQuestionGroupObservations();
456
- if (allGroups && allGroups.length) {
457
- // Check each group in the repeatable question group
458
- allGroups.forEach(group => {
459
- const groupObservations = group.getValue && group.getValue();
460
- if (processQuestionGroupObservations(groupObservations, oldValue, newValue)) {
461
- updated = true;
462
- }
463
- });
464
- }
465
- }
466
- // Handle regular QuestionGroup
467
- else {
468
- const groupObservations = valueWrapper.getValue && valueWrapper.getValue();
469
- if (processQuestionGroupObservations(groupObservations, oldValue, newValue)) {
470
- updated = true;
471
- }
472
- }
473
- });
474
- return updated;
475
- }
476
-
477
391
  // Helper method to update media value in an observation
478
392
  _updateMediaValueInObservation(observation, oldValue, newValue) {
479
393
  if (!observation) return false;
@@ -482,7 +396,13 @@ class ObservationsHolder {
482
396
 
483
397
  // Handle ImageV2 type
484
398
  if (observation.concept.datatype === _Concept.default.dataType.ImageV2) {
485
- const mediaObjects = JSON.parse(valueWrapper.getValue());
399
+ let mediaObjects;
400
+ try {
401
+ mediaObjects = JSON.parse(valueWrapper.getValue());
402
+ } catch (e) {
403
+ // A malformed value can't reference the file; one bad obs must not crash the whole scan.
404
+ return false;
405
+ }
486
406
  let updated = false;
487
407
  const newAnswers = _lodash.default.map(mediaObjects, mediaObject => {
488
408
  if (mediaObject.uri === oldValue) {
@@ -492,7 +412,7 @@ class ObservationsHolder {
492
412
  return mediaObject;
493
413
  });
494
414
  if (updated) {
495
- observation.valueJSON = new _PrimitiveValue.default(JSON.stringify(newAnswers), _Concept.default.dataType.ImageV2);
415
+ observation.valueJSON = new _PrimitiveValue.default(JSON.stringify(newAnswers), _Concept.default.dataType.ImageV2, valueWrapper.answerSource);
496
416
  return true;
497
417
  }
498
418
  }
@@ -501,15 +421,19 @@ class ObservationsHolder {
501
421
  const answers = valueWrapper.getValue();
502
422
  const oldValueIndex = _lodash.default.indexOf(answers, oldValue);
503
423
  if (oldValueIndex >= 0) {
424
+ // Duplicate occurrences are not meaningful for media values — collapse them
425
+ // into the single replaced entry.
504
426
  const newAnswers = _lodash.default.reject(answers, answer => answer === oldValue);
505
427
  newAnswers.splice(oldValueIndex, 0, newValue);
506
- observation.valueJSON = new _MultipleCodedValues.default(newAnswers);
428
+ observation.valueJSON = new _MultipleCodedValues.default(newAnswers, valueWrapper.answerSource);
507
429
  return true;
508
430
  }
509
431
  }
510
432
  // Handle single coded value
511
433
  else if (valueWrapper.getValue() === oldValue) {
512
- observation.valueJSON = new _SingleCodedValue.default(newValue);
434
+ const newWrapper = observation.concept.getValueWrapperFor(newValue);
435
+ newWrapper.answerSource = valueWrapper.answerSource;
436
+ observation.valueJSON = newWrapper;
513
437
  return true;
514
438
  }
515
439
  return false;
@@ -524,7 +448,7 @@ class ObservationsHolder {
524
448
  const groupObservations = group && group.getValue && group.getValue();
525
449
  if (!Array.isArray(groupObservations)) return;
526
450
  _lodash.default.forEach(groupObservations, childObs => {
527
- if (_Concept.default.dataType.Media.includes(childObs.concept.datatype) && this._updateMediaValueInObservation(childObs, oldValue, newValue)) {
451
+ if (childObs.concept.isMediaConcept() && this._updateMediaValueInObservation(childObs, oldValue, newValue)) {
528
452
  updated = true;
529
453
  }
530
454
  });
@@ -540,7 +464,7 @@ class ObservationsHolder {
540
464
  replaceMediaObservation(oldValue, newValue, conceptUUID) {
541
465
  let updated = false;
542
466
  _lodash.default.forEach(this.observations, obs => {
543
- if (_Concept.default.dataType.Media.includes(obs.concept.datatype)) {
467
+ if (obs.concept.isMediaConcept()) {
544
468
  if (this._updateMediaValueInObservation(obs, oldValue, newValue)) updated = true;
545
469
  } else if (obs.concept.datatype === _Concept.default.dataType.QuestionGroup) {
546
470
  const wrapper = obs.getValueWrapper && obs.getValueWrapper();
@@ -460,10 +460,6 @@ class ProgramEnrolment extends _BaseEntity.default {
460
460
  const inExitObservations = new _ObservationsHolder.default(this.programExitObservations).replaceMediaObservation(originalValue, newValue, conceptUUID);
461
461
  return inObservations || inExitObservations;
462
462
  }
463
- replaceObservation(originalValue, newValue) {
464
- new _ObservationsHolder.default(this.observations).updateObservationBasedOnValue(originalValue, newValue);
465
- new _ObservationsHolder.default(this.programExitObservations).updateObservationBasedOnValue(originalValue, newValue);
466
- }
467
463
  getName() {
468
464
  return "ProgramEnrolment";
469
465
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "openchs-models",
3
3
  "description": "OpenCHS data model to be used by front end clients",
4
- "version": "1.33.66",
4
+ "version": "1.33.68",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",