Skip to content

Commit

Permalink
hard-code "code" text into observations
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Sep 26, 2024
1 parent e9e19dd commit 2d8dc74
Show file tree
Hide file tree
Showing 11 changed files with 10,186 additions and 9,251 deletions.
18 changes: 11 additions & 7 deletions packages/fhir-jembi/build/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const generateCode = (schema, mappings) => {

if (schema[type]) {
statements.push(generateEntry(type, schema[type]));
for (const variant of schema[type]) {
const name = getTypeName(variant);
statements.push(generateBuilder(name, variant, mappings[type]));
for (const profile of schema[type]) {
const overriddes = Object.assign({}, mappings[type].any, mappings[type][profile.id])
const name = getTypeName(profile);
statements.push(generateBuilder(name, profile, overriddes));
}
}
}
Expand Down Expand Up @@ -118,7 +119,7 @@ const mapProps = (schema, mappings) => {
// maybe it's ok just to assign the top object hey?
props.push(mapComposite(key, mappings[key], spec));
} else if (spec.typeDef) {
props.push(mapTypeDef(key, spec));
props.push(mapTypeDef(key, mappings[key], spec));
} else {
switch (spec.type) {
case 'string':
Expand All @@ -138,7 +139,7 @@ const mapProps = (schema, mappings) => {
// console.warn(
// `WARNING: using simple mapping for ${schema.id}.${key}`
// );
props.push(mapSimpleProp(key, mappings[key]));
props.push(mapSimpleProp(key, mappings[key], spec));
// TODO: warn unused type
}
}
Expand Down Expand Up @@ -205,6 +206,9 @@ const addDefaults = (propName: string, mapping: Mapping, schema: Schema) => {
// A simple prop will just take what's in the input and map it right across
// Mapping rules could add extra complications here, like aliasing and converting
const mapSimpleProp = (propName: string, mapping: Mapping, schema: Schema) => {
if (propName === 'code') {

}
// This is the actual assignment
const assignProp = assignToInput(
propName,
Expand All @@ -219,7 +223,7 @@ const mapSimpleProp = (propName: string, mapping: Mapping, schema: Schema) => {
// map a type def (ie, a nested object) property by property
// TODO this is designed to handle singletone and array types
// The array stuff adds a lot of complication and I need tests on both formats
const mapTypeDef = (propName: string, schema: Schema) => {
const mapTypeDef = (propName: string, mapping: Mapping, schema: Schema) => {
const statements: any[] = [];

statements.push(
Expand Down Expand Up @@ -364,7 +368,7 @@ const mapTypeDef = (propName: string, schema: Schema) => {
}

let elseStmnt;
const d = addDefaults(propName, undefined, schema);
const d = addDefaults(propName, mapping, schema);
if (d) {
elseStmnt = d;
}
Expand Down
120 changes: 92 additions & 28 deletions packages/fhir-jembi/build/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,106 @@
// this is pretty high level
export default {
Encounter: {
identifier: {
// Force identifier to accept a string
// (the system will be defaulted)
type: 'string',
},
// Specify individual mapping rules for fields here
// or pass field: false to ignore it
// (meta is always ignored)

// serviceProvider will be defaulted
// (I don't really know if we want this but lets see!)
serviceProvider: {
defaults: {
reference: 'Organization/Patient.managingOrganization',
},
},
any: {},
},
Patient: {
// This should automap now, probably as patientReligion
// But it doesn't??
any: {
// This should automap now, probably as patientReligion
// But it doesn't??

// manually map the `religion` key to the patient.religion extension
religion: {
type: 'CodeableConcept',
extension: 'http://hl7.org/fhir/StructureDefinition/patient-religion',
// manually map the `religion` key to the patient.religion extension
religion: {
type: 'CodeableConcept',
extension: 'http://hl7.org/fhir/StructureDefinition/patient-religion',
},
},
},
Observation: {
// id: true,
},
MedicationAdministration: {},
MedicationDispense: {},
MedicationRequest: {},
Medication: {},
CarePlan: {
activity: false // TODO I need to look closely at this
CarePlan: {},
RelatedPerson: {},
Observation: {
// The schema doesn't include text in the codes
// so we have to manually set each one here
'arv-change-category-type-observation': {
code: {
defaults: {
coding: [
{
system: 'http://snomed.info/sct',
code: '182838006',
},
],
text: 'ARV regimen change',
},
},
},
'highest-education-observation': {
code: {
defaults: {
coding: [
{
system: 'http://loinc.org',
code: '82589-3',
},
],
text: 'Highest level of education',
},
},
},
'patient-occupation-observation': {
code: {
defaults: {
coding: [
{
system: 'http://loinc.org',
code: '85658-3',
},
],
text: 'Occupation',
},
},
},
'target-population-observation': {
code: {
defaults: {
coding: [
{
system: 'http://snomed.info/sct',
code: '385436007',
},
],
text: 'Target population',
},
},
},
'arv-regimen-changed-observation': {
code: {
defaults: {
coding: [
{
system: 'http://snomed.info/sct',
code: '182838006',
},
],
text: 'ARV regimen change',
},
},
},
'arv-regimen-change-reason-observation': {
code: {
defaults: {
coding: [
{
system: 'http://loinc.org',
code: 'LL354-2',
},
],
text: 'ARV regimen change reason',
},
},
},
},
RelatedPerson: {}
};
Loading

0 comments on commit 2d8dc74

Please sign in to comment.