use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskServiceImplTest method getTask_shouldRetrieveTaskByUuid.
@Test
public void getTask_shouldRetrieveTaskByUuid() {
FhirTask task = new FhirTask();
org.hl7.fhir.r4.model.Task translatedTask = new org.hl7.fhir.r4.model.Task();
task.setUuid(TASK_UUID);
translatedTask.setId(TASK_UUID);
when(dao.get(TASK_UUID)).thenReturn(task);
when(translator.toFhirResource(task)).thenReturn(translatedTask);
org.hl7.fhir.r4.model.Task result = fhirTaskService.get(TASK_UUID);
assertThat(result, notNullValue());
assertThat(result, equalTo(translatedTask));
}
use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskServiceImplTest method updateTask_shouldUpdateExistingTask.
@Test
public void updateTask_shouldUpdateExistingTask() {
org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
FhirTask openmrsTask = new FhirTask();
FhirTask updatedOpenmrsTask = new FhirTask();
fhirTask.setId(TASK_UUID);
fhirTask.setStatus(FHIR_NEW_TASK_STATUS);
fhirTask.setIntent(FHIR_TASK_INTENT);
openmrsTask.setUuid(TASK_UUID);
openmrsTask.setStatus(OPENMRS_TASK_STATUS);
openmrsTask.setIntent(OPENMRS_TASK_INTENT);
updatedOpenmrsTask.setUuid(TASK_UUID);
updatedOpenmrsTask.setStatus(OPENMRS_NEW_TASK_STATUS);
openmrsTask.setIntent(OPENMRS_TASK_INTENT);
when(translator.toOpenmrsType(openmrsTask, fhirTask)).thenReturn(updatedOpenmrsTask);
when(dao.createOrUpdate(updatedOpenmrsTask)).thenReturn(updatedOpenmrsTask);
when(dao.get(TASK_UUID)).thenReturn(openmrsTask);
when(translator.toFhirResource(updatedOpenmrsTask)).thenReturn(fhirTask);
org.hl7.fhir.r4.model.Task result = fhirTaskService.update(TASK_UUID, fhirTask);
assertThat(result, notNullValue());
assertThat(result, equalTo(fhirTask));
}
use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskDaoImplTest method saveTask_shouldCreateNewTask.
@Test
public void saveTask_shouldCreateNewTask() {
FhirTask newTask = new FhirTask();
newTask.setStatus(NEW_STATUS);
newTask.setName(TASK_INTENT.toString());
newTask.setIntent(TASK_INTENT);
dao.createOrUpdate(newTask);
FhirTask result = dao.get(TASK_UUID);
assertThat(result, notNullValue());
assertThat(result.getStatus(), equalTo(NEW_STATUS));
}
use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.
the class FhirTaskDaoImplTest method saveTask_shouldUpdateInput.
@Test
public void saveTask_shouldUpdateInput() throws Exception {
executeDataSet(CONCEPT_DATA_XML);
HibernateConceptDAO cd = new HibernateConceptDAO();
cd.setSessionFactory(sessionFactory);
FhirTask toUpdate = dao.get(TASK_UUID);
Double someNumericVal = 123123.11;
Concept type = cd.getConceptByUuid(CONCEPT_UUID);
assertThat(type, notNullValue());
FhirTaskInput input = new FhirTaskInput();
input.setValueNumeric(someNumericVal);
input.setType(type);
input.setName("TEMP");
// TODO: why is this not autogenerated?
input.setId(23423);
toUpdate.setInput(Collections.singleton(input));
FhirTask result = dao.get(TASK_UUID);
assertThat(result.getInput(), notNullValue());
assertThat(result.getInput(), not(empty()));
assertThat(result.getInput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID)))));
assertThat(result.getInput(), hasItem(hasProperty("valueNumeric", equalTo(someNumericVal))));
}
use of org.openmrs.module.fhir2.model.FhirTask 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)))));
}
Aggregations