Fix null pointer exception in validator validating language codes

This commit is contained in:
Grahame Grieve 2021-03-29 13:35:51 +11:00
parent dc0542adb9
commit 4e4885dc7d
8 changed files with 84 additions and 25 deletions

View File

@ -0,0 +1,46 @@
package org.hl7.fhir.convertors.loaders;
import java.io.IOException;
import java.io.InputStream;
import org.hl7.fhir.convertors.VersionConvertor_10_50;
import org.hl7.fhir.convertors.VersionConvertor_14_50;
import org.hl7.fhir.convertors.VersionConvertor_30_50;
import org.hl7.fhir.convertors.VersionConvertor_40_50;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
public class XVersionLoader {
public static Resource loadXml(String version, InputStream stream) throws FHIRFormatError, IOException {
if (Utilities.noString(version)) {
return new org.hl7.fhir.r5.formats.XmlParser().parse(stream);
}
switch (VersionUtilities.getMajMin(version)) {
case "1.0": return VersionConvertor_10_50.convertResource(new org.hl7.fhir.dstu2.formats.XmlParser().parse(stream));
case "1.4": return VersionConvertor_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(stream));
case "3.0": return VersionConvertor_30_50.convertResource(new org.hl7.fhir.dstu3.formats.XmlParser().parse(stream), false);
case "4.0": return VersionConvertor_40_50.convertResource(new org.hl7.fhir.r4.formats.XmlParser().parse(stream));
case "5.0": return new org.hl7.fhir.r5.formats.XmlParser().parse(stream);
}
throw new FHIRException("Unknown version "+version+" loading resource");
}
public static Resource loadJson(String version, InputStream stream) throws FHIRFormatError, FHIRException, IOException {
if (Utilities.noString(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().parse(stream);
}
switch (VersionUtilities.getMajMin(version)) {
case "1.0": return VersionConvertor_10_50.convertResource(new org.hl7.fhir.dstu2.formats.JsonParser().parse(stream));
case "1.4": return VersionConvertor_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream));
case "3.0": return VersionConvertor_30_50.convertResource(new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream), false);
case "4.0": return VersionConvertor_40_50.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(stream));
case "5.0": return new org.hl7.fhir.r5.formats.JsonParser().parse(stream);
}
throw new FHIRException("Unknown version "+version+" loading resource");
}
}

View File

@ -786,7 +786,7 @@ public class ProfileUtilities extends TranslatingUtilities {
List<ElementDefinition> children = getChildren(derived, element);
List<ElementChoiceGroup> groups = readChoices(element, children);
for (ElementChoiceGroup group : groups) {
System.out.println(children);
// System.out.println(children);
String mandated = null;
Set<String> names = new HashSet<>();
for (ElementDefinition ed : children) {

View File

@ -587,6 +587,10 @@ public interface IWorkerContext {
this.txLink = txLink;
return this;
}
public boolean hasMessage() {
return message != null;
}
}

View File

@ -170,7 +170,7 @@ public class ValueSetCheckerSimple implements ValueSetChecker {
res = validateCode(code, cs);
} else if (cs == null && valueset.hasExpansion() && inExpansion) {
// we just take the value set as face value then
res = new ValidationResult(IssueSeverity.INFORMATION, null);
res = new ValidationResult(new ConceptDefinitionComponent().setCode(code.getCode()).setDisplay(code.getDisplay()));
} else {
// well, we didn't find a code system - try the expansion?
// disabled waiting for discussion

View File

@ -1059,18 +1059,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
// to validate, we'll validate that the codes actually exist
if (bindingsOk) {
for (Coding nextCoding : cc.getCoding()) {
if (isNotBlank(nextCoding.getCode()) && isNotBlank(nextCoding.getSystem()) && context.supportsSystem(nextCoding.getSystem())) {
ValidationResult vr = checkCodeOnServer(stack, valueset, nextCoding, false);
if (vr.getSeverity() != null) {
if (vr.getSeverity() == IssueSeverity.INFORMATION) {
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
} else if (vr.getSeverity() == IssueSeverity.WARNING) {
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
} else {
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
}
}
}
checkBindings(errors, path, element, stack, valueset, nextCoding);
}
}
timeTracker.tx(t);
@ -1090,6 +1079,21 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return res;
}
public void checkBindings(List<ValidationMessage> errors, String path, Element element, NodeStack stack, ValueSet valueset, Coding nextCoding) {
if (isNotBlank(nextCoding.getCode()) && isNotBlank(nextCoding.getSystem()) && context.supportsSystem(nextCoding.getSystem())) {
ValidationResult vr = checkCodeOnServer(stack, valueset, nextCoding, false);
if (vr.getSeverity() != null/* && vr.hasMessage()*/) {
if (vr.getSeverity() == IssueSeverity.INFORMATION) {
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
} else if (vr.getSeverity() == IssueSeverity.WARNING) {
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
} else {
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
}
}
}
}
private boolean checkTerminologyCodeableConcept(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, ElementDefinition theElementCntext, NodeStack stack, StructureDefinition logical) {
boolean res = true;
@ -2583,7 +2587,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
}
}
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, (allowExamples && (ref.contains("example.org") || ref.contains("acme.com"))) || (we != null || pol == ReferenceValidationPolicy.CHECK_TYPE_IF_EXISTS), I18nConstants.REFERENCE_REF_CANTRESOLVE, ref);
boolean ok = (allowExamples && (ref.contains("example.org") || ref.contains("acme.com"))) || (we != null || pol == ReferenceValidationPolicy.CHECK_TYPE_IF_EXISTS);
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, ok, I18nConstants.REFERENCE_REF_CANTRESOLVE, ref);
}
String ft;

View File

@ -18,7 +18,8 @@ public class SpecialExtensions {
return Utilities.existsInList(url,
"http://hl7.org/fhir/StructureDefinition/elementdefinition-type-must-support",
"http://hl7.org/fhir/StructureDefinition/instance-name",
"http://hl7.org/fhir/StructureDefinition/instance-description"
"http://hl7.org/fhir/StructureDefinition/instance-description",
"http://hl7.org/fhir/StructureDefinition/structuredefinition-rdf-type"
);
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -11,6 +12,7 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.hl7.fhir.convertors.loaders.XVersionLoader;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
@ -171,24 +173,25 @@ public class SnapShotGenerationXTests {
this.output = output;
}
public void load() throws FHIRFormatError, FileNotFoundException, IOException {
public void load(String version) throws FHIRFormatError, FileNotFoundException, IOException {
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", id + "-input.json"))
source = (StructureDefinition) new JsonParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
source = (StructureDefinition) XVersionLoader.loadJson(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
else
source = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
source = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
if (!fail)
expected = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
expected = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
if (!Utilities.noString(include))
included = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
included = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
if (!Utilities.noString(register)) {
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", register + ".xml")) {
included = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
included = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
} else {
included = (StructureDefinition) new JsonParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
included = (StructureDefinition) XVersionLoader.loadJson(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
}
}
}
public boolean isNewSliceProcessing() {
return newSliceProcessing;
}
@ -399,7 +402,7 @@ public class SnapShotGenerationXTests {
while (test != null && test.getNodeName().equals("test")) {
TestDetails t = new TestDetails(test);
context.tests.add(t);
t.load();
t.load(test.getAttribute("load-version"));
objects.add(new Object[]{t.getId(), t, context});
test = XMLUtil.getNextSibling(test);
}

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>5.1.0</hapi_fhir_version>
<validator_test_case_version>1.1.58-SNAPSHOT</validator_test_case_version>
<validator_test_case_version>1.1.58</validator_test_case_version>
<junit_jupiter_version>5.7.1</junit_jupiter_version>
<junit_platform_launcher_version>1.7.1</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M4</maven_surefire_version>