Skip to content

Updating Generated ES6 classes

Dylan Hall edited this page Feb 25, 2019 · 6 revisions

Notes on updating the generated SHR ES6 Classes

json-helper.js

  1. Flux has added the following line to createInstance() in order to handle null values in JSON:
  if (value == null) return null;

Insert this line before the if (typeof value === 'object') block (as of 5/3/2018, this is line 134). The additional line allows you to set { "Value": null } properly.

ES6 Classes

  1. Flux created SourceClinicalNote while it is still in development in the SHR. Due to this, some manual edits to the generated classes is needed:
  • Manually create the src/model/shr/base/SourceClinicalNote.js file.
  • Add get and set methods for SourceClinicalNotes in src/model/shr/base/Entry.js.
  1. Until this issue is resolved: https://github.com/standardhealth/shr-es6-export/issues/37 the generated Coding and CodeableConcept classes do not support implicit mapping from codes. Current workaround is to manually update the fromFHIR methods in these 2 classes, and add a case where the fhir parameter is a string instead of the expected object: Coding.js
  static fromFHIR(fhir, shrId=uuid(), allEntries=[], mappedResources={}, referencesOut=[], asExtension=false) {
    const inst = new Coding();
    if (typeof fhir === 'string') {
        inst.code = FHIRHelper.createInstanceFromFHIR('shr.core.Code', fhir, shrId, allEntries, mappedResources, referencesOut, false);
        inst.displayText = FHIRHelper.createInstanceFromFHIR('shr.core.DisplayText', fhir, shrId, allEntries, mappedResources, referencesOut, false);
    } else {
      if (fhir['system'] != null) {
        inst.codeSystem = FHIRHelper.createInstanceFromFHIR('shr.core.CodeSystem', fhir['system'], shrId, allEntries, mappedResources, referencesOut, false);
      }
      if (fhir['version'] != null) {
        inst.codeSystemVersion = FHIRHelper.createInstanceFromFHIR('shr.core.CodeSystemVersion', fhir['version'], shrId, allEntries, mappedResources, referencesOut, false);
      }
      if (fhir['code'] != null) {
        inst.code = FHIRHelper.createInstanceFromFHIR('shr.core.Code', fhir['code'], shrId, allEntries, mappedResources, referencesOut, false);
      }
      if (fhir['display'] != null) {
        inst.displayText = FHIRHelper.createInstanceFromFHIR('shr.core.DisplayText', fhir['display'], shrId, allEntries, mappedResources, referencesOut, false);
      }
    }
    return inst;
  }

CodeableConcept.js

  static fromFHIR(fhir, shrId=uuid(), allEntries=[], mappedResources={}, referencesOut=[], asExtension=false) {
    const inst = new CodeableConcept();
    if (typeof fhir === 'string') {
      inst.coding = inst.coding || [];
      const inst_coding = FHIRHelper.createInstanceFromFHIR('shr.core.Coding', fhir, shrId, allEntries, mappedResources, referencesOut, false);
      inst.coding.push(inst_coding);

      inst.displayText = FHIRHelper.createInstanceFromFHIR('shr.core.DisplayText', fhir, shrId, allEntries, mappedResources, referencesOut, false);
    } else {
      for (const fhir_coding of fhir['coding'] || []) {
        inst.coding = inst.coding || [];
        const inst_coding = FHIRHelper.createInstanceFromFHIR('shr.core.Coding', fhir_coding, shrId, allEntries, mappedResources, referencesOut, false);
        inst.coding.push(inst_coding);
      }
      if (fhir['text'] != null) {
        inst.displayText = FHIRHelper.createInstanceFromFHIR('shr.core.DisplayText', fhir['text'], shrId, allEntries, mappedResources, referencesOut, false);
      }
      if (asExtension) {
        inst.value = fhir['valueCodeableConcept'];
      }
    }

    return inst;
  }
Clone this wiki locally