Package org.openmrs

Examples of org.openmrs.ProgramWorkflowState


  public void handleSubmission(FormEntrySession session, HttpServletRequest submission) {
    String stateUuid = (String) widget.getValue(session.getContext(), submission);
    if (!StringUtils.isBlank(stateUuid)) {
      if (Mode.EDIT.equals(session.getContext().getMode())) {
       
        ProgramWorkflowState newState = Context.getProgramWorkflowService().getStateByUuid(stateUuid);
        PatientState oldPatientState = getActivePatientState(session.getContext().getExistingPatient(), session
                .getContext().getPreviousEncounterDate(), workflow);
       
        // 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


      String[] stateIdsUuidsOrPrefNames = stateIdsStr.split(",");
      //set to store unique work flow state combinations so as to determine multiple states in same work flow
      Set<String> workflowsAndStates = new HashSet<String>()
      for (String value : stateIdsUuidsOrPrefNames) {
        value = value.trim();
        ProgramWorkflowState state = HtmlFormEntryUtil.getState(value, program);
        if (state == null) {
          String errorMsgPart = "with an id or uuid";
          if (value.indexOf(":") > -1)
            errorMsgPart = "associated to a concept with a concept mapping";
          throw new FormEntryException("Cannot find a program work flow state " + errorMsgPart + " that matches '"
                  + value + "'");
        } else if (!state.getInitial()) {
          throw new FormEntryException("The program work flow state that matches '" + value
                  + "' is not marked as initial");
        } else if (!workflowsAndStates.add(state.getProgramWorkflow().getUuid())) {
          throw new FormEntryException("A patient cannot be in multiple states in the same workflow");
        }
        if (!states.contains(state))
          states.add(state);
      }
View Full Code Here

    final ProgramWorkflow wf = program.getWorkflow(100);
    final Date initialEnrollmentDate = new Date();
    pp.setDateEnrolled(initialEnrollmentDate);
    pp.transitionToState(wf.getState(200), initialEnrollmentDate);
    pws.savePatientProgram(pp);
    final ProgramWorkflowState originalState = pp.getCurrentState(wf).getState();
    final Integer patientProgramId = pp.getId();
    final Date completionDate = pp.getDateCompleted();
   
    //ensure the program is created
    Assert.assertEquals(1, pws.getPatientPrograms(patient, pws.getProgram(programId), null, null, null, null, false)
View Full Code Here

        results.assertEncounterCreated();
        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()));
View Full Code Here

        results.assertEncounterCreated();
        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()));
View Full Code Here

        results.assertEncounterCreated();
        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.assertEncounterCreated();
        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.assertEncounterCreated();
        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

    if (identifier == null) {
      return null;
    }
   
    // first try to fetch by id or uuid
    ProgramWorkflowState state = getState(identifier);
   
    if (state != null) {
      return state;
    }
    // if we didn't find a match, see if this is a concept mapping
View Full Code Here

    if (identifier == null) {
      return null;
    }
   
    // first try to fetch by id or uuid
    ProgramWorkflowState state = getState(identifier);
   
    if (state != null && state.getProgramWorkflow().equals(workflow)) {
      return state;
    }
   
    // if we didn't find a match, see if this is a concept mapping
    else {
View Full Code Here

TOP

Related Classes of org.openmrs.ProgramWorkflowState

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.