Search in sources :

Example 11 with Patient

use of com.salaboy.jbpm5.dev.guide.model.Patient in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessExecutorTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("InsuranceProcessV2.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
    //Registers the same generic handler for all the tasks. The handler will
    //schedule commands into the Executor Service. Each task in the process
    //is configured to use a different command.
    AsyncGenericWorkItemHandler genericHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
    session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Insurance Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Rates Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Invoice Service", genericHandler);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) AsyncGenericWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 12 with Patient

use of com.salaboy.jbpm5.dev.guide.model.Patient in project jBPM5-Developer-Guide by Salaboy.

the class InsuranceServiceImpl method notifyAndChargePatient.

public boolean notifyAndChargePatient(Patient patient, BigDecimal amount, List<ConceptCode> concepts) {
    System.out.println("+--------------------------------------------------------------+");
    System.out.println("| ### Hospital Invoice                                         |");
    System.out.println("+--------------------------------------------------------------+");
    DateFormat df = new SimpleDateFormat("EEE, MMM d, yyyy", Locale.UK);
    System.out.println("| Date: " + df.format(new Date()) + "|");
    System.out.println("|--------------------------------------------------------------|");
    System.out.println("| Patient: " + patient.getFirstName() + "," + patient.getLastName() + "|");
    System.out.println("|--------------------------------------------------------------|");
    //System.out.println("| Insured: "++"                                                |");
    System.out.println("|--------------------------------------------------------------|");
    System.out.println("| Concepts:                                                    |");
    System.out.println("|--------------------------------------------------------------|");
    for (ConceptCode code : concepts) {
        System.out.println("| -> Concept:  " + code.getDesc() + " ---------  | " + code.getUnits() + " X  |" + code.getRate() + "");
    }
    System.out.println("|--------------------------------------------------+-----------|");
    System.out.println("| Total                                            |        " + amount + "|");
    System.out.println("|--------------------------------------------------+-----------|");
    System.out.println(" -> Sending Invoce Via Email to: " + patient.getEmail());
    System.out.println(" -> Charging Credit Card (" + patient.getCreditCardNumber() + ") - Total: " + amount);
    return true;
}
Also used : ConceptCode(com.salaboy.jbpm5.dev.guide.model.ConceptCode) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 13 with Patient

use of com.salaboy.jbpm5.dev.guide.model.Patient in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessExecutorTest method testPatientInsuredProcessWithExecutor.

/**
     * Tests the execution path for a patient having a valid insurance.
     */
@Test
public void testPatientInsuredProcessWithExecutor() throws InterruptedException {
    HashMap<String, Object> input = new HashMap<String, Object>();
    Patient salaboy = testPatients.get("salaboy");
    input.put("patientName", salaboy.getId());
    SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    //Our application can continue doing other things, the executor will do the rest
    Thread.sleep(25000);
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    assertEquals(Boolean.TRUE, pI.getVariable("patientNotified"));
    assertEquals(50, ((BigDecimal) pI.getVariable("finalAmount")).intValue());
}
Also used : HashMap(java.util.HashMap) Patient(com.salaboy.jbpm5.dev.guide.model.Patient) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 14 with Patient

use of com.salaboy.jbpm5.dev.guide.model.Patient in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceServiceTest method setUp.

@Before
public void setUp() {
    initializeWebService();
    Patient salaboy = new Patient(UUID.randomUUID().toString(), "Salaboy", "SalaboyLastName", "salaboy@gmail.com", "555-15151-515151", 28);
    testPatients.put("salaboy", salaboy);
    Patient nonInsuredBrotha = new Patient(UUID.randomUUID().toString(), "John", "Doe", "gansta1980@gmail.com", "333-333131-13131", 40);
    testPatients.put("brotha", nonInsuredBrotha);
    this.service.getPatients().put(testPatients.get("salaboy").getId(), testPatients.get("salaboy"));
    this.service.getPatients().put(testPatients.get("brotha").getId(), testPatients.get("brotha"));
    this.service.getInsuredPatients().put(testPatients.get("salaboy").getId(), Boolean.TRUE);
    this.service.getInsuredPatients().put(testPatients.get("brotha").getId(), Boolean.FALSE);
}
Also used : Patient(com.salaboy.jbpm5.dev.guide.model.Patient) Before(org.junit.Before)

Example 15 with Patient

use of com.salaboy.jbpm5.dev.guide.model.Patient in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceServiceTest method patientNotInsuredTest.

@Test
public void patientNotInsuredTest() {
    Patient patient = this.service.getPatientData(testPatients.get("brotha").getId());
    assertNotNull(patient);
    boolean isPatientInsured = this.service.isPatientInsured(patient.getId());
    assertFalse(isPatientInsured);
    List<ConceptCode> concepts = new ArrayList<ConceptCode>(2);
    concepts.add(new ConceptCode("CO-123", new BigDecimal(125), "Dialy Hospital Bed Rate", 4));
    concepts.add(new ConceptCode("CO-123", new BigDecimal(100), "Nurse Service", 1));
    BigDecimal nonInsuredAmount = this.service.calculateHospitalRates(patient.getId(), concepts);
    assertEquals(600, nonInsuredAmount.intValue());
    boolean notifyAndChargePatient = this.service.notifyAndChargePatient(patient, nonInsuredAmount, concepts);
    assertTrue(notifyAndChargePatient);
}
Also used : ConceptCode(com.salaboy.jbpm5.dev.guide.model.ConceptCode) ArrayList(java.util.ArrayList) Patient(com.salaboy.jbpm5.dev.guide.model.Patient) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Patient (com.salaboy.jbpm5.dev.guide.model.Patient)15 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 ConceptCode (com.salaboy.jbpm5.dev.guide.model.ConceptCode)5 InsuranceService (com.salaboy.jbpm5.dev.guide.webservice.InsuranceService)4 BigDecimal (java.math.BigDecimal)4 WorkflowProcessInstance (org.drools.runtime.process.WorkflowProcessInstance)4 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionResults (org.jbpm.executor.api.ExecutionResults)2 SimpleValidationServiceImpl (com.salaboy.jbpm5.dev.guide.webservice.SimpleValidationServiceImpl)1 AsyncGenericWorkItemHandler (com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler)1 MalformedURLException (java.net.MalformedURLException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 KnowledgeBase (org.drools.KnowledgeBase)1 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)1 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)1