use of org.hl7.fhir.r4.model.Task in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldTranslateUnsupportedStatusToUnknown.
@Test
public void toOpenmrsType_shouldTranslateUnsupportedStatusToUnknown() {
Task task = new Task();
task.setStatus(Task.TaskStatus.ENTEREDINERROR);
FhirTask result = taskTranslator.toOpenmrsType(task);
assertThat(result, notNullValue());
assertThat(result.getStatus(), equalTo(FhirTask.TaskStatus.UNKNOWN));
}
use of org.hl7.fhir.r4.model.Task in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toFhirResource_shouldAddProvenanceResources.
@Test
public void toFhirResource_shouldAddProvenanceResources() {
FhirTask task = new FhirTask();
task.setUuid(TASK_UUID);
Provenance provenance = new Provenance();
provenance.setId(new IdType(FhirUtils.newUuid()));
when(provenanceTranslator.getCreateProvenance(task)).thenReturn(provenance);
when(provenanceTranslator.getUpdateProvenance(task)).thenReturn(provenance);
org.hl7.fhir.r4.model.Task result = taskTranslator.toFhirResource(task);
assertThat(result, notNullValue());
assertThat(result.getContained(), not(empty()));
assertThat(result.getContained().size(), greaterThanOrEqualTo(2));
assertThat(result.getContained().stream().anyMatch(resource -> resource.getResourceType().name().equals(Provenance.class.getSimpleName())), is(true));
}
use of org.hl7.fhir.r4.model.Task in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldUpdateOutputReference.
@Test
public void toOpenmrsType_shouldUpdateOutputReference() {
Task task = new Task();
Task.TaskOutputComponent output = new Task.TaskOutputComponent();
Reference outputReference = new Reference().setReference(DIAGNOSTIC_REPORT_UUID).setType(FhirConstants.DIAGNOSTIC_REPORT);
CodeableConcept outputType = new CodeableConcept().setText("some text");
output.setType(outputType).setValue(outputReference);
Concept openmrsOutputType = new Concept();
openmrsOutputType.setUuid(CONCEPT_UUID);
task.setOutput(Collections.singletonList(output));
FhirTask openmrsTask = new FhirTask();
openmrsTask.setUuid(TASK_UUID);
openmrsTask.setOutput(Collections.singleton(new FhirTaskOutput()));
when(conceptTranslator.toOpenmrsType(outputType)).thenReturn(openmrsOutputType);
FhirTask result = shouldUpdateReferenceInOpenmrs(task, FhirConstants.DIAGNOSTIC_REPORT, DIAGNOSTIC_REPORT_UUID, output::setValue, t -> t.getOutput().iterator().next().getValueReference());
assertThat(result.getOutput(), hasSize(1));
assertThat(result.getOutput().iterator().next().getType().getUuid(), equalTo(CONCEPT_UUID));
}
use of org.hl7.fhir.r4.model.Task in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method shouldUpdateReferenceListInOpenmrs.
private void shouldUpdateReferenceListInOpenmrs(Task task, String refType, String refUuid, Consumer<List<Reference>> setFhirReference, Function<FhirTask, Set<FhirReference>> getOpenmrsReference) {
Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
setFhirReference.accept(Collections.singletonList(fhirReference));
FhirReference openmrsReference = new FhirReference();
openmrsReference.setReference(refUuid);
openmrsReference.setType(refType);
FhirTask openmrsTask = new FhirTask();
openmrsTask.setUuid(TASK_UUID);
openmrsTask.setEncounterReference(new FhirReference());
when(referenceTranslator.toOpenmrsType(any(Reference.class))).thenReturn(openmrsReference);
FhirTask result = taskTranslator.toOpenmrsType(openmrsTask, task);
Collection<FhirReference> resultReference = getOpenmrsReference.apply(result);
assertThat(resultReference, notNullValue());
assertThat(resultReference, hasSize(1));
assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
assertThat(resultReference.iterator().next().getType(), equalTo(refType));
}
use of org.hl7.fhir.r4.model.Task in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toFhirResource_shouldTranslateInputTextValue.
// Task.input
@Test
public void toFhirResource_shouldTranslateInputTextValue() {
FhirTask task = new FhirTask();
FhirTaskInput input = new FhirTaskInput();
String inputVal = "some input value";
Concept inputType = new Concept();
inputType.setUuid(CONCEPT_UUID);
input.setType(inputType);
input.setValueText(inputVal);
task.setInput(Collections.singleton(input));
when(conceptTranslator.toFhirResource(inputType)).thenReturn(new CodeableConcept().setCoding(Collections.singletonList(new Coding().setCode(CONCEPT_UUID))));
Task result = taskTranslator.toFhirResource(task);
assertThat(result, notNullValue());
assertThat(result.getInput(), hasSize(1));
assertThat(result.getInput().iterator().next().getType().getCoding().iterator().next().getCode(), equalTo(CONCEPT_UUID));
assertThat(result.getInput().iterator().next().getValue().toString(), equalTo(inputVal));
}
Aggregations