Skip to content

Commit

Permalink
#165:fix FHIR validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ohr committed Oct 11, 2017
1 parent 00d919f commit 44f119b
Show file tree
Hide file tree
Showing 12 changed files with 24,761 additions and 5,140 deletions.
4 changes: 4 additions & 0 deletions commons/ihe/fhir/core/pom.xml
Expand Up @@ -27,6 +27,10 @@
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation</artifactId>
</dependency>
<dependency>
<groupId>org.openehealth.ipf.commons</groupId>
<artifactId>ipf-commons-ihe-core</artifactId>
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.instance.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;

Expand Down
@@ -0,0 +1,52 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.instance.model.DocumentReference;
import org.hl7.fhir.instance.model.StructureDefinition;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

/**
*
*/
public class CustomValidationSupportTest {

private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu2Hl7Org();
@Test
public void testFindStructureDefinition() {
CustomValidationSupport customValidationSupport = new CustomValidationSupport();
customValidationSupport.setPrefix("profiles/MHD-");
StructureDefinition definition = customValidationSupport.fetchResource(FHIR_CONTEXT, StructureDefinition.class,
CustomValidationSupport.HTTP_HL7_ORG_FHIR_STRUCTURE_DEFINITION + "DocumentReference");
assertNotNull(definition);
assertEquals(DocumentReference.class.getSimpleName(), definition.getConstrainedType());
}

@Test
public void testFindUnknownStructureDefinition() {
CustomValidationSupport customValidationSupport = new CustomValidationSupport();
customValidationSupport.setPrefix("profiles/Gablorg-");
StructureDefinition definition = customValidationSupport.fetchResource(FHIR_CONTEXT, StructureDefinition.class,
CustomValidationSupport.HTTP_HL7_ORG_FHIR_STRUCTURE_DEFINITION + "DocumentReference");
assertNull(definition);
}
}
Expand Up @@ -17,7 +17,15 @@
package org.openehealth.ipf.commons.ihe.fhir.iti65;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport;
import org.hl7.fhir.instance.model.*;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.openehealth.ipf.commons.ihe.fhir.CustomValidationSupport;
import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionValidator;
import org.openehealth.ipf.commons.ihe.fhir.FhirUtils;
import org.openehealth.ipf.commons.ihe.xds.core.responses.ErrorCode;
Expand All @@ -33,15 +41,15 @@
*/
public class Iti65Validator extends FhirTransactionValidator.Support {

// private static final IValidationSupport VALIDATION_SUPPORT = new CustomValidationSupport("profiles/MHD");
private static final IValidationSupport VALIDATION_SUPPORT = new CustomValidationSupport("profiles/MHD");

// Prepare the required validator instances so that the structure definitions are not reloaded each time
// private static Map<Class<?>, FhirInstanceValidator> VALIDATORS = new HashMap<>();
private static Map<Class<?>, FhirInstanceValidator> VALIDATORS = new HashMap<>();

static {
// VALIDATORS.put(DocumentManifest.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
// VALIDATORS.put(DocumentReference.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
// VALIDATORS.put(List_.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
VALIDATORS.put(DocumentManifest.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
VALIDATORS.put(DocumentReference.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
VALIDATORS.put(List_.class, new FhirInstanceValidator(VALIDATION_SUPPORT));
}

@Override
Expand All @@ -50,11 +58,10 @@ public void validateRequest(FhirContext context, Object payload, Map<String, Obj
validateTransactionBundle(transactionBundle);
validateBundleConsistency(transactionBundle);

/*
for (Bundle.BundleEntryComponent entry : transactionBundle.getEntry()) {
Class<? extends IBaseResource> clazz = entry.getResource().getClass();
if (VALIDATORS.containsKey(clazz)) {
ca.uhn.fhir.validation.FhirValidator validator = context.newValidator();
FhirValidator validator = context.newValidator();
validator.registerValidatorModule(VALIDATORS.get(clazz));
ValidationResult validationResult = validator.validateWithResult(entry.getResource());
if (!validationResult.isSuccessful()) {
Expand All @@ -63,7 +70,6 @@ public void validateRequest(FhirContext context, Object payload, Map<String, Obj
}
}
}
*/
}


Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;

import java.io.InputStream;
Expand Down
@@ -0,0 +1,52 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.dstu3.model.DocumentReference;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

/**
*
*/
public class CustomValidationSupportTest {

private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu3();
@Test
public void testFindStructureDefinition() {
CustomValidationSupport customValidationSupport = new CustomValidationSupport();
customValidationSupport.setPrefix("profiles/MHD-");
StructureDefinition definition = customValidationSupport.fetchResource(FHIR_CONTEXT, StructureDefinition.class,
CustomValidationSupport.HTTP_HL7_ORG_FHIR_STRUCTURE_DEFINITION + "DocumentReference");
assertNotNull(definition);
assertEquals(DocumentReference.class.getSimpleName(), definition.getType());
}

@Test
public void testFindUnknownStructureDefinition() {
CustomValidationSupport customValidationSupport = new CustomValidationSupport();
customValidationSupport.setPrefix("profiles/Gablorg-");
StructureDefinition definition = customValidationSupport.fetchResource(FHIR_CONTEXT, StructureDefinition.class,
CustomValidationSupport.HTTP_HL7_ORG_FHIR_STRUCTURE_DEFINITION + "DocumentReference");
assertNull(definition);
}
}

0 comments on commit 44f119b

Please sign in to comment.