Skip to content

Module: husky fhir emed ch epr

Quentin Ligier edited this page Feb 17, 2023 · 2 revisions

Module: husky-fhir-emed-ch-epr

This is the module dedicated to the CH-EMED-EPR IG.

It is built upon the HAPI FHIR library, which does most of the work of implementing resources, providing parser and serializer. Resources are extended to provide a better API.

Parsing/serializing documents

You can use HAPI's parser to get the standard resources, or our own ChEmedEprParser:

final var parser = new ChEmedEprParser(FhirContext.forR4Cached());
final var document = (ChEmedEprDocumentMtp) parser.parse(jsonOrXml, EmedDocumentType.MTP);

final var json = parser.serialize(document, EncodingEnum.JSON);
final var xml = parser.serializePrettyPrint(document, EncodingEnum.XML);

⚠️ Parsing PML documents with ChEmedEprParser does not produce the right class types because HAPI's parser cannot distinguish between a ChEmedEprMedicationStatementPml and a ChEmedEprMedicationStatementMtp. This only happens in PML documents.

Creating documents

Easier done with the custom resources:

final UUID id = UUID.randomUUID();

final var composition = new ChEmedEprCompositionPmlc(id, date, language);
composition.getCardSection(); // Force creation of the required section

final var document = new ChEmedEprDocumentPmlc(id, timestamp);
document.getCompositionEntry().setResource(composition).setFullUrl(Uuids.URN_PREFIX + id);
// ...

Validating documents

A validator pre-loaded with the last IG version is available in ChEmedEprValidator:

final var validator = new ChEmedEprValidator(FhirContext.forR4Cached());
final var result = validator.validateDocumentBundle(document);
if (!result.isSuccessful()) {
    System.out.println(String.format("[%s] %s [%s] in %s",
        message.getSeverity().name(),
        message.getMessage(),
        message.getMessageId(),
        message.getLocationString()));
}