Class ChEmedEprParser

java.lang.Object
org.projecthusky.fhir.emed.ch.epr.service.ChEmedEprParser

@ThreadSafe public class ChEmedEprParser extends Object
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

    Constructors
    Constructor
    Description
    ChEmedEprParser(@Nullable ca.uhn.fhir.context.FhirContext fhirR4Context)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    <T extends ChEmedEprDocument>
    T
    parse(String resource, EmedDocumentType type)
    Parses the given string (JSON or XML) as a CH-EMED-EPR document Bundle.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChEmedEprParser

      public ChEmedEprParser(@Nullable ca.uhn.fhir.context.FhirContext fhirR4Context)
      Constructor.
      Parameters:
      fhirR4Context - The non-null FHIR context (R4).
  • Method Details

    • parse

      public <T extends ChEmedEprDocument> T parse(String resource, EmedDocumentType type)
      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 from org.projecthusky.fhir.emed.ch.common.resource and org.projecthusky.fhir.emed.ch.epr.resource over HAPI's resources).
      Parameters:
      encoding - The encoding to use (XML, JSON, NDJSON or RDF).
      type - The document type or null to disable the preferred types (not needed for serialization).
      Returns:
      the created parser.