Skip to content

Commit

Permalink
fhir-jembi: handle reference types
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Sep 12, 2024
1 parent ca9e6da commit fa38639
Show file tree
Hide file tree
Showing 5 changed files with 1,078 additions and 1,004 deletions.
15 changes: 13 additions & 2 deletions packages/fhir-jembi/build/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ const mapProps = (schema, mappings) => {
} else {
switch (spec.type) {
case 'string':
case 'Reference':
case 'Period':
props.push(mapSimpleProp(key, mappings[key]));
break;
case 'Reference':
props.push(mapReference(key, mappings[key], spec));
break;
case 'Identifier':
props.push(mapIdentifier(key, mappings[key] || {}, spec));
break;
Expand Down Expand Up @@ -382,6 +384,15 @@ const mapExtension = (propName: string, mapping: Mapping) => {
return ifPropInInput(propName, [callBuilder]);
};

const mapReference = (propName: string, _mapping: Mapping, _schema: Schema) => {
const callBuilder = b.callExpression(
b.memberExpression(b.identifier('util'), b.identifier('reference')),
[b.memberExpression(b.identifier(INPUT_NAME), b.identifier(propName))]
);

return ifPropInInput(propName, [assignToInput(propName, callBuilder)]);
};

// this will ensure a meta prop on the data
const addMeta = (schema, _mapping) => {
return b.expressionStatement(
Expand All @@ -398,7 +409,7 @@ const addMeta = (schema, _mapping) => {
);
};

const mapIdentifier = (name: string, mapping: Mapping, schema: Schema) => {
const mapIdentifier = (name: string, _mapping: Mapping, schema: Schema) => {
const defaultSystem = schema.defaults?.system;

const statements: StatementKind[] = [];
Expand Down
20 changes: 20 additions & 0 deletions packages/fhir-jembi/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,23 @@ export const concept = (text, ...codings) => {

return result;
};

// opts is { type, identifier, display}
export const reference = (ref, opts) => {
// if passed a rull reference, just return it
if (ref.reference) {
return ref;
}

const result = {};

if (typeof ref === 'string') {
result.reference = ref;
}

if (opts) {
Object.assign(result, opts);
}

return result;
};
Loading

0 comments on commit fa38639

Please sign in to comment.