Skip to content

Updating Generated ES6 classes

Dylan Hall edited this page Jun 11, 2019 · 6 revisions

Notes on updating the generated SHR ES6 Classes

The SHR ES6 Generator uses a "Class Registry" in order to minimize the effort needed for users to maintain their modifications across re-generations of the same spec. Rather than modifying the generated classes directly and having to reimplement those changes across re-generations of the spec, affected classes should instead be subclassed, and then added to the registry in the slot of the class they are subclassing.

The ClassRegistry class defines a map of [namespace][name] => class object, and is initialized in the init.js file to avoid circular dependencies. In Flux, any "fix classes" will be stored in the src/model/fluxExtensions folder. Each time the classes are re-generated these classes should be reviewed to ensure the modifications are still applicable. If a specific modification is no longer relevant, it should be removed and "unregistered" in init.js.

init.js

src/model/init.js is the main entry point that initializes the SHR model classes. The function here is now also used to register the appropriate subclasses in the class registry:

function init() {
  setObjectFactory(FluxObjectFactory);

  ClassRegistry.initialize();
  ClassRegistry.set('shr.base', 'Entry', EntryFix);
  ClassRegistry.set('shr.encounter', 'Encounter', EncounterFix);
  ClassRegistry.set('shr.core', 'Coding', CodingFix);
  ClassRegistry.set('shr.core', 'CodeableConcept', CodeableConceptFix);
  ClassRegistry.set('shr.base', 'Reason', ReasonFix);
  ClassRegistry.set('shr.medication', 'MedicationRequested', MedicationRequestedFix);
}
Clone this wiki locally