Class ChEmedEprParser
java.lang.Object
org.projecthusky.fhir.emed.ch.epr.service.ChEmedEprParser
A parser for the FHIR CH-EMED-EPR IG resources. It can both serialize and parse (deserialize) documents.
- Author:
- Quentin Ligier
- Implementation Note:
- Parsers are cheap to create and may not be thread-safe. They're created on-the-fly for each operation.
-
Constructor Summary
ConstructorsConstructorDescriptionChEmedEprParser(@Nullable ca.uhn.fhir.context.FhirContext fhirR4Context) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected ca.uhn.fhir.parser.IParsergetParser(ca.uhn.fhir.rest.api.EncodingEnum encoding, @Nullable EmedDocumentType type) Creates a FHIR parser for the given encoding.<T extends ChEmedEprDocument>
Tparse(String resource, EmedDocumentType type) Parses the given string (JSON or XML) as a CH-EMED-EPR document Bundle.protected voidPost-processing for further needed refining/transformations after the initial HAPI parsing.serialize(org.hl7.fhir.r4.model.Bundle documentBundle, ca.uhn.fhir.rest.api.EncodingEnum encoding) Encodes the CH-EMED-EPR document Bundle to a string, in either XML, JSON, NDJSON or RDF format.serializePrettyPrint(org.hl7.fhir.r4.model.Bundle documentBundle, ca.uhn.fhir.rest.api.EncodingEnum encoding) Encodes the CH-EMED-EPR document Bundle to a string, in either XML, JSON, NDJSON or RDF format.
-
Constructor Details
-
ChEmedEprParser
public ChEmedEprParser(@Nullable ca.uhn.fhir.context.FhirContext fhirR4Context) Constructor.- Parameters:
fhirR4Context- The non-null FHIR context (R4).
-
-
Method Details
-
parse
Parses the given string (JSON or XML) as a CH-EMED-EPR document Bundle.The resource shall be validated before, with
ChEmedEprValidator.- Parameters:
resource- The document Bundle representation as XML, JSON or RDF.type- The type of eMed document.
-
serialize
public String serialize(org.hl7.fhir.r4.model.Bundle documentBundle, ca.uhn.fhir.rest.api.EncodingEnum encoding) Encodes the CH-EMED-EPR document Bundle to a string, in either XML, JSON, NDJSON or RDF format. The parser will output in condensed form, with no newlines or indenting; the resulting string is smaller.- Parameters:
documentBundle- The document Bundle to serialize.encoding- The desired encoding.- Returns:
- the serialized document.
-
serializePrettyPrint
public String serializePrettyPrint(org.hl7.fhir.r4.model.Bundle documentBundle, ca.uhn.fhir.rest.api.EncodingEnum encoding) Encodes the CH-EMED-EPR document Bundle to a string, in either XML, JSON, NDJSON or RDF format. The parser will output in pretty-printed form, with newlines and indenting; the resulting string is larger but more easily human- readable.- Parameters:
documentBundle- The document Bundle to serialize.encoding- The desired encoding.- Returns:
- the serialized document.
-
getParser
protected ca.uhn.fhir.parser.IParser getParser(ca.uhn.fhir.rest.api.EncodingEnum encoding, @Nullable EmedDocumentType type) Creates a FHIR parser for the given encoding. If the document type is given, it'll also configure the preferred types for this document type (i.e. to use resources fromorg.projecthusky.fhir.emed.ch.common.resourceandorg.projecthusky.fhir.emed.ch.epr.resourceover HAPI's resources).- Parameters:
encoding- The encoding to use (XML, JSON, NDJSON or RDF).type- The document type ornullto disable the preferred types (not needed for serialization).- Returns:
- the created parser.
-
postHapiParsing
Post-processing for further needed refining/transformations after the initial HAPI parsing.For the moment being, it is used for replacing medication statement|request changed resources within the PML, that are parsed as simple medication statement|request within the PML (but not as changed) due to limitations of the HAPI parser, with resources of the actual
ChEmedEprMedicationStatementChangedPmlandChEmedEprMedicationRequestChangedPmlas needed.- Parameters:
doc-
-