use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method eventHappensWithin4Days.
@Test
public void eventHappensWithin4Days() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
Observation observationIN = new Observation();
DateTimeType observationEffective = new DateTimeType(new Date());
observationEffective.setYear(2015);
observationEffective.setMonth(1);
observationEffective.setDay(15);
observationIN.setEffective(observationEffective);
observationIN.setId("FIRST");
Observation observationOUT = new Observation();
DateTimeType observationEffective2 = new DateTimeType(new Date());
observationEffective2.setYear(2015);
observationEffective2.setMonth(1);
observationEffective2.setDay(16);
observationOUT.setEffective(observationEffective2);
observationOUT.setId("SECOND");
Bundle bundle = new Bundle();
Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
firstEncounter.setResource(observationIN);
Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
secondEncounter.setResource(observationOUT);
bundle.addEntry(firstEncounter);
bundle.addEntry(secondEncounter);
mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "ValidObservation within 4 days";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test5", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method doesNotFindEventAfterSecondEvent.
@Test
public void doesNotFindEventAfterSecondEvent() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
Observation observationOUT = new Observation();
DateTimeType observationEffective2 = new DateTimeType(new Date());
observationEffective2.setYear(2017);
observationEffective2.setMonth(1);
observationEffective2.setDay(15);
observationOUT.setEffective(observationEffective2);
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observationOUT, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "Observations Exist";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test1", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, false);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method confirmCanFindEventAfterSecondEvent.
@Test
public void confirmCanFindEventAfterSecondEvent() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
Observation observationIN = new Observation();
DateTimeType observationEffective = new DateTimeType(new Date());
observationEffective.setYear(2015);
observationEffective.setMonth(1);
observationEffective.setDay(15);
observationIN.setEffective(observationEffective);
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observationIN, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "Observations Exist";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test1", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method determineIfAnEventFollows.
@Test
public void determineIfAnEventFollows() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_3, fhirConfig);
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "NotFollowedByCondition";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test4", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandler method createValueSet.
@POST
@Path("/valueset/")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiImplicitParams({ // This is necessary for the dark launch feature
@ApiImplicitParam(access = DarkFeatureSwaggerFilter.DARK_FEATURE_CONTROLLED, paramType = "header", dataType = "string"), @ApiImplicitParam(name = FHIR_DATA_SERVER_CONFIG_PART, value = CohortEngineRestHandler.EXAMPLE_DATA_SERVER_CONFIG_JSON, dataTypeClass = FhirServerConfig.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = VALUE_SET_PART, value = VALUE_SET_DESC, dataTypeClass = File.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = CUSTOM_CODE_SYSTEM, value = CUSTOM_CODE_SYSTEM_DESC, dataTypeClass = File.class, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 201, message = "Successful Operation"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 409, message = "Conflict", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
@ApiOperation(value = "Insert a new value set to the fhir server or, if it already exists, update it in place", notes = CohortEngineRestHandler.VALUE_SET_API_NOTES, tags = { "ValueSet" }, nickname = "create_value_set", extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD) }) })
public Response createValueSet(@DefaultValue(ServiceBuildConstants.DATE) @ApiParam(value = ServiceBaseConstants.MINOR_VERSION_DESCRIPTION, required = true, defaultValue = ServiceBuildConstants.DATE) @QueryParam(CohortEngineRestHandler.VERSION) String version, @ApiParam(hidden = true, type = "file", required = true) IMultipartBody multipartBody, @ApiParam(value = CohortEngineRestHandler.VALUE_SET_UPDATE_IF_EXISTS_DESC, defaultValue = "false") @DefaultValue("false") @QueryParam(CohortEngineRestHandler.UPDATE_IF_EXISTS_PARM) boolean updateIfExists) {
String methodName = MethodNames.CREATE_VALUE_SET.getName();
Response response;
ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_VALUE_SET_UPLOAD);
try {
// Perform api setup
Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
if (errorResponse != null) {
return errorResponse;
}
IAttachment dataSourceAttachment = multipartBody.getAttachment(FHIR_DATA_SERVER_CONFIG_PART);
if (dataSourceAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", FHIR_DATA_SERVER_CONFIG_PART));
}
// deserialize the MeasuresEvaluation request
ObjectMapper om = new ObjectMapper();
FhirServerConfig fhirServerConfig = om.readValue(dataSourceAttachment.getDataHandler().getInputStream(), FhirServerConfig.class);
// validate the contents of the fhirServerConfig
validateBean(fhirServerConfig);
// get the fhir client object used to call to FHIR
FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder();
IGenericClient terminologyClient = clientBuilder.createFhirClient(fhirServerConfig);
IAttachment valueSetAttachment = multipartBody.getAttachment(VALUE_SET_PART);
if (valueSetAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", VALUE_SET_PART));
}
IAttachment customCodes = multipartBody.getAttachment(CUSTOM_CODE_SYSTEM);
Map<String, String> customCodeMap = null;
if (customCodes != null) {
customCodeMap = ValueSetUtil.getMapFromInputStream(customCodes.getDataHandler().getInputStream());
}
ValueSetArtifact artifact;
try (InputStream is = valueSetAttachment.getDataHandler().getInputStream()) {
artifact = ValueSetUtil.createArtifact(is, customCodeMap);
}
ValueSetUtil.validateArtifact(artifact);
String valueSetId = ValueSetUtil.importArtifact(terminologyClient, artifact, updateIfExists);
if (valueSetId == null) {
return Response.status(Response.Status.CONFLICT).header("Content-Type", "application/json").entity("{\"message\":\"Value Set already exists! Rerun with updateIfExists set to true!\"}").build();
}
response = Response.status(Response.Status.CREATED).header("Content-Type", "application/json").entity("{\"valueSetId\":\"" + valueSetId + "\"}").build();
} catch (Throwable e) {
return new CohortServiceExceptionMapper().toResponse(e);
} finally {
// Perform api cleanup
Response errorResponse = ServiceBaseUtility.apiCleanup(logger, methodName);
if (errorResponse != null) {
response = errorResponse;
}
}
return response;
}
Aggregations