Work on term service

This commit is contained in:
James Agnew 2016-06-27 08:22:09 -04:00
parent 21ea81dd7f
commit cf0ac8fc04
3 changed files with 69 additions and 34 deletions

View File

@ -34,6 +34,7 @@ import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.dstu3.exceptions.TerminologyServiceException;
import org.hl7.fhir.dstu3.hapi.validation.HapiWorkerContext;
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport;
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.CodeableConcept;
@ -169,7 +170,6 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, Coding theCoding, CodeableConcept theCodeableConcept) {
List<IIdType> valueSetIds = Collections.emptyList();
List<IIdType> codeSystemIds = Collections.emptyList();
boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
boolean haveCoding = theCoding != null && theCoding.isEmpty() == false;
@ -204,6 +204,26 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
}
}
// if (valueSetIds.isEmpty()) {
// if (haveIdentifierParam) {
// myValidationSupport.expandValueSet(getContext(), include);
// if (myValidationSupport.isCodeSystemSupported(getContext(), theValueSetIdentifier.getValue())) {
// String system = toStringOrNull(theSystem);
// String code = toStringOrNull(theCode);
// String display = toStringOrNull(theDisplay);
// CodeValidationResult result = myValidationSupport.validateCode(getContext(), system, code, display);
// if (result != null) {
// if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) {
// if (!theDisplay.getValue().equals(result.getDisplay())) {
// return new ValidateCodeResult(false, "Display for code does not match", result.getDisplay());
// }
// }
// return new ValidateCodeResult(true, "Code validates", result.getDisplay());
// }
// }
// }
// }
for (IIdType nextId : valueSetIds) {
ValueSet expansion = expand(nextId, null);
List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
@ -218,19 +238,6 @@ public class FhirResourceDaoValueSetDstu3 extends FhirResourceDaoDstu3<ValueSet>
}
}
for (IIdType nextId : codeSystemIds) {
ValueSet expansion = expand(nextId, null);
List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
ValidateCodeResult result = validateCodeIsInContains(contains, toStringOrNull(theSystem), toStringOrNull(theCode), theCoding, theCodeableConcept);
if (result != null) {
if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) {
if (!theDisplay.getValue().equals(result.getDisplay())) {
return new ValidateCodeResult(false, "Display for code does not match", result.getDisplay());
}
}
return result;
}
}
return new ValidateCodeResult(false, "Code not found", null);
}

View File

@ -82,27 +82,11 @@ public class BaseJpaResourceProviderValueSetDstu3 extends JpaResourceProviderDst
}
private static boolean moreThanOneTrue(boolean... theBooleans) {
boolean haveOne = false;
for (boolean next : theBooleans) {
if (next) {
if (haveOne) {
return true;
} else {
haveOne = true;
}
}
}
return false;
}
private String toFilterString(StringType theFilter) {
return theFilter != null ? theFilter.getValue() : null;
}
//@formatter:off
@SuppressWarnings("unchecked")
@Operation(name = "$validate-code", idempotent = true, returnParameters= {
@ -141,4 +125,20 @@ public class BaseJpaResourceProviderValueSetDstu3 extends JpaResourceProviderDst
}
private static boolean moreThanOneTrue(boolean... theBooleans) {
boolean haveOne = false;
for (boolean next : theBooleans) {
if (next) {
if (haveOne) {
return true;
} else {
haveOne = true;
}
}
}
return false;
}
}

View File

@ -12,7 +12,6 @@ import java.io.IOException;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.UriType;
@ -20,11 +19,11 @@ import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.TestUtil;
public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test {
@ -98,6 +97,8 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3
}
//
@Test
public void testExpandByIdentifier() {
//@formatter:off
@ -120,6 +121,33 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3
}
@Test
@Ignore
public void testValidateCode() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new StringType("BRN"))
.andParameter("identifier", new StringType("http://hl7.org/fhir/ValueSet/v2-0487"))
.andParameter("system", new StringType("http://hl7.org/fhir/v2/0487"))
.useHttpGet()
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
//@formatter:off
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
//@formatter:on
}
@Test
public void testExpandByValueSet() throws IOException {
ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml");