Fix validation issue
This commit is contained in:
parent
fb277a0595
commit
fd2671d28e
|
@ -223,14 +223,32 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
|
|||
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
|
||||
CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
|
||||
if (cs != null) {
|
||||
for (ConceptDefinitionComponent next : cs.getConcept()) {
|
||||
if (next.getCode().equals(theCode)) {
|
||||
return new CodeValidationResult(next);
|
||||
}
|
||||
CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept());
|
||||
|
||||
if (retVal != null) {
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
return new CodeValidationResult(IssueSeverity.INFORMATION, "Unknown code: " + theCodeSystem + " / " + theCode);
|
||||
}
|
||||
|
||||
private CodeValidationResult testIfConceptIsInList(String theCode, List<ConceptDefinitionComponent> conceptList) {
|
||||
CodeValidationResult retVal = null;
|
||||
for (ConceptDefinitionComponent next : conceptList) {
|
||||
if (next.getCode().equals(theCode)) {
|
||||
retVal = new CodeValidationResult(next);
|
||||
break;
|
||||
}
|
||||
|
||||
// recurse
|
||||
retVal = testIfConceptIsInList(theCode, next.getConcept());
|
||||
if (retVal != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import static org.hamcrest.Matchers.stringContainsInOrder;
|
|||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.dstu3.model.CodeableConcept;
|
||||
import org.hl7.fhir.dstu3.model.Coding;
|
||||
import org.hl7.fhir.dstu3.model.Condition;
|
||||
|
@ -35,15 +37,14 @@ public class ResourceValidatorDstu3Test {
|
|||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu3();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorDstu3Test.class);
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure that the elements that appear in all resources (meta, language, extension, etc)
|
||||
* all appear in the correct order
|
||||
* Make sure that the elements that appear in all resources (meta, language, extension, etc) all appear in the correct order
|
||||
*/
|
||||
@Test
|
||||
public void testValidateResourceWithResourceElements() {
|
||||
|
@ -87,9 +88,7 @@ public class ResourceValidatorDstu3Test {
|
|||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
* https://groups.google.com/d/msgid/hapi-fhir/a266083f-6454-4cf0-a431-c6500f052bea%40googlegroups.com?utm_medium=
|
||||
* email&utm_source=footer
|
||||
* See https://groups.google.com/d/msgid/hapi-fhir/a266083f-6454-4cf0-a431-c6500f052bea%40googlegroups.com?utm_medium= email&utm_source=footer
|
||||
*/
|
||||
@Test
|
||||
public void testValidateWithExtensionsXml() {
|
||||
|
@ -140,9 +139,26 @@ public class ResourceValidatorDstu3Test {
|
|||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
* https://groups.google.com/d/msgid/hapi-fhir/a266083f-6454-4cf0-a431-c6500f052bea%40googlegroups.com?utm_medium=
|
||||
* email&utm_source=footer
|
||||
* Per email from Jon Zammit
|
||||
*/
|
||||
@Test
|
||||
public void testValidateQuestionnaire() throws IOException {
|
||||
String input = IOUtils.toString(getClass().getResourceAsStream("/questionnaire_jon_z_20160506.xml"));
|
||||
|
||||
FhirValidator val = ourCtx.newValidator();
|
||||
val.registerValidatorModule(new FhirInstanceValidator());
|
||||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
OperationOutcome operationOutcome = (OperationOutcome) result.toOperationOutcome();
|
||||
String ooencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome);
|
||||
ourLog.info(ooencoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://groups.google.com/d/msgid/hapi-fhir/a266083f-6454-4cf0-a431-c6500f052bea%40googlegroups.com?utm_medium= email&utm_source=footer
|
||||
*/
|
||||
@Test
|
||||
public void testValidateWithExtensionsJson() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -107,6 +107,12 @@
|
|||
Properly handle null arrays when parsing JSON resources. Thanks to Subhro for
|
||||
fixing this and providing a pull request!
|
||||
</action>
|
||||
<action type="fix">
|
||||
STU3 validator failed to validate codes where the
|
||||
code was a child code within the code system that contained it
|
||||
(i.e. not a top level code). Thanks to Jon
|
||||
Zammit for reporting!
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.5" date="2016-04-20">
|
||||
<action type="fix" issue="339">
|
||||
|
|
Loading…
Reference in New Issue