use of org.openmrs.module.fhir2.model.FhirTask 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.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toFhirResource_shouldTranslateBasedOn.
// Task.basedOn
@Test
public void toFhirResource_shouldTranslateBasedOn() {
FhirTask task = new FhirTask();
shouldTranslateReferenceListToFhir(task, FhirConstants.SERVICE_REQUEST, SERVICE_REQUEST_UUID, task::setBasedOnReferences, t -> new ArrayList<>(t.getBasedOn()));
}
use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldThrowExceptionWhenFhirTaskNull.
@Test(expected = NullPointerException.class)
public void toOpenmrsType_shouldThrowExceptionWhenFhirTaskNull() {
FhirTask task = new FhirTask();
task.setUuid(TASK_UUID);
taskTranslator.toOpenmrsType(task, null);
}
use of org.openmrs.module.fhir2.model.FhirTask 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.openmrs.module.fhir2.model.FhirTask 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));
}
Aggregations