java.lang.Object
org.projecthusky.fhir.emed.ch.epr.model.emediplan.EMediplan<E,G,M,I>
Type Parameters:
E - The type of eMediplan extension used by this document.
G - The type of eMediplan patient gender enum used by this document.
M - The type of eMediplan medicament object used by this document.
I - The type of patient identifier object used by this document.
All Implemented Interfaces:
EMediplanExtendable<E>, EMediplanObject
Direct Known Subclasses:
ChMed16AEMediplan, ChMed23AEMediplan

public abstract class EMediplan<E extends EMediplanObject,G extends EMediplanGender,M extends EMediplanMedicament<E>,I extends EMediplanIdentifier> extends Object implements EMediplanExtendable<E>
Base class to model an eMediplan document object, be it of CHMED16A or CHMED23A specs.
  • Field Details

  • Constructor Details

    • EMediplan

      public EMediplan()
  • Method Details

    • getEmediplanVersion

      public abstract String getEmediplanVersion()
    • getChTransmissionFormatPrefix

      public abstract String getChTransmissionFormatPrefix()
    • getPatient

      public abstract EMediplanPatient<E,G,I> getPatient()
    • getMedicaments

      public abstract List<@NonNull M> getMedicaments()
    • getType

      public abstract @Nullable EMediplanType getType()
    • getId

      public abstract @Nullable String getId()
    • getTimestamp

      public abstract Instant getTimestamp()
    • getRemark

      public abstract @Nullable String getRemark()
    • resolveType

      @ExpectsValidResource public abstract EMediplanType resolveType()
      Resolves the eMediplan type, which can be missing for ChMed23A eMediplan objects authored by a patient, because a Medication Plan is assumed (since they are not allowed to author prescriptions).
      Returns:
      The resolved EMediplanType.
    • addMedicament

      public void addMedicament(@NonNull M medicament)
      Convenience method to add a medication to the eMediplan document.
      Parameters:
      medicament - The eMediplan medicament object to be added.
    • validate

      public ValidationResult validate(@Nullable String basePath)
      Description copied from interface: EMediplanObject
      Validates the eMediplan object, without any further context than its JSON path and its own content, against the eMediplan specs.
      Specified by:
      validate in interface EMediplanObject
      Parameters:
      basePath - The JSON path of this object. If null, the object is considered to be root. Any validation issues produced by the validation will use this path as a base for each issue's path.
      Returns:
      The validation result containing all the encountered validation issues, if any.
    • trim

      public void trim()
      Description copied from interface: EMediplanObject
      Trims the eMediplan object, that is, removes any redundant info and sets to null values that match the default assumed value by the specs, to shorten the serialized result.
      Specified by:
      trim in interface EMediplanExtendable<E extends EMediplanObject>
      Specified by:
      trim in interface EMediplanObject
    • toChTransmissionFormat

      @ExpectsValidResource public String toChTransmissionFormat() throws IOException
      Converts the eMediplan format to the ChTransmissionFormat specified by the relevant ChMed specification. This is useful for data transmission as well as used for the QR code to be embedded in the eMediplan paper/PDF format.

      Although ChMed16A supports non-compressed content within the transmission format, this implementation supports only compressed content.

      Returns:
      The ChTransmissionFormat string with the eMediplan object information.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - The eMediplan object could not be serialized to JSON.
      IOException - The eMediplan object could not be serialized and compressed to ChTransmissionFormat.
    • compressJson

      protected static byte[] compressJson(String rawJson) throws IOException
      Compresses the serialized eMediplan (JSON) using GZIP, as specified by CHMED23A and, optionally, CHMED16A.
      Parameters:
      rawJson - The raw JSON to be compressed.
      Returns:
      The GZIP compressed byte array.
      Throws:
      IOException - In case of error compressing the JSON content.
    • uncompressJson

      protected static byte[] uncompressJson(byte[] compressed) throws IOException
      Uncompresses a received serialized eMediplan (JSON) normally conveyed via ChTransmissionFormat, as specified by eMediplan.
      Parameters:
      compressed - The compressed content, as a byte array.
      Returns:
      The uncompressed content, as a byte array.
      Throws:
      IOException - In case of an I/O exception while uncompressing the received content.