Search in sources :

Example 1 with MedicalRecord

use of org.jbpm.test.entity.MedicalRecord in project jbpm by kiegroup.

the class PatientVariablePersistenceStrategyTest method simplePatientMedicalRecordTest.

@Test
public void simplePatientMedicalRecordTest() throws Exception {
    Patient salaboy = new Patient("salaboy");
    MedicalRecord medicalRecord = new MedicalRecord("Last Three Years Medical Hisotry", salaboy);
    emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.patient.example");
    addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    EntityManager em = emfDomain.createEntityManager();
    createRuntimeManager("org/jbpm/test/functional/jpa/patient-appointment.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    logger.info("### Starting process ###");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("medicalRecord", medicalRecord);
    ProcessInstance process = ksession.startProcess("org.jbpm.PatientAppointment", parameters);
    long processInstanceId = process.getId();
    // The process is in the first Human Task waiting for its completion
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
    List<? extends VariableInstanceLog> varLogs = runtimeEngine.getAuditService().findVariableInstances(processInstanceId, "medicalRecord");
    assertNotNull(varLogs);
    assertEquals(1, varLogs.size());
    // gets frontDesk's tasks
    List<TaskSummary> frontDeskTasks = taskService.getTasksAssignedAsPotentialOwner("frontDesk", "en-UK");
    Assert.assertEquals(1, frontDeskTasks.size());
    // doctor doesn't have any task
    List<TaskSummary> doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
    Assert.assertTrue(doctorTasks.isEmpty());
    // manager doesn't have any task
    List<TaskSummary> managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertTrue(managerTasks.isEmpty());
    taskService.start(frontDeskTasks.get(0).getId(), "frontDesk");
    // frontDesk completes its task
    MedicalRecord taskMedicalRecord = getTaskContent(runtimeEngine, frontDeskTasks.get(0));
    assertNotNull(taskMedicalRecord.getId());
    taskMedicalRecord.setDescription("Initial Description of the Medical Record");
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output1", taskMedicalRecord);
    taskService.complete(frontDeskTasks.get(0).getId(), "frontDesk", output);
    varLogs = runtimeEngine.getAuditService().findVariableInstances(processInstanceId, "medicalRecord");
    assertNotNull(varLogs);
    assertEquals(2, varLogs.size());
    assertTrue(varLogs.get(0).getValue().contains("Last Three Years Medical Hisotry"));
    assertTrue(varLogs.get(1).getValue().contains("Initial Description of the Medical Record"));
    // Now doctor has 1 task
    doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
    Assert.assertEquals(1, doctorTasks.size());
    // No tasks for manager yet
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertTrue(managerTasks.isEmpty());
    // modify the entity from outside
    taskMedicalRecord.setDescription("Initial Description of the Medical Record - Updated");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    try {
        ut.begin();
        em.merge(taskMedicalRecord);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    taskMedicalRecord = getTaskContent(runtimeEngine, doctorTasks.get(0));
    assertNotNull(taskMedicalRecord.getId());
    taskMedicalRecord.setDescription("Initial Description of the Medical Record - Updated");
    taskService.start(doctorTasks.get(0).getId(), "doctor");
    // Check that we have the Modified Document
    taskMedicalRecord = em.find(MedicalRecord.class, taskMedicalRecord.getId());
    Assert.assertEquals("Initial Description of the Medical Record - Updated", taskMedicalRecord.getDescription());
    taskMedicalRecord.setDescription("Medical Record Validated by Doctor");
    List<RecordRow> rows = new ArrayList<RecordRow>();
    RecordRow recordRow = new RecordRow("CODE-999", "Just a regular Cold");
    recordRow.setMedicalRecord(medicalRecord);
    rows.add(recordRow);
    taskMedicalRecord.setRows(rows);
    taskMedicalRecord.setPriority(1);
    output = new HashMap<String, Object>();
    output.put("output2", taskMedicalRecord);
    taskService.complete(doctorTasks.get(0).getId(), "doctor", output);
    // tasks for manager
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertEquals(1, managerTasks.size());
    taskService.start(managerTasks.get(0).getId(), "manager");
    Patient patient = taskMedicalRecord.getPatient();
    patient.setNextAppointment(new Date());
    output = new HashMap<String, Object>();
    output.put("output3", taskMedicalRecord);
    // ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);
    taskService.complete(managerTasks.get(0).getId(), "manager", output);
    // since persisted process instance is completed it should be null
    process = ksession.getProcessInstance(process.getId());
    Assert.assertNull(process);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) UserTransaction(javax.transaction.UserTransaction) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RecordRow(org.jbpm.test.entity.RecordRow) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) Patient(org.jbpm.test.entity.Patient) MedicalRecord(org.jbpm.test.entity.MedicalRecord) IOException(java.io.IOException) Date(java.util.Date) EntityManager(javax.persistence.EntityManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 2 with MedicalRecord

use of org.jbpm.test.entity.MedicalRecord in project jbpm by kiegroup.

the class PatientVariablePersistenceStrategyTest method getTaskContent.

@SuppressWarnings("rawtypes")
private MedicalRecord getTaskContent(RuntimeEngine runtimeEngine, TaskSummary summary) throws IOException, ClassNotFoundException {
    logger.info(" >>> Getting Task Content = {}", summary.getId());
    Task task = runtimeEngine.getTaskService().getTaskById(summary.getId());
    long documentContentId = task.getTaskData().getDocumentContentId();
    Content content = runtimeEngine.getTaskService().getContentById(documentContentId);
    Object readObject = ContentMarshallerHelper.unmarshall(content.getContent(), runtimeEngine.getKieSession().getEnvironment());
    logger.info(" >>> Object = {}", readObject);
    return (MedicalRecord) ((Map) readObject).get("Content");
}
Also used : Task(org.kie.api.task.model.Task) Content(org.kie.api.task.model.Content) MedicalRecord(org.jbpm.test.entity.MedicalRecord)

Aggregations

MedicalRecord (org.jbpm.test.entity.MedicalRecord)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 EntityManager (javax.persistence.EntityManager)1 UserTransaction (javax.transaction.UserTransaction)1 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)1 JPAPlaceholderResolverStrategy (org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy)1 Patient (org.jbpm.test.entity.Patient)1 RecordRow (org.jbpm.test.entity.RecordRow)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 TaskService (org.kie.api.task.TaskService)1 Content (org.kie.api.task.model.Content)1 Task (org.kie.api.task.model.Task)1 TaskSummary (org.kie.api.task.model.TaskSummary)1