Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.hl7.fhir.common.hapi.validation.support.*;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.projecthusky.fhir.emed.ch.epr.resource.ChEmedEprDocument;
import org.projecthusky.fhir.emed.ch.epr.validator.logicvalidator.LogicValidator;

Expand Down Expand Up @@ -90,8 +89,7 @@ public ChEmedEprHapiValidator(final FhirContext context, final @Nullable String

@Override
public ValidationResult validateDocumentBundle(final InputStream documentStream,
final ChEmedEprDocument document,
final Manager.FhirFormat streamFormat)
final ChEmedEprDocument document)
throws IOException {
final var validationOptions = new ValidationOptions();
validationOptions.addProfile(document.getEmedType().getProfileEpr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.projecthusky.fhir.emed.ch.common.enums.EmedDocumentType;
import org.projecthusky.fhir.emed.ch.epr.resource.ChEmedEprDocument;

Expand Down Expand Up @@ -39,14 +37,12 @@ public interface ChEmedEprValidator {
*
* @param documentStream The document Bundle to validate as a stream.
* @param document The parsed CH EMED EPR document, for the logic validator.
* @param streamFormat The FHIR format of the document stream content.
* @return the validation result.
* @implNote We need the parsed document for the logical validator and the serialized document for the instance
* validator, because HAPI's parser messes with resource IDs.
*/
ValidationResult validateDocumentBundle(final InputStream documentStream,
final ChEmedEprDocument document,
final Manager.FhirFormat streamFormat) throws EOperationOutcome, IOException;
final ChEmedEprDocument document) throws IOException;

/**
* Validates a CH-EMED-EPR document Bundle. No logic validation is performed on the content.
Expand All @@ -57,7 +53,7 @@ ValidationResult validateDocumentBundle(final InputStream documentStream,
*/
ValidationResult validateDocumentBundle(final Bundle bundle,
final String profile
) throws EOperationOutcome, IOException;
) throws IOException;

/**
* Maps an {@link OperationOutcome} issue to Husky's own model of a validation issue.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.projecthusky.fhir.emed.ch.epr.validator;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.junit.jupiter.api.Test;
import org.projecthusky.fhir.emed.ch.common.enums.EmedDocumentType;
import org.projecthusky.fhir.emed.ch.epr.service.ChEmedEprParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URISyntaxException;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -24,19 +21,19 @@ class ChEmedEprValidatorTest {
private static final Logger log = LoggerFactory.getLogger(ChEmedEprValidatorTest.class);

@Test
void validateDocumentBundleWithHapi() throws IOException, URISyntaxException, EOperationOutcome {
void validateDocumentBundleWithHapi() throws IOException {
final var ctx = FhirContext.forR4Cached();
final var validator = new ChEmedEprHapiValidator(ctx);
performValidate(ctx, validator);
}

private void performValidate(final FhirContext ctx, final ChEmedEprValidator validator) throws IOException, EOperationOutcome {
private void performValidate(final FhirContext ctx, final ChEmedEprValidator validator) throws IOException {
final var parser = new ChEmedEprParser(ctx);

final var xml = new String(getClass().getResourceAsStream("/examples/ch-emed/Bundle-1-1-MedicationTreatmentPlan.xml").readAllBytes());
final var mtpDocument = parser.parse(xml, EmedDocumentType.MTP);
ValidationResult results = validator.validateDocumentBundle(getClass().getResourceAsStream(
"/examples/ch-emed/Bundle-1-1-MedicationTreatmentPlan.xml"), mtpDocument, Manager.FhirFormat.XML);
"/examples/ch-emed/Bundle-1-1-MedicationTreatmentPlan.xml"), mtpDocument);

for (final var message : results.getIssues()) {
log.info(String.format("[%s][%s] %s", message.getSeverity().name(), message.getType().name(),
Expand All @@ -46,8 +43,7 @@ private void performValidate(final FhirContext ctx, final ChEmedEprValidator val
assertTrue(results.isSuccessful());
final var preDocument = parser.parse(xml, EmedDocumentType.PRE);
results = validator.validateDocumentBundle(getClass().getResourceAsStream("/examples/ch-emed/Bundle-1-1-MedicationTreatmentPlan.xml"),
preDocument,
Manager.FhirFormat.XML);
preDocument);
assertFalse(results.isSuccessful());
}

Expand All @@ -66,7 +62,7 @@ void validatePreDocumentBundleWithHapi() throws IOException {
final var xml = new String(getClass().getResourceAsStream("/examples/ch-emed-epr/Bundle-DocumentPreParacetamolAxapharmCARAPMP004.xml").readAllBytes());
final var doc = parser.parse(xml, EmedDocumentType.PRE);
ValidationResult results = validator.validateDocumentBundle(getClass().getResourceAsStream(
"/examples/ch-emed-epr/Bundle-DocumentPreParacetamolAxapharmCARAPMP004.xml"), doc, Manager.FhirFormat.XML);
"/examples/ch-emed-epr/Bundle-DocumentPreParacetamolAxapharmCARAPMP004.xml"), doc);

for (final var message : results.getIssues()) {
log.info(String.format("[%s][%s] %s", message.getSeverity().name(), message.getType().name(),
Expand All @@ -85,7 +81,7 @@ void validateDisDocumentBundleWithHapi() throws IOException {
final var xml = new String(getClass().getResourceAsStream("/examples/ch-emed/Bundle-1-2-MedicationDispense.xml").readAllBytes());
final var doc = parser.parse(xml, EmedDocumentType.DIS);
ValidationResult results = validator.validateDocumentBundle(getClass().getResourceAsStream(
"/examples/ch-emed/Bundle-1-2-MedicationDispense.xml"), doc, Manager.FhirFormat.XML);
"/examples/ch-emed/Bundle-1-2-MedicationDispense.xml"), doc);

for (final var message : results.getIssues()) {
log.info(String.format("[%s][%s] %s", message.getSeverity().name(), message.getType().name(),
Expand Down
Loading
Loading