In FHIR, all resources extending DomainResource include a Narrative element. The Narrative provides a human-readable summary of the structured data and is typically used for display and review by clinicians or end users.
Manual Narrative authoring can be labor-intensive and error-prone. This project enables automatic Narrative generation for FHIR resources by leveraging HAPI-FHIR as the FHIR processing engine and Thymeleaf as the templating engine.
This project is licensed under Apache 2.0 with an additional attribution clause. Any use of this code must provide explicit attribution of the original author and repository, as specified in the LICENSE file.
- Entry point:
src/main/java/fr/gouv/esante/fhirNarrativeGenerator/App.java - JSON output writer:
src/main/java/fr/gouv/esante/fhirNarrativeGenerator/JsonFileCreator.java - Properties loader:
src/main/java/fr/gouv/esante/fhirNarrativeGenerator/PropertiesUtil.java - Runtime version helper:
src/main/java/fr/gouv/esante/fhirNarrativeGenerator/VersionUtil.java - Thymeleaf narrative template:
src/main/resources/NamingSystem.html - Template configuration:
src/main/resources/narrative.properties - Execution configuration (input/output paths):
configuration.properties - Build:
pom.xml
- Example input JSON:
target/input/namingSystem_IheRoleCode.json - Example generated outputs:
target/output/namingSystem_ADICAP_withNarrativeGenerated.jsontarget/output/namingSystem_UCUM_withNarrativeGenerated.json- other files under
target/output/
- Unit tests:
src/test/java/fr/gouv/esante/fhirNarrativeGenerator/AppTest.java— reports intarget/surefire-reports/
- Build:
mvn clean package - Run:
mvn org.codehaus.mojo:exec-maven-plugin:3.1.0:java -Dexec.mainClass="fr.gouv.esante.fhirNarrativeGenerator.App"
The application reads JSON files from the directory configured in configuration.properties (inputFileDirectory) and writes results to outputFileDirectory.
- Edit the Thymeleaf template for ConceptMap resources:
src/main/resources/NamingSystem.html - Add new templates for other type of resources: src/main/resources/
- If you move the template, update
src/main/resources/narrative.propertiesand rebuild.
Log4j configuration: src/main/resources/log4j2.properties (also copied to target/classes/).
- Invalid input / JSON parsing: logic in
App.java - File writing:
JsonFileCreator.java - Missing properties:
PropertiesUtil.javaandconfiguration.properties
- Unit tests:
src/test/java/fr/gouv/esante/fhirNarrativeGenerator/AppTest.java - Test reports:
target/surefire-reports/
Edit the referenced files to modify behavior or templates.