use of org.hl7.fhir.dstu2016may.model.CodeType in project pathling by aehrc.
the class ImportTest method buildImportParameters.
@SuppressWarnings("SameParameterValue")
@Nonnull
Parameters buildImportParameters(@Nonnull final URL jsonURL, @Nonnull final ResourceType resourceType, @Nonnull final ImportMode mode) {
final Parameters parameters = buildImportParameters(jsonURL, resourceType);
final ParametersParameterComponent sourceParam = parameters.getParameter().stream().filter(p -> p.getName().equals("source")).findFirst().orElseThrow();
sourceParam.addPart().setName("mode").setValue(new CodeType(mode.getCode()));
return parameters;
}
use of org.hl7.fhir.dstu2016may.model.CodeType in project pathling by aehrc.
the class ImportTest method buildImportParameters.
@SuppressWarnings("SameParameterValue")
@Nonnull
Parameters buildImportParameters(@Nonnull final URL jsonURL, @Nonnull final ResourceType resourceType) {
final Parameters parameters = new Parameters();
final ParametersParameterComponent sourceParam = parameters.addParameter().setName("source");
sourceParam.addPart().setName("resourceType").setValue(new CodeType(resourceType.toCode()));
sourceParam.addPart().setName("url").setValue(new UrlType(jsonURL.toExternalForm()));
return parameters;
}
use of org.hl7.fhir.dstu2016may.model.CodeType in project pathling by aehrc.
the class DockerImageTest method importDataAndQuery.
@Test
void importDataAndQuery() throws JSONException {
try {
// Get the token endpoint from the CapabilityStatement.
final CapabilityStatement capabilities = getCapabilityStatement();
final String tokenUrl = capabilities.getRest().stream().findFirst().map(rest -> ((UriType) rest.getSecurity().getExtensionByUrl("http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris").getExtensionByUrl("token").getValue()).asStringValue()).orElseThrow();
// Get an access token from the token endpoint.
final HttpPost clientCredentialsGrant = new HttpPost(tokenUrl);
final List<? extends NameValuePair> nameValuePairs = Arrays.asList(new BasicNameValuePair("grant_type", "client_credentials"), new BasicNameValuePair("client_id", CLIENT_ID), new BasicNameValuePair("client_secret", CLIENT_SECRET), new BasicNameValuePair("scope", REQUESTED_SCOPE));
clientCredentialsGrant.setEntity(new UrlEncodedFormEntity(nameValuePairs));
log.info("Requesting client credentials grant");
final String accessToken;
try (final CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(clientCredentialsGrant)) {
assertThat(response.getStatusLine().getStatusCode()).withFailMessage("Client credentials grant did not succeed").isEqualTo(200);
final InputStream clientCredentialsStream = response.getEntity().getContent();
final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final ClientCredentialsResponse ccResponse = gson.fromJson(new InputStreamReader(clientCredentialsStream), ClientCredentialsResponse.class);
accessToken = ccResponse.getAccessToken();
}
// Create a request to the $import operation, referencing the NDJSON files we have loaded into
// the staging area.
final InputStream requestStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("import/SystemTest/request.Parameters.json");
assertThat(requestStream).isNotNull();
final HttpPost importRequest = new HttpPost("http://localhost:8091/fhir/$import");
importRequest.setEntity(new InputStreamEntity(requestStream));
importRequest.addHeader("Content-Type", "application/json");
importRequest.addHeader("Accept", "application/fhir+json");
importRequest.addHeader("Authorization", "Bearer " + accessToken);
log.info("Sending import request");
final OperationOutcome importOutcome;
try (final CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(importRequest)) {
final InputStream importResponseStream = response.getEntity().getContent();
importOutcome = (OperationOutcome) jsonParser.parseResource(importResponseStream);
assertThat(response.getStatusLine().getStatusCode()).withFailMessage(importOutcome.getIssueFirstRep().getDiagnostics()).isEqualTo(200);
}
assertThat(importOutcome.getIssueFirstRep().getDiagnostics()).isEqualTo("Data import completed successfully");
log.info("Import completed successfully");
final Parameters inParams = new Parameters();
// Set subject resource parameter.
final ParametersParameterComponent subjectResourceParam = new ParametersParameterComponent();
subjectResourceParam.setName("subjectResource");
subjectResourceParam.setValue(new CodeType("Patient"));
// Add aggregation, number of patients.
final ParametersParameterComponent aggregationParam = new ParametersParameterComponent();
aggregationParam.setName("aggregation");
aggregationParam.setValue(new StringType("count()"));
// Add grouping, has the patient been diagnosed with a chronic disease?
final ParametersParameterComponent groupingParam = new ParametersParameterComponent();
groupingParam.setName("grouping");
groupingParam.setValue(new StringType("reverseResolve(Condition.subject)" + ".code" + ".memberOf('http://snomed.info/sct?fhir_vs=ecl/" + "^ 32570581000036105 : " + "<< 263502005 = << 90734009')"));
// Add filter, females only.
final ParametersParameterComponent filterParam = new ParametersParameterComponent();
filterParam.setName("filter");
filterParam.setValue(new StringType("gender = 'female'"));
inParams.getParameter().add(subjectResourceParam);
inParams.getParameter().add(aggregationParam);
inParams.getParameter().add(groupingParam);
inParams.getParameter().add(filterParam);
// Send a request to the `$aggregate` operation on the FHIR server.
final String requestString = jsonParser.encodeResourceToString(inParams);
final HttpPost queryRequest = new HttpPost("http://localhost:8091/fhir/Patient/$aggregate");
queryRequest.setEntity(new StringEntity(requestString));
queryRequest.addHeader("Content-Type", "application/fhir+json");
queryRequest.addHeader("Accept", "application/fhir+json");
queryRequest.addHeader("Authorization", "Bearer " + accessToken);
log.info("Sending query request");
try (final CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(queryRequest)) {
final int statusCode = response.getStatusLine().getStatusCode();
final InputStream queryResponseStream = response.getEntity().getContent();
if (statusCode == 200) {
final StringWriter writer = new StringWriter();
IOUtils.copy(queryResponseStream, writer, StandardCharsets.UTF_8);
assertJson("responses/DockerImageTest/importDataAndQuery.Parameters.json", writer.toString());
} else {
captureLogs();
final OperationOutcome opOutcome = (OperationOutcome) jsonParser.parseResource(queryResponseStream);
assertEquals(200, statusCode, opOutcome.getIssueFirstRep().getDiagnostics());
}
}
} catch (final Exception e) {
captureLogs();
} finally {
stopContainer(dockerClient, fhirServerContainerId);
fhirServerContainerId = null;
getRuntime().removeShutdownHook(shutdownHook);
}
}
use of org.hl7.fhir.dstu2016may.model.CodeType 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.dstu2016may.model.CodeType in project kindling by HL7.
the class SpreadSheetReloader method parseStatus.
private void parseStatus(Element ed, String value) {
ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
ed.removeExtension(BuildExtensions.EXT_STANDARDS_STATUS);
ed.removeExtension(BuildExtensions.EXT_NORMATIVE_VERSION);
if (!Utilities.noString(value) && value.contains("/")) {
String[] p = value.split("\\/");
if (Utilities.noString(p[0].trim())) {
ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
} else {
ed.addExtension(BuildExtensions.EXT_FMM_LEVEL, new IntegerType(p[0]));
}
if (p[1].contains(";")) {
ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1].substring(0, p[1].indexOf(";"))));
ed.addExtension(BuildExtensions.EXT_NORMATIVE_VERSION, new CodeType(p[1].substring(p[1].indexOf("from=") + 5)));
} else {
ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1]));
}
}
sortExtensions(ed);
}
Aggregations