FIx validation for resources using v2 tables
This commit is contained in:
parent
79047ef6ab
commit
1cc6a05273
|
@ -11,7 +11,14 @@ a browser.
|
|||
<!--*/-->
|
||||
|
||||
<div>
|
||||
<div class="hapiHeaderText" th:if="${not resource.nameElement.empty}" th:narrative="${resource.name}"></div>
|
||||
<th:block th:switch="${fhirVersion}">
|
||||
<th:block th:case="'DSTU1'">
|
||||
<div class="hapiHeaderText" th:if="${not resource.nameElement.empty}" th:narrative="${resource.name}"></div>
|
||||
</th:block>
|
||||
<th:block th:case="*">
|
||||
<div class="hapiHeaderText" th:if="${not resource.code.empty}" th:narrative="${resource.code}"></div>
|
||||
</th:block>
|
||||
</th:block>
|
||||
</div>
|
||||
|
||||
<!--/*-->
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<context:annotation-config />
|
||||
|
||||
<websocket:handlers>
|
||||
<websocket:mapping path="/baseDstu2/websocket" handler="mySubscriptionWebsocketHandler" />
|
||||
<websocket:mapping path="/websocket/dstu2" handler="mySubscriptionWebsocketHandler" />
|
||||
</websocket:handlers>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -183,7 +183,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
SimpleEchoSocket socket = new SimpleEchoSocket(subsId);
|
||||
try {
|
||||
client.start();
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/baseDstu2/websocket");
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/websocket/dstu2");
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
client.connect(socket, echoUri, request);
|
||||
ourLog.info("Connecting to : {}", echoUri);
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package ca.uhn.fhirtest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.derby.drda.NetworkServerControl;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
@ -22,7 +26,30 @@ public class DerbyNetworkServer implements InitializingBean, DisposableBean {
|
|||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
server = new NetworkServerControl();
|
||||
server.start (null);
|
||||
Writer w = new Writer() {
|
||||
|
||||
@Override
|
||||
public void write(char[] theCbuf, int theOff, int theLen) throws IOException {
|
||||
ourLog.info("[DERBY] " + new String(theCbuf, theOff, theLen));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// nothing
|
||||
}};
|
||||
server.start (new PrintWriter(w));
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DerbyNetworkServer s = new DerbyNetworkServer();
|
||||
s.afterPropertiesSet();
|
||||
s.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
@ -35,7 +36,7 @@ public class TestRestfulServer extends RestfulServer {
|
|||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestRestfulServer.class);
|
||||
|
||||
private ClassPathXmlApplicationContext myAppCtx;
|
||||
private ApplicationContext myAppCtx;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
@ -44,6 +45,7 @@ public class TestRestfulServer extends RestfulServer {
|
|||
|
||||
// Get the spring context from the web container (it's declared in web.xml)
|
||||
WebApplicationContext parentAppCtx = ContextLoaderListener.getCurrentWebApplicationContext();
|
||||
myAppCtx = (parentAppCtx);
|
||||
|
||||
// These two parmeters are also declared in web.xml
|
||||
String implDesc = getInitParameter("ImplementationDescription");
|
||||
|
@ -64,9 +66,6 @@ public class TestRestfulServer extends RestfulServer {
|
|||
String baseUrlProperty;
|
||||
switch (fhirVersionParam.trim().toUpperCase()) {
|
||||
case "DSTU1": {
|
||||
myAppCtx = new ClassPathXmlApplicationContext(new String[] {
|
||||
"hapi-fhir-server-database-config-dstu1.xml",
|
||||
"hapi-fhir-server-resourceproviders-dstu1.xml"}, parentAppCtx);
|
||||
setFhirContext(FhirContext.forDstu1());
|
||||
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
|
||||
systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
|
||||
|
@ -79,11 +78,6 @@ public class TestRestfulServer extends RestfulServer {
|
|||
break;
|
||||
}
|
||||
case "DSTU2": {
|
||||
myAppCtx = new ClassPathXmlApplicationContext(new String[] {
|
||||
"hapi-fhir-server-database-config-dstu2.xml",
|
||||
"hapi-fhir-server-resourceproviders-dstu2.xml",
|
||||
"fhir-spring-subscription-config-dstu2.xml"
|
||||
}, parentAppCtx);
|
||||
setFhirContext(FhirContext.forDstu2());
|
||||
beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class);
|
||||
systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
/WEB-INF/hapi-fhir-server-config.xml
|
||||
/WEB-INF/hapi-fhir-tester-application-context.xml
|
||||
/WEB-INF/hapi-fhir-tester-config.xml
|
||||
classpath:/hapi-fhir-server-database-config-dstu1.xml
|
||||
classpath:/hapi-fhir-server-database-config-dstu2.xml
|
||||
classpath:hapi-fhir-server-resourceproviders-dstu1.xml
|
||||
classpath:hapi-fhir-server-resourceproviders-dstu2.xml
|
||||
classpath:fhir-spring-subscription-config-dstu2.xml
|
||||
</param-value>
|
||||
</context-param>
|
||||
|
||||
|
@ -25,6 +30,7 @@
|
|||
<param-value>
|
||||
/WEB-INF/hapi-fhir-tester-application-context.xml
|
||||
/WEB-INF/hapi-fhir-tester-config.xml
|
||||
classpath:fhir-spring-subscription-config-dstu2.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ca.uhn.fhir.narrative;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -53,7 +54,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
Patient value = new Patient();
|
||||
|
||||
value.addIdentifier().setSystem("urn:names").setValue("123456");
|
||||
value.addName().addFamily("blow").addGiven("joe").addGiven((String)null).addGiven("john");
|
||||
value.addName().addFamily("blow").addGiven("joe").addGiven((String) null).addGiven("john");
|
||||
value.getAddressFirstRep().addLine("123 Fake Street").addLine("Unit 1");
|
||||
value.getAddressFirstRep().setCity("Toronto").setState("ON").setCountry("Canada");
|
||||
|
||||
|
@ -67,12 +68,12 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
|
||||
String title = myGen.generateTitle(value);
|
||||
assertEquals("joe john BLOW (123456)", title);
|
||||
// ourLog.info(title);
|
||||
// ourLog.info(title);
|
||||
|
||||
value.getIdentifierFirstRep().setValue("FOO MRN 123");
|
||||
title = myGen.generateTitle(value);
|
||||
assertEquals("joe john BLOW (FOO MRN 123)", title);
|
||||
// ourLog.info(title);
|
||||
// ourLog.info(title);
|
||||
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
public void testGenerateEncounter() throws DataFormatException {
|
||||
Encounter enc = new Encounter();
|
||||
|
||||
enc.addIdentifier().setSystem("urn:visits").setValue( "1234567");
|
||||
enc.addIdentifier().setSystem("urn:visits").setValue("1234567");
|
||||
enc.setClassElement(EncounterClassEnum.AMBULATORY);
|
||||
enc.setPeriod(new PeriodDt().setStart(new DateTimeDt("2001-01-02T11:11:00")));
|
||||
enc.setType(ca.uhn.fhir.model.dstu2.valueset.EncounterTypeEnum.ANNUAL_DIABETES_MELLITUS_SCREENING);
|
||||
|
@ -92,7 +93,6 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateDiagnosticReport() throws DataFormatException {
|
||||
DiagnosticReport value = new DiagnosticReport();
|
||||
|
@ -127,9 +127,9 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
|
||||
OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, parse);
|
||||
|
||||
// String output = gen.generateTitle(oo);
|
||||
// ourLog.info(output);
|
||||
// assertEquals("Operation Outcome (2 issues)", output);
|
||||
// String output = gen.generateTitle(oo);
|
||||
// ourLog.info(output);
|
||||
// assertEquals("Operation Outcome (2 issues)", output);
|
||||
|
||||
NarrativeDt narrative = new NarrativeDt();
|
||||
myGen.generateNarrative(null, oo, narrative);
|
||||
|
@ -137,11 +137,11 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
|
||||
ourLog.info(output);
|
||||
|
||||
// oo = new OperationOutcome();
|
||||
// oo.addIssue().setSeverity(IssueSeverityEnum.FATAL).setDetails("AA");
|
||||
// output = gen.generateTitle(oo);
|
||||
// ourLog.info(output);
|
||||
// assertEquals("Operation Outcome (fatal)", output);
|
||||
// oo = new OperationOutcome();
|
||||
// oo.addIssue().setSeverity(IssueSeverityEnum.FATAL).setDetails("AA");
|
||||
// output = gen.generateTitle(oo);
|
||||
// ourLog.info(output);
|
||||
// assertEquals("Operation Outcome (fatal)", output);
|
||||
|
||||
}
|
||||
|
||||
|
@ -193,27 +193,43 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 {
|
|||
assertThat(output, StringContains.containsString("<div class=\"hapiHeaderText\"> Some & Diagnostic Report </div>"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateMedicationPrescription(){
|
||||
public void testGenerateMedicationPrescription() {
|
||||
MedicationOrder mp = new MedicationOrder();
|
||||
mp.setId("12345");
|
||||
Medication med = new Medication();
|
||||
med.getCode().setText("ciproflaxin");
|
||||
ResourceReferenceDt medRef = new ResourceReferenceDt(med);
|
||||
mp.setMedication(medRef );
|
||||
mp.setMedication(medRef);
|
||||
mp.setStatus(MedicationOrderStatusEnum.ACTIVE);
|
||||
mp.setDateWritten(new DateTimeDt("2014-09-01"));
|
||||
|
||||
|
||||
NarrativeDt narrative = new NarrativeDt();
|
||||
myGen.generateNarrative(mp, narrative);
|
||||
|
||||
assertTrue("Expected medication name of ciprofloaxin within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ciprofloaxin")>-1);
|
||||
assertTrue("Expected string status of ACTIVE within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ACTIVE")>-1);
|
||||
|
||||
|
||||
assertTrue("Expected medication name of ciprofloaxin within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ciprofloaxin") > -1);
|
||||
assertTrue("Expected string status of ACTIVE within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ACTIVE") > -1);
|
||||
|
||||
String title = myGen.generateTitle(mp);
|
||||
assertEquals("ciprofloaxin", title);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateMedication() {
|
||||
Medication med = new Medication();
|
||||
med.getCode().setText("ciproflaxin");
|
||||
|
||||
NarrativeDt narrative = new NarrativeDt();
|
||||
myGen.generateNarrative(med, narrative);
|
||||
|
||||
String string = narrative.getDiv().toString();
|
||||
assertThat(string, containsString("ciproflaxin"));
|
||||
|
||||
String title = myGen.generateTitle(med);
|
||||
assertEquals("ciproflaxin", title);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.uhn.fhir.validation;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -20,67 +22,102 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
|||
|
||||
public class DefaultProfileValidationSupport implements IValidationSupport {
|
||||
|
||||
private Map<String, ValueSet> myDefaultValueSets;
|
||||
|
||||
@Override
|
||||
public boolean isCodeSystemSupported(String theSystem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {
|
||||
if (theUri.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
|
||||
return (T) FhirInstanceValidator.loadProfileOrReturnNull(null, FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext), theUri.substring("http://hl7.org/fhir/StructureDefinition/".length()));
|
||||
}
|
||||
if (theUri.startsWith("http://hl7.org/fhir/ValueSet/")) {
|
||||
Map<String, ValueSet> defaultValueSets = myDefaultValueSets;
|
||||
if (defaultValueSets == null) {
|
||||
InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/valuesets.xml");
|
||||
if (valuesetText == null) {
|
||||
return null;
|
||||
}
|
||||
InputStreamReader reader;
|
||||
try {
|
||||
reader = new InputStreamReader(valuesetText, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Shouldn't happen!
|
||||
throw new InternalErrorException("UTF-8 encoding not supported on this platform", e);
|
||||
}
|
||||
|
||||
defaultValueSets = new HashMap<String, ValueSet>();
|
||||
|
||||
FhirContext ctx = FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext);
|
||||
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, reader);
|
||||
for (BundleEntryComponent next : bundle.getEntry()) {
|
||||
IdType nextId = new IdType(next.getFullUrl());
|
||||
if (nextId.isEmpty() || !nextId.getValue().startsWith("http://hl7.org/fhir/ValueSet/")) {
|
||||
continue;
|
||||
}
|
||||
defaultValueSets.put(nextId.toVersionless().getValue(), (ValueSet) next.getResource());
|
||||
}
|
||||
|
||||
myDefaultValueSets = defaultValueSets;
|
||||
}
|
||||
|
||||
return (T) defaultValueSets.get(theUri);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private Map<String, ValueSet> myDefaultValueSets;
|
||||
private Map<String, ValueSet> myCodeSystems;
|
||||
|
||||
@Override
|
||||
public CodeValidationResult validateCode(String theCodeSystem, String theCode, String theDisplay) {
|
||||
public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {
|
||||
if (theUri.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
|
||||
return (T) FhirInstanceValidator.loadProfileOrReturnNull(null, FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext), theUri.substring("http://hl7.org/fhir/StructureDefinition/".length()));
|
||||
}
|
||||
if (theUri.startsWith("http://hl7.org/fhir/ValueSet/")) {
|
||||
Map<String, ValueSet> defaultValueSets = myDefaultValueSets;
|
||||
if (defaultValueSets == null) {
|
||||
InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream("/org/hl7/fhir/instance/model/valueset/valuesets.xml");
|
||||
if (valuesetText == null) {
|
||||
return null;
|
||||
}
|
||||
InputStreamReader reader;
|
||||
try {
|
||||
reader = new InputStreamReader(valuesetText, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Shouldn't happen!
|
||||
throw new InternalErrorException("UTF-8 encoding not supported on this platform", e);
|
||||
}
|
||||
|
||||
defaultValueSets = new HashMap<String, ValueSet>();
|
||||
|
||||
FhirContext ctx = FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext);
|
||||
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, reader);
|
||||
for (BundleEntryComponent next : bundle.getEntry()) {
|
||||
IdType nextId = new IdType(next.getFullUrl());
|
||||
if (nextId.isEmpty() || !nextId.getValue().startsWith("http://hl7.org/fhir/ValueSet/")) {
|
||||
continue;
|
||||
}
|
||||
defaultValueSets.put(nextId.toVersionless().getValue(), (ValueSet) next.getResource());
|
||||
}
|
||||
|
||||
myDefaultValueSets = defaultValueSets;
|
||||
}
|
||||
|
||||
return (T) defaultValueSets.get(theUri);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
|
||||
return new CodeValidationResult(IssueSeverity.INFORMATION, "Unknown code: " + theCodeSystem + " / " + theCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueSet fetchCodeSystem(String theSystem) {
|
||||
return null;
|
||||
public ValueSet fetchCodeSystem(FhirContext theContext, String theSystem) {
|
||||
Map<String, ValueSet> codeSystems = myCodeSystems;
|
||||
if (codeSystems == null) {
|
||||
codeSystems = new HashMap<String, ValueSet>();
|
||||
|
||||
loadCodeSystems(theContext, codeSystems, "/org/hl7/fhir/instance/model/valueset/valuesets.xml");
|
||||
loadCodeSystems(theContext, codeSystems, "/org/hl7/fhir/instance/model/valueset/v2-tables.xml");
|
||||
loadCodeSystems(theContext, codeSystems, "/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml");
|
||||
|
||||
myCodeSystems = codeSystems;
|
||||
}
|
||||
|
||||
return codeSystems.get(theSystem);
|
||||
}
|
||||
|
||||
private void loadCodeSystems(FhirContext theContext, Map<String, ValueSet> codeSystems, String file) {
|
||||
InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(file);
|
||||
if (valuesetText != null) {
|
||||
InputStreamReader reader;
|
||||
try {
|
||||
reader = new InputStreamReader(valuesetText, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Shouldn't happen!
|
||||
throw new InternalErrorException("UTF-8 encoding not supported on this platform", e);
|
||||
}
|
||||
|
||||
FhirContext ctx = FhirInstanceValidator.getHl7OrgDstu2Ctx(theContext);
|
||||
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, reader);
|
||||
for (BundleEntryComponent next : bundle.getEntry()) {
|
||||
ValueSet nextValueSet = (ValueSet) next.getResource();
|
||||
String system = nextValueSet.getCodeSystem().getSystem();
|
||||
if (isNotBlank(system)) {
|
||||
codeSystems.put(system, nextValueSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueSetExpansionComponent expandValueSet(ConceptSetComponent theInclude) {
|
||||
public ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
|
||||
@Override
|
||||
public ValueSetExpansionComponent expandVS(ConceptSetComponent theInc) {
|
||||
return myValidationSupport.expandValueSet(theInc);
|
||||
return myValidationSupport.expandValueSet(myCtx, theInc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -282,7 +282,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
if (myValidationSupport == null) {
|
||||
return null;
|
||||
} else {
|
||||
return myValidationSupport.fetchCodeSystem(theSystem);
|
||||
return myValidationSupport.fetchCodeSystem(myCtx, theSystem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,13 +335,13 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
if (myValidationSupport == null) {
|
||||
return false;
|
||||
} else {
|
||||
return myValidationSupport.isCodeSystemSupported(theSystem);
|
||||
return myValidationSupport.isCodeSystemSupported(myCtx, theSystem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validateCode(String theSystem, String theCode, String theDisplay) {
|
||||
CodeValidationResult result = myValidationSupport.validateCode(theSystem, theCode, theDisplay);
|
||||
CodeValidationResult result = myValidationSupport.validateCode(myCtx, theSystem, theCode, theDisplay);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface IValidationSupport {
|
|||
* The portion to include
|
||||
* @return The expansion
|
||||
*/
|
||||
ValueSetExpansionComponent expandValueSet(ConceptSetComponent theInclude);
|
||||
ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude);
|
||||
|
||||
/**
|
||||
* Fetch a code system by ID
|
||||
|
@ -27,7 +27,7 @@ public interface IValidationSupport {
|
|||
* The code system
|
||||
* @return The valueset (must not be null, but can be an empty ValueSet)
|
||||
*/
|
||||
ValueSet fetchCodeSystem(String theSystem);
|
||||
ValueSet fetchCodeSystem(FhirContext theContext, String theSystem);
|
||||
|
||||
/**
|
||||
* Loads a resource needed by the validation (a StructureDefinition, or a
|
||||
|
@ -53,7 +53,7 @@ public interface IValidationSupport {
|
|||
* @return Returns <code>true</code> if codes in the given code system can be
|
||||
* validated
|
||||
*/
|
||||
boolean isCodeSystemSupported(String theSystem);
|
||||
boolean isCodeSystemSupported(FhirContext theContext, String theSystem);
|
||||
|
||||
/**
|
||||
* Validates that the given code exists and if possible returns a display
|
||||
|
@ -68,7 +68,7 @@ public interface IValidationSupport {
|
|||
* The display name, if it should also be validated
|
||||
* @return Returns a validation result object
|
||||
*/
|
||||
CodeValidationResult validateCode(String theCodeSystem, String theCode, String theDisplay);
|
||||
CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay);
|
||||
|
||||
public class CodeValidationResult {
|
||||
private ConceptDefinitionComponent definition;
|
||||
|
|
|
@ -24,19 +24,19 @@ public class ValidationSupportChain implements IValidationSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ValueSetExpansionComponent expandValueSet(ConceptSetComponent theInclude) {
|
||||
public ValueSetExpansionComponent expandValueSet(FhirContext theCtx, ConceptSetComponent theInclude) {
|
||||
for (IValidationSupport next : myChain) {
|
||||
if (next.isCodeSystemSupported(theInclude.getSystem())) {
|
||||
return next.expandValueSet(theInclude);
|
||||
if (next.isCodeSystemSupported(theCtx, theInclude.getSystem())) {
|
||||
return next.expandValueSet(theCtx, theInclude);
|
||||
}
|
||||
}
|
||||
return myChain.get(0).expandValueSet(theInclude);
|
||||
return myChain.get(0).expandValueSet(theCtx, theInclude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueSet fetchCodeSystem(String theSystem) {
|
||||
public ValueSet fetchCodeSystem(FhirContext theCtx, String theSystem) {
|
||||
for (IValidationSupport next : myChain) {
|
||||
ValueSet retVal = next.fetchCodeSystem(theSystem);
|
||||
ValueSet retVal = next.fetchCodeSystem(theCtx, theSystem);
|
||||
if (retVal != null) {
|
||||
return retVal;
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ public class ValidationSupportChain implements IValidationSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCodeSystemSupported(String theSystem) {
|
||||
public boolean isCodeSystemSupported(FhirContext theCtx, String theSystem) {
|
||||
for (IValidationSupport next : myChain) {
|
||||
if (next.isCodeSystemSupported(theSystem)) {
|
||||
if (next.isCodeSystemSupported(theCtx, theSystem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +66,13 @@ public class ValidationSupportChain implements IValidationSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CodeValidationResult validateCode(String theCodeSystem, String theCode, String theDisplay) {
|
||||
public CodeValidationResult validateCode(FhirContext theCtx, String theCodeSystem, String theCode, String theDisplay) {
|
||||
for (IValidationSupport next : myChain) {
|
||||
if (next.isCodeSystemSupported(theCodeSystem)) {
|
||||
return next.validateCode(theCodeSystem, theCode, theDisplay);
|
||||
if (next.isCodeSystemSupported(theCtx, theCodeSystem)) {
|
||||
return next.validateCode(theCtx, theCodeSystem, theCode, theDisplay);
|
||||
}
|
||||
}
|
||||
return myChain.get(0).validateCode(theCodeSystem, theCode, theDisplay);
|
||||
return myChain.get(0).validateCode(theCtx, theCodeSystem, theCode, theDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.hl7.fhir.instance.model.CodeType;
|
||||
import org.hl7.fhir.instance.model.Observation;
|
||||
import org.hl7.fhir.instance.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.instance.model.Patient;
|
||||
import org.hl7.fhir.instance.model.StringType;
|
||||
import org.hl7.fhir.instance.model.ValueSet;
|
||||
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
|
||||
|
@ -61,19 +62,19 @@ public class FhirInstanceValidatorTest {
|
|||
myValidConcepts = new ArrayList<String>();
|
||||
|
||||
myMockSupport = mock(IValidationSupport.class);
|
||||
when(myMockSupport.expandValueSet(any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() {
|
||||
when(myMockSupport.expandValueSet(any(FhirContext.class), any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() {
|
||||
@Override
|
||||
public ValueSetExpansionComponent answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
ConceptSetComponent arg = (ConceptSetComponent)theInvocation.getArguments()[0];
|
||||
ValueSetExpansionComponent retVal = mySupportedCodeSystemsForExpansion.get(arg.getSystem());
|
||||
if (retVal == null) {
|
||||
retVal = myDefaultValidationSupport.expandValueSet(arg);
|
||||
retVal = myDefaultValidationSupport.expandValueSet(any(FhirContext.class), arg);
|
||||
}
|
||||
ourLog.info("expandValueSet({}) : {}", new Object[] { theInvocation.getArguments()[0], retVal });
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
when(myMockSupport.isCodeSystemSupported(any(String.class))).thenAnswer(new Answer<Boolean>() {
|
||||
when(myMockSupport.isCodeSystemSupported(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<Boolean>() {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
boolean retVal = mySupportedCodeSystemsForExpansion.containsKey(theInvocation.getArguments()[0]);
|
||||
|
@ -93,27 +94,28 @@ public class FhirInstanceValidatorTest {
|
|||
return retVal;
|
||||
}
|
||||
});
|
||||
when(myMockSupport.validateCode(any(String.class), any(String.class), any(String.class)))
|
||||
when(myMockSupport.validateCode(any(FhirContext.class), any(String.class), any(String.class), any(String.class)))
|
||||
.thenAnswer(new Answer<CodeValidationResult>() {
|
||||
@Override
|
||||
public CodeValidationResult answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
String system = (String) theInvocation.getArguments()[0];
|
||||
String code = (String) theInvocation.getArguments()[1];
|
||||
FhirContext ctx = (FhirContext) theInvocation.getArguments()[0];
|
||||
String system = (String) theInvocation.getArguments()[1];
|
||||
String code = (String) theInvocation.getArguments()[2];
|
||||
CodeValidationResult retVal;
|
||||
if (myValidConcepts.contains(system + "___" + code)) {
|
||||
retVal = new CodeValidationResult(new ConceptDefinitionComponent(new CodeType(code)));
|
||||
} else {
|
||||
retVal = myDefaultValidationSupport.validateCode(system, code, (String) theInvocation.getArguments()[2]);
|
||||
retVal = myDefaultValidationSupport.validateCode(ctx, system, code, (String) theInvocation.getArguments()[2]);
|
||||
}
|
||||
ourLog.info("validateCode({}, {}, {}) : {}",
|
||||
new Object[] { system, code, (String) theInvocation.getArguments()[2], retVal });
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
when(myMockSupport.fetchCodeSystem(any(String.class))).thenAnswer(new Answer<ValueSet>() {
|
||||
when(myMockSupport.fetchCodeSystem(any(FhirContext.class), any(String.class))).thenAnswer(new Answer<ValueSet>() {
|
||||
@Override
|
||||
public ValueSet answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
ValueSet retVal = myDefaultValidationSupport.fetchCodeSystem((String) theInvocation.getArguments()[0]);
|
||||
ValueSet retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[0],(String) theInvocation.getArguments()[1]);
|
||||
ourLog.info("fetchCodeSystem({}) : {}", new Object[] { (String) theInvocation.getArguments()[0], retVal });
|
||||
return retVal;
|
||||
}
|
||||
|
@ -306,6 +308,29 @@ public class FhirInstanceValidatorTest {
|
|||
output.getMessages().get(0).getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidateResourceWithValuesetExpansion() {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("http://system").setValue("12345").getType().addCoding().setSystem("foo").setCode("bar");
|
||||
|
||||
ValidationResult output = myVal.validateWithResult(patient);
|
||||
List<SingleValidationMessage> all = logResultsAndReturnAll(output);
|
||||
assertEquals(1, all.size());
|
||||
assertEquals("/f:Patient/f:identifier/f:type", all.get(0).getLocationString());
|
||||
assertEquals("None of the codes are in the expected value set http://hl7.org/fhir/ValueSet/identifier-type (http://hl7.org/fhir/ValueSet/identifier-type)", all.get(0).getMessage());
|
||||
assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity());
|
||||
|
||||
patient = new Patient();
|
||||
patient.addIdentifier().setSystem("http://system").setValue("12345").getType().addCoding().setSystem("http://hl7.org/fhir/v2/0203").setCode("MR");
|
||||
|
||||
output = myVal.validateWithResult(patient);
|
||||
all = logResultsAndReturnAll(output);
|
||||
assertEquals(0, all.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidateResourceWithExampleBindingCodeValidationFailing() {
|
||||
Observation input = new Observation();
|
||||
|
|
|
@ -84,6 +84,13 @@
|
|||
a more appropriate 400/404 in the JPA server (vread on invalid version,
|
||||
delete with no ID, etc.)
|
||||
</action>
|
||||
<action type="fix">
|
||||
Fix narrative generation for DSTU2 Medication resource
|
||||
</action>
|
||||
<action type="fix">
|
||||
Profile validator now works for valuesets which use
|
||||
v2 tables
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.2" date="2015-09-18">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue