Add US Core profiles TypeScript example (CSV to FHIR Bundle)#30
Open
Add US Core profiles TypeScript example (CSV to FHIR Bundle)#30
Conversation
Companion to the "Tutorial: US Core Profiles in TypeScript with @atomic-ehr/codegen" blog post. Demonstrates: - Generating typed profile classes for US Core Patient and US Core Blood Pressure plus base Bundle from hl7.fhir.r4.core - Parsing a small CSV (5 patients, each with one BP reading) - Converting rows to validated USCorePatientProfile and USCoreBloodPressureProfile instances - Packaging them as a transaction Bundle with urn:uuid cross-references - Reading the bundle back with typed getters to compute average BP Code verified end-to-end: tsc --strict passes, npx tsx load.ts prints "Avg BP: 125.2/82.0 mmHg (n=5)". Generated fhir-types/ is committed so readers can browse the output without running the generator.
Switches the example to @atomic-ehr/codegen@canary (0.0.13-canary with
PR #144 merged). Reference.reference now accepts all FHIR literal
reference forms -- urn:uuid:<uuid>, http://..., urn:oid:..., #fragment,
in addition to Patient/<id>.
Drops the inline cast: subject.reference takes the urn:uuid placeholder
directly. rowToBP's patientRef parameter is narrowed to
\`urn:uuid:\${string}\` so the typing carries the bundle placeholder
semantics all the way through.
Regenerate fhir-types/ with the canary. README note on urn:uuid
updated to reflect the fix.
Closes atomic-ehr/codegen#141.
rowToPatient now builds a plain Patient resource first and then calls USCorePatientProfile.apply(basePatient) to wrap it with the profile. Reads cleaner than the previous create() + Object.assign pattern and mirrors the tutorial narrative. tsconfig.json added so tsc picks up @types/node (node:fs / node:crypto imports fail to resolve without "types": ["node"]).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New example at
developer-experience/atomic-ehr-codegen-typescript-us-core-profiles/— a working CSV-to-FHIR-Bundle converter using@atomic-ehr/codegenprofile class generation for US Core. Companion code to the blog tutorial Tutorial: US Core Profiles in TypeScript with @atomic-ehr/codegen.What the example does:
Bundlefromhl7.fhir.r4.core.patients.csv(5 patients, one BP reading each — race-coded with OMB categories).USCorePatientProfile+USCoreBloodPressureProfile.urn:uuidcross-references.USCoreBloodPressureProfile.from(),getSystolic(),getDiastolic()) to compute an average BP.Verified
npx tscpasses under--strict.npx tsx load.tsprintsAvg BP: 125.2/82.0 mmHg (n=5).bundle.jsonoutput has correctmeta.profilestamps, auto-populated category/component discriminators, and urn:uuid cross-refs.Files
generate.tsfhir-types/load.tspatients.csvfhir-types/tsconfig.json--strict,types: ["node"]fornode:fs/node:cryptoresolutionpackage.json@atomic-ehr/codegen@canary(for the widenedReferencetype from codegen#144),tsx,typescript,@types/nodeREADME.md.gitignorenode_modules/,.codegen-cache/,bundle.jsonDependency note
@atomic-ehr/codegenis pinned to the currentcanary(which includes PR #144 wideningReference.referenceto accepturn:uuidplaceholders used in transaction bundles). Once0.0.14ships with that fix, this pin should move to plain^0.0.14.Test plan
npm installsucceedsnpx tsx generate.tsregeneratesfhir-types/identically to what's committednpx tsx load.tsprintsLoaded 5 rows,Wrote bundle with 10 entries,Avg BP: 125.2/82.0 mmHg (n=5)npx tscexits with 0bundle.jsonto a local Aidbox and verify theurn:uuidreferences resolved to real Patient IDs