standardhealth / shr-es6-export

ES6 library for exporting SHR models to ES6 classes
Apache License 2.0
3 stars 0 forks source link

fromFHIR incorrect mapping between reference and Value of mapped object #56

Open dehall opened 5 years ago

dehall commented 5 years ago

Observed using mCODE 0.9 spec:

Definition of Encounter:

Abstract Element:   EncounterOrEpisode
Based on:           DomainResource
[...]
1..1            SubjectOfRecord is type PatientSubjectOfRecord  // EpisodeOfCare restricted in v2 (otherwise could be Patient or Group)

EntryElement:   Encounter
Based on:       EncounterOrEpisode

Encounter maps to Encounter:
[...]
    SubjectOfRecord maps to patient

    Element:        PatientSubjectOfRecord
    Based on:       ObservationSubjectOfRecord
    Value:          ref(Patient)

Generated FHIR profile:

      {
        "path": "Encounter.patient",
        "short": "The patient present at the encounter",
        "definition": "The patient present at the encounter.",
        "comments": "While the encounter is always about the patient, the patient may not actually be known in all contexts of use.",
        "alias": [
          "patient"
        ],
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Reference",
            "profile": [
              "http://hl7.org/fhir/us/shr/DSTU2/StructureDefinition/shr-core-Patient"
            ]
          }
        ],
        "isSummary": true,
        "mapping": [
          {
            "identity": "v2",
            "map": "PID-3"
          },
          {
            "identity": "rim",
            "map": ".participation[typeCode=SBJ]/role[classCode=PAT]"
          },
          {
            "identity": "w5",
            "map": "who.focus"
          },
          {
            "identity": "shr",
            "map": "<shr.core.PatientSubjectOfRecord>"
          }
        ],
        "id": "Encounter.patient",
        "base": {
          "path": "Encounter.patient",
          "min": 0,
          "max": "1"
        }
      },

Resulting ES6 class fromFHIR method:

    if (fhir['patient'] != null) {
      const entryId = fhir['patient']['reference'];
      if (!mappedResources[entryId]) {
        const referencedEntry = allEntries.find(e => e.fullUrl === entryId);
        if (referencedEntry) {
          mappedResources[entryId] = FHIRHelper.createInstanceFromFHIR('shr.core.Patient', referencedEntry['resource'], 'undefined', shrId, allEntries, mappedResources, referencesOut);
        }
      }
      inst.subjectOfRecord = mappedResources[entryId];
    }

The issue here is that subjectOfRecord is getting populated with a Patient object, when it should be populated with a PersonSubjectOfRecord object where the value is a ref(Patient). It's unclear how often this occurs across the spec