Skip to content

Commit

Permalink
Add basic documentation for builders
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Sep 26, 2024
1 parent c551f55 commit 0d37d3c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/fhir-jembi/build/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const generateCode = (schema, mappings) => {
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 All @@ -48,6 +49,15 @@ export default generateCode;
// TODO this isn't pretty but it works
// Note that I really need to standardize name builders for these things
const generateEntry = (resourceType: string, variants: Schema[]) => {
const comment = parse(`/**
* Create a FHIR ${resourceType} resource.
* @public
* @function
* @param {string} type - The profile id for the resource variant
* @param props - Properties to apply to the resource
*/
`)

const map = b.variableDeclaration('const', [
b.variableDeclarator(
b.identifier('mappings'),
Expand All @@ -63,20 +73,24 @@ const generateEntry = (resourceType: string, variants: Schema[]) => {
)
),
]);

// TODO handle errors for invalid types
const mapper = parse(`
return mappings[type](props)
`);

return b.exportDeclaration(
return mappings[type](props)
`);
const ex = b.exportDeclaration(
false,
b.functionDeclaration(
b.identifier(getBuilderName(resourceType)),
[b.identifier('type'), b.identifier(INPUT_NAME)],
b.blockStatement([map, ...mapper.program.body])
)
),
);

ex.comments = comment.program.comments;
ex.comments[0].leading = true;

return ex;
};

const generateBuilder = (resourceName, schema, mappings) => {
Expand Down
63 changes: 63 additions & 0 deletions packages/fhir-jembi/src/builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import * as util from "./Utils.js";
import _ from "lodash";

/**
* Create a FHIR Encounter resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function encounter(type, props) {
const mappings = {
"entry-from-outside-target-facility-encounter": encounter_entry_from_outside_target_facility_encounter,
Expand Down Expand Up @@ -833,6 +840,13 @@ function encounter_target_facility_encounter(props) {
return resource;
}

/**
* Create a FHIR Patient resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function patient(type, props) {
const mappings = {
"patient": patient_patient
Expand Down Expand Up @@ -1234,6 +1248,13 @@ function patient_patient(props) {
return resource;
}

/**
* Create a FHIR MedicationAdministration resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function medicationAdministration(type, props) {
const mappings = {
"arv-medication-administration": medicationAdministration_arv_medication_administration,
Expand Down Expand Up @@ -1844,6 +1865,13 @@ function medicationAdministration_fluconazole_preventive_therapy_medication_admi
return resource;
}

/**
* Create a FHIR MedicationDispense resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function medicationDispense(type, props) {
const mappings = {
"arv-medication-dispense": medicationDispense_arv_medication_dispense,
Expand Down Expand Up @@ -2689,6 +2717,13 @@ function medicationDispense_generic_medication_dispense(props) {
return resource;
}

/**
* Create a FHIR MedicationRequest resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function medicationRequest(type, props) {
const mappings = {
"arv-medication-request": medicationRequest_arv_medication_request,
Expand Down Expand Up @@ -3980,6 +4015,13 @@ function medicationRequest_tpt_medication_request(props) {
return resource;
}

/**
* Create a FHIR Medication resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function medication(type, props) {
const mappings = {
"arv-regimen-medication": medication_arv_regimen_medication,
Expand Down Expand Up @@ -4446,6 +4488,13 @@ function medication_tpt_medication(props) {
return resource;
}

/**
* Create a FHIR CarePlan resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function carePlan(type, props) {
const mappings = {
"art-follow-up-careplan": carePlan_art_follow_up_careplan,
Expand Down Expand Up @@ -5543,6 +5592,13 @@ function carePlan_tpt_careplan(props) {
return resource;
}

/**
* Create a FHIR RelatedPerson resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function relatedPerson(type, props) {
const mappings = {
"related-person": relatedPerson_related_person
Expand Down Expand Up @@ -5807,6 +5863,13 @@ function relatedPerson_related_person(props) {
return resource;
}

/**
* Create a FHIR Observation resource.
* @public
* @function
* @param {string} type - the profile id for the resource variant
* @param props - properties to apply to the resource
*/
export function observation(type, props) {
const mappings = {
"active-tb-observation": observation_active_tb_observation,
Expand Down

0 comments on commit 0d37d3c

Please sign in to comment.