use of org.hl7.fhir.r4.model.DiagnosticReport in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveActivityDefinition.
// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
Resource result = newResource(activityDefinition.getKind().toCode());
switch(result.fhirType()) {
case "ServiceRequest":
result = resolveServiceRequest(activityDefinition, patientId, practitionerId, organizationId);
break;
case "MedicationRequest":
result = resolveMedicationRequest(activityDefinition, patientId);
break;
case "SupplyRequest":
result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
break;
case "Procedure":
result = resolveProcedure(activityDefinition, patientId);
break;
case "DiagnosticReport":
result = resolveDiagnosticReport(activityDefinition, patientId);
break;
case "Communication":
result = resolveCommunication(activityDefinition, patientId);
break;
case "CommunicationRequest":
result = resolveCommunicationRequest(activityDefinition, patientId);
break;
case "Task":
result = resolveTask(activityDefinition, patientId);
break;
}
for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
// ActivityDefinition apply operation does not fail.
try {
if (dynamicValue.getExpression() != null) {
// Special case for setting a Patient reference
if ("Patient".equals(dynamicValue.getExpression().getExpression())) {
this.modelResolver.setValue(result, dynamicValue.getPath(), new Reference(patientId));
} else {
/*
* TODO: Passing the activityDefinition as context here because that's what will
* have the libraries, but perhaps the "context" here should be the result
* resource?
*/
Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression().getExpression(), patientId, theRequest);
if (value != null) {
logger.debug("dynamicValue value: {}", value);
if (value instanceof Boolean) {
value = new BooleanType((Boolean) value);
} else if (value instanceof DateTime) {
value = Date.from(((DateTime) value).getDateTime().toInstant());
} else if (value instanceof String) {
value = new StringType((String) value);
}
this.modelResolver.setValue(result, dynamicValue.getPath(), value);
} else {
logger.warn("WARNING: ActivityDefinition has null value for path: {}", dynamicValue.getPath());
}
}
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition dynamicValue {} could not be applied and threw exception {}", dynamicValue.getPath(), e.toString());
logger.error(e.toString());
}
}
return result;
}
use of org.hl7.fhir.r4.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportSearchQueryTest method searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongObsResult.
@Test
public void searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongObsResult() {
ReferenceAndListParam param = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam(DIAGNOSTIC_REPORT_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.RESULT_SEARCH_HANDLER, param);
IBundleProvider diagnosticReports = search(theParams);
assertThat(diagnosticReports, notNullValue());
assertThat(diagnosticReports.size(), equalTo(0));
List<DiagnosticReport> resultList = get(diagnosticReports);
assertThat(diagnosticReports, notNullValue());
assertThat(resultList.size(), equalTo(0));
}
use of org.hl7.fhir.r4.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportSearchQueryTest method searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongIssueDate.
@Test
public void searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongIssueDate() {
DateRangeParam issueDate = new DateRangeParam(new DateParam(DIAGNOSTIC_REPORT_WRONG_DATETIME));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, issueDate);
IBundleProvider diagnosticReports = search(theParams);
assertThat(diagnosticReports, notNullValue());
assertThat(diagnosticReports.size(), equalTo(0));
List<DiagnosticReport> resultList = get(diagnosticReports);
assertThat(resultList, empty());
}
use of org.hl7.fhir.r4.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportSearchQueryTest method searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongPatientIdentifier.
@Test
public void searchForDiagnosticReports_shouldReturnEmptyCollectionByWrongPatientIdentifier() {
ReferenceAndListParam patientReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(WRONG_PATIENT_IDENTIFIER).setChain(SP_IDENTIFIER)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference);
IBundleProvider diagnosticReports = search(theParams);
assertThat(diagnosticReports, notNullValue());
assertThat(diagnosticReports.size(), equalTo(0));
List<DiagnosticReport> resultList = get(diagnosticReports);
assertThat(resultList, empty());
}
use of org.hl7.fhir.r4.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportSearchQueryTest method searchForDiagnosticReports_shouldReturnDiagnosticReportByPatientName.
@Test
public void searchForDiagnosticReports_shouldReturnDiagnosticReportByPatientName() {
ReferenceAndListParam patientReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference);
IBundleProvider diagnosticReports = search(theParams);
assertThat(diagnosticReports, notNullValue());
assertThat(diagnosticReports.size(), greaterThanOrEqualTo(1));
List<DiagnosticReport> resultList = get(diagnosticReports);
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList.get(0).getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
}
Aggregations