Fix FhirInstanceValidatorR4BTest

This commit is contained in:
dotasek 2023-12-15 15:56:32 -05:00
parent 73eb12778c
commit 974a75336b
1 changed files with 38 additions and 14 deletions

View File

@ -477,6 +477,9 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateDoesntEnforceBestPracticesByDefault() {
Observation input = new Observation();
input.addPerformer(new Reference("Practitioner/124"));
input.setEffective(new DateTimeType("2023-01-01T11:22:33Z"));
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
input.setStatus(Enumerations.ObservationStatus.AMENDED);
input.getCode().addCoding().setSystem("http://loinc.org").setCode("1234").setDisplay("FOO");
@ -493,7 +496,10 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
result = val.validateWithResult(input);
all = logResultsAndReturnAll(result);
assertTrue(result.isSuccessful());
assertThat(all, empty());
assertThat(all, hasSize(1));
assertEquals("Best Practice Recommendation: In general, all observations should have a subject", all.get(0).getMessage());
assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity());
// With BPs enabled
val = ourCtx.newValidator();
@ -504,7 +510,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
result = val.validateWithResult(input);
all = logResultsAndReturnAll(result);
assertFalse(result.isSuccessful());
assertEquals("All observations should have a subject", all.get(0).getMessage());
assertEquals("Best Practice Recommendation: In general, all observations should have a subject", all.get(0).getMessage());
}
@ -976,7 +982,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
ValidationResult output = myFhirValidator.validateWithResult(encoded);
assertEquals(1, output.getMessages().size(), output.toString());
assertEquals("The extension http://hl7.org/fhir/v3/ethnicity is unknown, and not allowed here", output.getMessages().get(0).getMessage());
assertEquals("The extension http://hl7.org/fhir/v3/ethnicity could not be found so is not allowed here", output.getMessages().get(0).getMessage());
assertEquals(ResultSeverityEnum.ERROR, output.getMessages().get(0).getSeverity());
}
@ -1064,7 +1070,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
ValidationResult output = myFhirValidator.validateWithResult(input);
List<SingleValidationMessage> res = logResultsAndReturnNonInformationalOnes(output);
assertEquals(1, res.size(), output.toString());
assertEquals("A code with no system has no defined meaning. A system should be provided", output.getMessages().get(0).getMessage());
assertEquals("A code with no system has no defined meaning, and it cannot be validated. A system should be provided", output.getMessages().get(0).getMessage());
}
/**
@ -1138,11 +1144,19 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
assertThat(errors.toString(), containsString("Observation.device: minimum required = 1, but only found 0"));
}
private Observation createObservationWithDefaultSubjectPerfomerEffective() {
Observation observation = new Observation();
observation.setSubject(new Reference("Patient/123"));
observation.addPerformer(new Reference("Practitioner/124"));
observation.setEffective(new DateTimeType("2023-01-01T11:22:33Z"));
return observation;
}
@Test
public void testValidateResourceContainingProfileDeclarationDoesntResolve() {
addValidConcept("http://loinc.org", "12345");
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
input.getMeta().addProfile("http://foo/structuredefinition/myprofile");
@ -1154,7 +1168,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
assertEquals(1, errors.size());
assertEquals("Profile reference 'http://foo/structuredefinition/myprofile' has not been checked because it is unknown", errors.get(0).getMessage());
assertEquals("Profile reference 'http://foo/structuredefinition/myprofile' has not been checked because it could not be found", errors.get(0).getMessage());
assertEquals(ResultSeverityEnum.ERROR, errors.get(0).getSeverity());
}
@ -1175,7 +1189,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateResourceWithDefaultValueset() {
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
input.setStatus(Enumerations.ObservationStatus.FINAL);
@ -1203,7 +1217,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
ValidationResult output = myFhirValidator.validateWithResult(input);
logResultsAndReturnAll(output);
assertEquals(
"The value provided ('notvalidcode') is not in the value set 'ObservationStatus' (http://hl7.org/fhir/ValueSet/observation-status|4.3.0), and a code is required from this value set (error message = Unknown code 'notvalidcode' for in-memory expansion of ValueSet 'http://hl7.org/fhir/ValueSet/observation-status')",
"The value provided ('notvalidcode') was not found in the value set 'ObservationStatus' (http://hl7.org/fhir/ValueSet/observation-status|4.3.0), and a code is required from this value set (error message = Unknown code 'notvalidcode' for in-memory expansion of ValueSet 'http://hl7.org/fhir/ValueSet/observation-status')",
output.getMessages().get(0).getMessage());
}
@ -1239,7 +1253,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateResourceWithExampleBindingCodeValidationFailing() {
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
myInstanceVal.setValidationSupport(myValidationSupport);
@ -1273,7 +1287,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateResourceWithExampleBindingCodeValidationPassingLoinc() {
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
myInstanceVal.setValidationSupport(myValidationSupport);
@ -1289,7 +1303,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateResourceWithExampleBindingCodeValidationPassingLoincWithExpansion() {
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
ValueSetExpansionComponent expansionComponent = new ValueSetExpansionComponent();
@ -1310,7 +1324,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
@Test
public void testValidateResourceWithExampleBindingCodeValidationPassingNonLoinc() {
Observation input = new Observation();
Observation input = createObservationWithDefaultSubjectPerfomerEffective();
input.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
myInstanceVal.setValidationSupport(myValidationSupport);
@ -1356,7 +1370,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
all = logResultsAndReturnNonInformationalOnes(output);
assertEquals(2, all.size());
assertThat(all.get(0).getMessage(), containsString("The unit 'Heck' is unknown' at position 0 for 'http://unitsofmeasure.org#Heck'"));
assertThat(all.get(1).getMessage(), containsString("The value provided ('Heck') is not in the value set 'Body Temperature Units'"));
assertThat(all.get(1).getMessage(), containsString("The value provided ('Heck') was not found in the value set 'Body Temperature Units'"));
}
@ -1430,6 +1444,10 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
String input = """
{
"resourceType": "Invoice",
"text": {
"status" : "generated",
"div" : "<div xmlns=\\"http://www.w3.org/1999/xhtml\\">Dummy text</div>"
},
"status": "draft",
"date": "2020-01-08",
"totalGross": {
@ -1449,6 +1467,10 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
String input = """
{
"resourceType": "Invoice",
"text": {
"status" : "generated",
"div" : "<div xmlns=\\"http://www.w3.org/1999/xhtml\\">Dummy text</div>"
},
"status": "draft",
"date": "2020-01-08",
"totalGross": {
@ -1459,7 +1481,7 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
ValidationResult output = myFhirValidator.validateWithResult(input);
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
assertEquals(1, errors.size(), errors.toString());
assertThat(errors.get(0).getMessage(), containsString("The value provided ('BLAH') is not in the value set 'CurrencyCode' (http://hl7.org/fhir/ValueSet/currencies|4.3.0), and a code is required from this value set (error message = Unknown code 'BLAH' for in-memory expansion of ValueSet 'http://hl7.org/fhir/ValueSet/currencies')"));
assertThat(errors.get(0).getMessage(), containsString("The value provided ('BLAH') was not found in the value set 'CurrencyCode' (http://hl7.org/fhir/ValueSet/currencies|4.3.0), and a code is required from this value set"));
}
@ -1468,6 +1490,8 @@ public class FhirInstanceValidatorR4BTest extends BaseTest {
public void testValidateReferenceTargetType_Correct() {
AllergyIntolerance allergy = new AllergyIntolerance();
allergy.getText().setDiv(new XhtmlNode().setValue("<div>AA</div>")).setStatus(Narrative.NarrativeStatus.GENERATED);
allergy.getClinicalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical").setCode("active").setDisplay("Active");
allergy.getVerificationStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/allergyintolerance-verification").setCode("confirmed").setDisplay("Confirmed");
allergy.setPatient(new Reference("Patient/123"));