Search in sources :

Example 1 with FhirTask

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));
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Example 2 with FhirTask

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));
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Example 3 with 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));
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with FhirTask

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))));
}
Also used : Concept(org.openmrs.Concept) HibernateConceptDAO(org.openmrs.api.db.hibernate.HibernateConceptDAO) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 5 with FhirTask

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)))));
}
Also used : Concept(org.openmrs.Concept) HibernateConceptDAO(org.openmrs.api.db.hibernate.HibernateConceptDAO) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirReference(org.openmrs.module.fhir2.model.FhirReference) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

FhirTask (org.openmrs.module.fhir2.model.FhirTask)66 Test (org.junit.Test)57 Task (org.hl7.fhir.r4.model.Task)47 FhirReference (org.openmrs.module.fhir2.model.FhirReference)16 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)10 Reference (org.hl7.fhir.r4.model.Reference)9 Concept (org.openmrs.Concept)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)7 Date (java.util.Date)5 FhirTaskInput (org.openmrs.module.fhir2.model.FhirTaskInput)4 FhirTaskOutput (org.openmrs.module.fhir2.model.FhirTaskOutput)4 Coding (org.hl7.fhir.r4.model.Coding)3 StringType (org.hl7.fhir.r4.model.StringType)3 ArrayList (java.util.ArrayList)2 Identifier (org.hl7.fhir.r4.model.Identifier)2 Provenance (org.hl7.fhir.r4.model.Provenance)2 Before (org.junit.Before)2 HibernateConceptDAO (org.openmrs.api.db.hibernate.HibernateConceptDAO)2 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)1 Collection (java.util.Collection)1