use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project pathling by aehrc.
the class DefaultTerminologyServiceTest method testTranslateForValidAndInvalidCodings.
@Test
void testTranslateForValidAndInvalidCodings() {
// Response bundle:
// [1] CODING1_VERSION1 -> None
// [2] CODING2_VERSION1 -> { equivalent: CODING3_VERSION1, wider: CODING1_VERSION1}
final Bundle responseBundle = new Bundle().setType(BundleType.BATCHRESPONSE);
// entry with no mapping
final Parameters noTranslation = new Parameters().addParameter("result", false);
responseBundle.addEntry().setResource(noTranslation).getResponse().setStatus("200");
// entry with two mappings
final Parameters withTranslation = new Parameters().addParameter("result", true);
final ParametersParameterComponent equivalentMatch = withTranslation.addParameter().setName("match");
equivalentMatch.addPart().setName("equivalence").setValue(new CodeType("equivalent"));
equivalentMatch.addPart().setName("concept").setValue(CODING3_VERSION1.toCoding());
final ParametersParameterComponent widerMatch = withTranslation.addParameter().setName("match");
widerMatch.addPart().setName("equivalence").setValue(new CodeType("wider"));
widerMatch.addPart().setName("concept").setValue(CODING1_VERSION1.toCoding());
responseBundle.addEntry().setResource(withTranslation).getResponse().setStatus("200");
when(terminologyClient.batch(any())).thenReturn(responseBundle);
final ConceptTranslator actualTranslator = terminologyService.translate(Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null), "uuid:concept-map", false, Collections.singletonList(ConceptMapEquivalence.EQUIVALENT));
assertEquals(ConceptTranslatorBuilder.empty().put(CODING2_VERSION1, CODING3_VERSION1.toCoding()).build(), actualTranslator);
// expected request bundle
final Bundle requestBundle = new Bundle().setType(BundleType.BATCH);
requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING1_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING2_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
verify(terminologyClient).batch(deepEq(requestBundle));
verifyNoMoreInteractions(terminologyClient);
}
use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project kindling by HL7.
the class BuildWorkerContext method lookupLoinc.
private String lookupLoinc(String code) throws Exception {
if (true) {
// (!triedServer || serverOk) {
try {
triedServer = true;
// for this, we use the FHIR client
if (txClient == null) {
txClient = new TerminologyClientR5(tsServer);
this.txLog = new HTMLClientLogger(null);
}
Map<String, String> params = new HashMap<String, String>();
params.put("code", code);
params.put("system", "http://loinc.org");
Parameters result = txClient.lookupCode(params);
for (ParametersParameterComponent p : result.getParameter()) {
if (p.getName().equals("display"))
return ((StringType) p.getValue()).asStringValue();
}
throw new Exception("Did not find LOINC code in return values");
} catch (EFhirClientException e) {
serverOk = true;
throw e;
} catch (Exception e) {
serverOk = false;
throw e;
}
} else
throw new Exception("Server is not available");
}
use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project redmatch by aehrc.
the class RedmatchGrammarValidator method validateCode.
private ValidationResult validateCode(String code, String path, String message) throws IOException {
// Special case: codes ending with extension.url
if (code.endsWith("extension.url")) {
code = code.substring(0, code.length() - 4);
}
Boolean res = null;
Parameters out = terminologyService.validate(fhirPackage, code);
for (ParametersParameterComponent param : out.getParameter()) {
if (param.getName().equals("result")) {
res = ((BooleanType) param.getValue()).getValue();
}
}
if (res == null) {
throw new RuntimeException("Unexpected response (has no 'result' out parameter).");
}
ValidationResult vr = new ValidationResult(res, code);
if (!res) {
vr.getMessages().add(String.format(message, path));
}
return vr;
}
use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method serverValidateCode.
private ValidationResult serverValidateCode(Parameters pin) {
Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
boolean ok = false;
String message = "No Message returned";
String display = null;
for (ParametersParameterComponent p : pout.getParameter()) {
if (p.getName().equals("result"))
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
else if (p.getName().equals("message"))
message = ((StringType) p.getValue()).getValue();
else if (p.getName().equals("display"))
display = ((StringType) p.getValue()).getValue();
}
if (!ok)
return new ValidationResult(IssueSeverity.ERROR, message);
else if (display != null)
return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
else
return new ValidationResult(null);
}
use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method processValidationResult.
public ValidationResult processValidationResult(Parameters pOut) {
boolean ok = false;
String message = "No Message returned";
String display = null;
String system = null;
String code = null;
TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
for (ParametersParameterComponent p : pOut.getParameter()) {
if (p.hasValue()) {
if (p.getName().equals("result")) {
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
} else if (p.getName().equals("message")) {
message = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("display")) {
display = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("system")) {
system = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("code")) {
code = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("cause")) {
try {
IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
if (it == IssueType.UNKNOWN) {
err = TerminologyServiceErrorClass.UNKNOWN;
} else if (it == IssueType.NOTFOUND) {
err = TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED;
} else if (it == IssueType.NOTSUPPORTED) {
err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
} else {
err = null;
}
} catch (FHIRException e) {
}
}
}
}
if (!ok) {
return new ValidationResult(IssueSeverity.ERROR, message + " (from " + txClient.getAddress() + ")", err).setTxLink(txLog.getLastId());
} else if (message != null && !message.equals("No Message returned")) {
return new ValidationResult(IssueSeverity.WARNING, message + " (from " + txClient.getAddress() + ")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else if (display != null) {
return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else {
return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
}
}
Aggregations