Package org.openmrs

Examples of org.openmrs.PatientProgram


       
        // but confirm that the patient was in the program in the past
        Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date()))
       
        // confirm that the proper program has been closed
        PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("32296060-03aa-102d-b0e3-001ec94a0cc5");
        Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted()));
      };

    }.run();
  }
View Full Code Here


       
        // but confirm that the patient was in the program in the past
        Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date()))
       
        // confirm that the proper program has been closed
        PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("32296060-03aa-102d-b0e3-001ec94a0cc5");
        Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted()));
      };
     

    }.run();
  }
View Full Code Here

   * @param encounterDatetime
   * @param workflow
   * @return
   */
  private PatientState getActivePatientState(Patient patient, Date encounterDatetime, ProgramWorkflow workflow) {
    PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByWorkflow(patient, workflow);
    if (patientProgram != null) {
      for (PatientState patientState : patientProgram.statesInWorkflow(workflow,false)) {
        if (patientState.getActive(encounterDatetime)) {
          return patientState;
        }
      }
    }
View Full Code Here

        // if no old state, simply transition to this new state
        if (oldPatientState == null) {

                    // if there is an active program enrollment in this program, add it to the programs to update (so that
                    // it is picked up by the FormSubmissionAction.transitionToState method and a new program is not created)
                    PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByProgramOnDate(session.getPatient(),
                            newState.getProgramWorkflow().getProgram(), session.getEncounter().getEncounterDatetime());

                    if (patientProgram != null) {
                        session.getSubmissionActions().getPatientProgramsToUpdate().add(patientProgram);
                    }

          session.getSubmissionActions().transitionToState(newState);
        }
        else {
          PatientProgram patientProgram = oldPatientState.getPatientProgram();
          Date previousEncounterDate = session.getContext().getPreviousEncounterDate();
          Date newEncounterDate = session.getEncounter().getEncounterDatetime();
         
          // if the encounter date has been moved earlier
          if (previousEncounterDate != null  && newEncounterDate.before(previousEncounterDate)) {
           
            // if there is an existing patient state on the new encounter date and it differs from the state on the old encounter date
            // we need to end it
            PatientState existingPatientStateOnNewEncounterDate = getActivePatientState(session.getContext().getExistingPatient(), newEncounterDate, workflow);
            if (existingPatientStateOnNewEncounterDate != null &&  !existingPatientStateOnNewEncounterDate.equals(oldPatientState)) {
              existingPatientStateOnNewEncounterDate.setEndDate(newEncounterDate);
            }
           
            // we also need to void any other states for this workflow that may have started between the new and old encounter dates
            for (PatientState state : patientProgram.statesInWorkflow(workflow, false)) {
              if (!state.equals(oldPatientState) && (state.getStartDate().after(newEncounterDate) || state.getStartDate().compareTo(newEncounterDate) == 0)
                  && state.getStartDate().before(previousEncounterDate)) {
                state.setVoided(true);
                state.setVoidedBy(Context.getAuthenticatedUser());
                state.setVoidReason("voided during htmlformentry submission");
              }
            }
          }
         
          // if the encounter date has been moved later
          if (previousEncounterDate != null && newEncounterDate.after(previousEncounterDate)) {
            // make sure we aren't trying to move the state start date past its end date
            if (oldPatientState.getEndDate() != null && newEncounterDate.after(oldPatientState.getEndDate())) {
              throw new FormEntryException("Cannot move encounter date ahead of end date of current active state");
            }
           
            // if there is a state that ended on the previous encounter date, its end date needs to be set to the new encounter date
            for (PatientState state : patientProgram.statesInWorkflow(workflow, false)) {
              if (!state.equals(oldPatientState) && state.getEndDate().compareTo(previousEncounterDate) == 0) {
                state.setEndDate(newEncounterDate);
              }
            }
          }
         
          // change the state if necessary
          if (!newState.equals(oldPatientState.getState())) {
            oldPatientState.setState(newState);
          }
         
          // update the state start date
          oldPatientState.setStartDate(newEncounterDate);
         
          // roll the program enrollment date earlier if necessary
          if (oldPatientState.getPatientProgram().getDateEnrolled().after(oldPatientState.getStartDate())) {
            oldPatientState.getPatientProgram().setDateEnrolled(oldPatientState.getStartDate());
          }
         
          session.getSubmissionActions().getPatientProgramsToUpdate().add(oldPatientState.getPatientProgram());
        }
      } else {   // handle ENTER state
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(stateUuid);

                // if there is an active program enrollment in the state, add it to the programs to update (so that
                // it is picked up by the FormSubmissionAction.transitionToState method and a new program is not created)
                PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByProgramOnDate(session.getPatient(),
                        state.getProgramWorkflow().getProgram(), session.getEncounter().getEncounterDatetime());

                if (patientProgram != null) {
                    session.getSubmissionActions().getPatientProgramsToUpdate().add(patientProgram);
                }
View Full Code Here

        // 2. if the patient is enrolled *after* the given date, shift the existing enrollment to start earlier. (TODO decide if this is right)
        // 3. otherwise just enroll them as requested
        if (submissionActions.getPatientProgramsToCreate() != null) {
            for (PatientProgram toCreate : submissionActions.getPatientProgramsToCreate()) {
                boolean skip = false;
                PatientProgram earliestAfter = null;
                List<PatientProgram> already = Context.getProgramWorkflowService().getPatientPrograms(toCreate.getPatient(),
                        toCreate.getProgram(), null, null, null, null, false);
                for (PatientProgram pp : already) {
                    if (pp.getActive(toCreate.getDateEnrolled())) {
                        skip = true;
                        break;
                    }
                    // if the existing one starts after toCreate
                    if (OpenmrsUtil.compare(pp.getDateEnrolled(), toCreate.getDateEnrolled()) > 0) {
                        if (earliestAfter == null
                                || OpenmrsUtil.compare(pp.getDateEnrolled(), earliestAfter.getDateEnrolled()) < 0) {
                            earliestAfter = pp;
                        }
                    }
                }
                if (skip) {
                    continue;
                }
                if (earliestAfter != null) {
                    // edit this enrollment to move its start date earlier
                    earliestAfter.setDateEnrolled(toCreate.getDateEnrolled());
                    Context.getProgramWorkflowService().savePatientProgram(earliestAfter);
                } else {
                    // just enroll as requested
                    Context.getProgramWorkflowService().savePatientProgram(toCreate);
                }
View Full Code Here

        results.assertProvider(502);
        results.assertLocation(2);
       
        //Then: Workflow state Y is created with a start date of the encounter date
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(START_STATE);
        PatientProgram patientProgram = getPatientProgramByState(results.getPatient(), state, DATE);
        PatientState patientState = getPatientState(patientProgram, state, DATE);
       
        Assert.assertNotNull(patientProgram);
        Assert.assertEquals(dateAsString(DATE), dateAsString(patientState.getStartDate()));
        Assert.assertEquals(dateAsString(DATE), dateAsString(patientProgram.getDateEnrolled()));
      }
    }.run();
  }
View Full Code Here

        results.assertProvider(502);
        results.assertLocation(2);
       
        //Then: Workflow state Y is created with a start date of June 2011 and a stop date of Jan 2012. Workflow state X stays as is.
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(MIDDLE_STATE);
        PatientProgram patientProgram = getPatientProgramByState(results.getPatient(), state, PAST_DATE);
        PatientState patientState = getPatientState(patientProgram, state, PAST_DATE);
       
        Assert.assertNotNull(patientProgram);
        Assert.assertEquals(dateAsString(PAST_DATE), dateAsString(patientState.getStartDate()));
        Assert.assertEquals(dateAsString(DATE), dateAsString(patientState.getEndDate()));
View Full Code Here

        results.assertProvider(502);
        results.assertLocation(2);
       
        //Then: Workflow state X is stopped with a stop date of Jan 2012, Workflow state Y is created with a start date of Jan 2012 and is still current
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(START_STATE);
        PatientProgram patientProgram = getPatientProgramByState(results.getPatient(), state, PAST_DATE);
        PatientState patientState = getPatientState(patientProgram, state, PAST_DATE);
       
        Assert.assertNotNull(patientProgram);
        Assert.assertEquals(dateAsString(DATE), dateAsString(patientState.getEndDate()));
       
View Full Code Here

        results.assertProvider(502);
        results.assertLocation(2);
       
        //Then: No change to workflow state
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(START_STATE);
        PatientProgram patientProgram = getPatientProgramByState(results.getPatient(), state, PAST_DATE);
        PatientState patientState = getPatientState(patientProgram, state, PAST_DATE);
       
        Assert.assertNotNull(patientProgram);
        Assert.assertEquals(dateAsString(PAST_DATE), dateAsString(patientState.getStartDate()));
      }
View Full Code Here

        results.assertProvider(502);
        results.assertLocation(2);
       
        //Then: A new workflow state X is created with a Start date of June 2011 and a stop date of Jan 2012
        ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(START_STATE);
        PatientProgram patientProgram = getPatientProgramByState(results.getPatient(), state, PAST_DATE);
        PatientState patientState = getPatientState(patientProgram, state, PAST_DATE);
        Assert.assertNotNull(patientProgram);
        Assert.assertEquals(dateAsString(PAST_DATE), dateAsString(patientState.getStartDate()));
        Assert.assertEquals(dateAsString(DATE), dateAsString(patientState.getEndDate()));
       
View Full Code Here

TOP

Related Classes of org.openmrs.PatientProgram

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.