use of org.openmrs.module.fhir2.model.FhirReference in project openmrs-module-fhir2 by openmrs.
the class FhirTaskDaoImplTest method saveTask_shouldUpdateOutput.
@Test
public void saveTask_shouldUpdateOutput() throws Exception {
executeDataSet(CONCEPT_DATA_XML);
HibernateConceptDAO cd = new HibernateConceptDAO();
cd.setSessionFactory(sessionFactory);
FhirTask toUpdate = dao.get(TASK_UUID);
FhirReference outputReference = new FhirReference();
outputReference.setType(FhirConstants.DIAGNOSTIC_REPORT);
outputReference.setReference(DIAGNOSTIC_REPORT_UUID);
outputReference.setName("TEMP");
Concept type = cd.getConceptByUuid(CONCEPT_UUID);
assertThat(type, notNullValue());
FhirTaskOutput output = new FhirTaskOutput();
output.setValueReference(outputReference);
output.setType(type);
output.setName("TEMP");
// TODO: why is this not autogenerated?
output.setId(23423);
toUpdate.setOutput(Collections.singleton(output));
FhirTask result = dao.get(TASK_UUID);
assertThat(result.getOutput(), notNullValue());
assertThat(result.getOutput(), not(empty()));
assertThat(result.getOutput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID)))));
assertThat(result.getOutput(), hasItem(hasProperty("valueReference", hasProperty("reference", equalTo(DIAGNOSTIC_REPORT_UUID)))));
}
use of org.openmrs.module.fhir2.model.FhirReference in project openmrs-module-fhir2 by openmrs.
the class FhirTaskDaoImplTest method searchForTasks_shouldHandleNullBasedOnRefs.
@Test
public void searchForTasks_shouldHandleNullBasedOnRefs() {
FhirTask toUpdate = dao.get(TASK_UUID);
FhirReference nullTypeRef = new FhirReference();
nullTypeRef.setType(null);
nullTypeRef.setReference(BASED_ON_ORDER_UUID);
toUpdate.setOwnerReference(nullTypeRef);
toUpdate.setBasedOnReferences(Collections.singleton(nullTypeRef));
dao.createOrUpdate(toUpdate);
FhirTask result = dao.get(TASK_UUID);
assertThat(result.getBasedOnReferences(), notNullValue());
assertThat(result.getBasedOnReferences().size(), greaterThan(0));
}
use of org.openmrs.module.fhir2.model.FhirReference in project openmrs-module-fhir2 by openmrs.
the class FhirTaskDaoImplTest method saveTask_shouldUpdateEncounterReference.
@Test
public void saveTask_shouldUpdateEncounterReference() {
FhirTask toUpdate = dao.get(TASK_UUID);
FhirReference forReference = new FhirReference();
forReference.setType(FhirConstants.ENCOUNTER);
forReference.setReference(ENCOUNTER_UUID);
forReference.setName("TEMP");
toUpdate.setEncounterReference(forReference);
dao.createOrUpdate(toUpdate);
FhirTask result = dao.get(TASK_UUID);
assertThat(result.getEncounterReference(), notNullValue());
assertThat(result.getEncounterReference().getId(), notNullValue());
assertThat(result.getEncounterReference().getType(), equalTo(FhirConstants.ENCOUNTER));
assertThat(result.getEncounterReference().getReference(), equalTo(ENCOUNTER_UUID));
}
use of org.openmrs.module.fhir2.model.FhirReference in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method shouldTranslateReferenceListToFhir.
private void shouldTranslateReferenceListToFhir(FhirTask task, String refType, String refUuid, Consumer<Set<FhirReference>> setOpenmrsReference, Function<Task, List<Reference>> getFhirReference) {
FhirReference openmrsReference = new FhirReference();
openmrsReference.setType(refType);
openmrsReference.setReference(refUuid);
setOpenmrsReference.accept(Collections.singleton(openmrsReference));
Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
Task result = taskTranslator.toFhirResource(task);
Collection<Reference> resultReference = getFhirReference.apply(result);
assertThat(resultReference, notNullValue());
assertThat(resultReference, hasSize(1));
assertThat(resultReference.iterator().next(), notNullValue());
assertThat(resultReference.iterator().next().getType(), equalTo(refType));
assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
}
use of org.openmrs.module.fhir2.model.FhirReference in project openmrs-module-fhir2 by openmrs.
the class FhirTaskTranslatorImplTest method shouldTranslateReferenceToFhir.
/**
* Helpers for reference associations
*/
private Task shouldTranslateReferenceToFhir(FhirTask task, String refType, String refUuid, Consumer<FhirReference> setOpenmrsReference, Function<Task, Reference> getFhirReference) {
FhirReference openmrsReference = new FhirReference();
openmrsReference.setType(refType);
openmrsReference.setReference(refUuid);
setOpenmrsReference.accept(openmrsReference);
Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
Task result = taskTranslator.toFhirResource(task);
Reference resultReference = getFhirReference.apply(result);
assertThat(resultReference, notNullValue());
assertThat(resultReference.getType(), equalTo(refType));
assertThat(resultReference.getReference(), equalTo(refUuid));
return result;
}
Aggregations