Skip to content

Commit

Permalink
[#181] CH EMED EPR / WIP support for emediplan export
Browse files Browse the repository at this point in the history
  • Loading branch information
dvribeira committed Oct 3, 2024
1 parent 03405a7 commit 45dc2d4
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<artifactId>husky-fhir-emed-ch-epr-narrative</artifactId>
<name>Husky FHIR eMedication Switzerland EPR Narrative</name>

<properties>
<openhtmltopdf-version>1.1.21</openhtmltopdf-version>
</properties>

<dependencies>
<dependency>
<groupId>org.projecthusky.fhir.emed.ch</groupId>
Expand All @@ -37,23 +33,19 @@
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-core</artifactId> <!-- LGPL -->
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-pdfbox</artifactId> <!-- LGPL -->
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-slf4j</artifactId>
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<!-- SVG support plugin. -->
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-svg-support</artifactId>
<version>${openhtmltopdf-version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void addMedicament(final @NonNull EMediplanMedicament medicament) {
getMedicaments().add(Objects.requireNonNull(medicament));
}

@Override
public List<@NonNull EMediplanExtension> getExtensions() {
if (extensions == null) extensions = new ArrayList<>();
return extensions;
Expand All @@ -126,6 +127,7 @@ public EMediplanType resolveType() {
} else return type;
}

@Override
public ValidationResult validate(final @Nullable String basePath) {
final var result = new ValidationResult();

Expand Down Expand Up @@ -246,6 +248,7 @@ public ValidationResult validate(final @Nullable String basePath) {
return result;
}

@Override
public void trim() {
if (patient != null) patient.trim();
if (hcPerson != null) hcPerson.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
import java.util.List;
import java.util.Objects;

/**
* Interface for objects that contain extensions. The extension property itself is to be defined by the implementing
* object, so that the JSON field name can be customized in principle. This interface provides convenience methods for
* extensions with a default implementation.
* @see EMediplanExtension
*/
public interface EMediplanExtendable {
/**
* Gets the list of this object's extensions.
* @return The list of extensions.
*/
List<@NonNull EMediplanExtension> getExtensions();

/**
* Adds an extension to the list of this object's extensions.
* @param extension The extension to be added.
*/
default void addExtension(final @NonNull EMediplanExtension extension) {
getExtensions().add(Objects.requireNonNull(extension));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,44 @@

import java.util.Objects;

/**
* Abstraction of an eMediplan (JSON) object. Declares common methods to all eMediplan objects and provides a default
* implementation for some of them.
*/
public 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.
*/
default void trim() {}

/**
* Validates the eMediplan object, without any further context than its own content, against the eMediplan specs.
* @return The validation result containing all the encountered validation issues, if any.
*/
default ValidationResult validate() {
return validate(null);
}

/**
* Validates the eMediplan object, without any further context than its JSON path and its own content, against the
* eMediplan specs.
*
* @param basePath The JSON path of this object. If {@code 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.
* @return The validation result containing all the encountered validation issues, if any.
*/
ValidationResult validate(final @Nullable String basePath);

/**
* Convenience method to get a validation issue of severity {@link OperationOutcome.IssueSeverity#ERROR} and type
* {@link OperationOutcome.IssueType#REQUIRED} with the specified issue path and message. This issue is to be used
* for eMediplan mandatory fields/objects that are however missing within the object being validated.
*
* @param path The path of the issue. Where the issue was encountered.
* @param message The message describing the issue.
* @return The produced validation issue.
*/
default ValidationIssue getRequiredFieldValidationIssue(final String path, final String message) {
return getValidationIssue(
OperationOutcome.IssueSeverity.ERROR,
Expand All @@ -29,6 +54,14 @@ default ValidationIssue getRequiredFieldValidationIssue(final String path, final
);
}

/**
* Convenience method to produce a validation issue by providing only severity, type, path and message.
* @param severity The severity of the issue.
* @param type The type of issue.
* @param path The path of the issue. Where the issue was encountered.
* @param message The message describing the issue.
* @return The produced validation issue.
*/
default ValidationIssue getValidationIssue(final OperationOutcome.IssueSeverity severity,
final OperationOutcome.IssueType type,
final String path,
Expand All @@ -45,6 +78,16 @@ default ValidationIssue getValidationIssue(final OperationOutcome.IssueSeverity
);
}

/**
* Convenience method to get a validation issue of severity {@link OperationOutcome.IssueSeverity#WARNING} and type
* {@link OperationOutcome.IssueType#INVALID} with the specified issue path and message. This issue is to be
* produced when a field is specified by the eMediplan specification not to be provided and to be ignored if
* encountered (on the specified conditions).
*
* @param path The path of the issue. Where the issue was encountered.
* @param message The message describing the issue.
* @return The produced validation issue.
*/
default ValidationIssue getIgnoredFieldValidationIssue(final String path, final String message) {
return getValidationIssue(
OperationOutcome.IssueSeverity.WARNING,
Expand All @@ -54,10 +97,31 @@ default ValidationIssue getIgnoredFieldValidationIssue(final String path, final
);
}

/**
* Convenience method to get a specific field's validation path, that is, the path to be used to produce a
* {@link ValidationIssue}.
*
* @param basePath The base path of the object being validated and containing the field triggering the validation
* issue.
* @param field The name of the field triggering the validation issue.
* @return The path for the specified field within the specified object as to be used for a validation issue.
*/
default String getFieldValidationPath(final @Nullable String basePath, final String field) {
return (basePath == null || basePath.isBlank()) ? field : basePath + "." + field;
}

/**
* Convenience method to get a specific field's validation path when the field is actually an element of a
* list/array. For instance, if the element failing to pass validation is the value <i>1</i> within the JSON
* {@code {"mylist": [1, 2]}} ; then this method can be called as {@code getFieldValidationPath(null, "mylist", 0)}
* to get a path for this element to be used to produce a validation issue.
*
* @param basePath The base path of the object being validated and containing the field triggering the validation
* issue.
* @param field The name of the field triggering the validation issue.
* @param index The index of the list/array element that failed to pass validation.
* @return The resulting field validation path.
*/
default String getFieldValidationPath(final @Nullable String basePath, final String field, final int index) {
return getFieldValidationPath(basePath, Objects.requireNonNull(field)) + "[" + index + "]";
}
Expand Down
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<camel.version>3.21.4</camel.version>

<zxing.version>3.5.3</zxing.version>
<openhtmltopdf-version>1.1.22</openhtmltopdf-version>
</properties>
<scm>
<connection>scm:git:https://github.com/project-husky/husky.git</connection>
Expand Down Expand Up @@ -641,6 +642,29 @@
</exclusions>
</dependency>

<!-- HTML to PDF conversion -->
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-core</artifactId> <!-- LGPL -->
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-pdfbox</artifactId> <!-- LGPL -->
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-slf4j</artifactId>
<version>${openhtmltopdf-version}</version>
</dependency>
<dependency>
<!-- SVG support plugin. -->
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-svg-support</artifactId>
<version>${openhtmltopdf-version}</version>
</dependency>

<!-- QR code generation -->
<dependency>
<groupId>com.google.zxing</groupId>
Expand Down

0 comments on commit 45dc2d4

Please sign in to comment.