This project provides utilities to generate patient summaries from FHIR Bundles, including narrative generation and section extraction, following the International Patient Summary (IPS) specification.
Clone the repository and install dependencies:
git clone <repo-url>
cd fhir-patient-summary
npm install
You can use the ComprehensiveIPSCompositionBuilder
in your TypeScript or JavaScript project to generate an IPS-compliant FHIR Bundle. The builder supports both fluent section addition and a convenient read_bundle()
method to extract all supported sections from a FHIR Bundle.
import { ComprehensiveIPSCompositionBuilder } from './src/generators/fhir_summary_generator';
import { IPSSections } from './src/structures/ips_sections';
const builder = new ComprehensiveIPSCompositionBuilder()
.setPatient(patientResource)
.addSection(IPSSections.ALLERGIES, allergiesArray, 'America/New_York')
.addSection(IPSSections.MEDICATIONS, medicationsArray, 'America/New_York')
.addSection(IPSSections.PROBLEMS, problemsArray, 'America/New_York')
.addSection(IPSSections.IMMUNIZATIONS, immunizationsArray, 'America/New_York');
const bundle = builder.build_bundle(
'example-organization',
'Example Organization',
'https://fhir.icanbwell.com/4_0_0/',
'America/New_York'
);
console.log(JSON.stringify(bundle, null, 2));
import { ComprehensiveIPSCompositionBuilder } from './src/generators/fhir_summary_generator';
import testBundle from './test/fhir-summary-bundle/fixtures/test-bundle.json';
const patientResource = testBundle.entry.find(e => e.resource.resourceType === 'Patient').resource;
const builder = new ComprehensiveIPSCompositionBuilder()
.setPatient(patientResource)
.read_bundle(testBundle, 'Europe/London');
const bundle = builder.build_bundle(
'org-1',
'Example Hospital',
'https://example.com/fhir',
'Europe/London'
);
console.log(JSON.stringify(bundle, null, 2));
- Use
setPatient(patientResource)
to set the patient. - Use
addSection(sectionType, resources, timezone)
to add each IPS section, or useread_bundle(fhirBundle, timezone)
to extract all supported sections from a FHIR Bundle. - Use
build_bundle
to generate the final FHIR Bundle.
To run the test suite:
npm test
src/generators/
: Main logic for summary and narrative generationsrc/types/
: FHIR resource TypeScript typestest/
: Test suites and FHIR bundle fixtures
See LICENSE.