コード例 #1
0
  @Test
  @Verifies(
      value = "should return a list consisting of active, not retired, states",
      method = "getPossibleNextStates")
  public void getPossibleNextStates_shouldReturnNonRetiredStates() throws Exception {
    executeDataSet(PROGRAM_NEXT_STATES_XML);

    Integer patient = 11;
    Integer workflow = 501;
    Vector<ListItem> possibleNextStates;

    /* retire a workflow state  */
    PatientProgram pp = Context.getProgramWorkflowService().getPatientProgram(patient);
    ProgramWorkflow pw = pp.getProgram().getWorkflow(workflow);
    Set<ProgramWorkflowState> pwss = pw.getStates();

    for (ProgramWorkflowState pws : pwss) {
      Concept cp = pws.getConcept();
      ConceptName cn = cp.getName();
      if (cn != null) {
        String cnn = cn.getName();
        if (cnn.equalsIgnoreCase("Test State 3")) {
          pws.setRetired(true);
        }
      }
    }

    possibleNextStates = dwrProgramWorkflowService.getPossibleNextStates(patient, workflow);
    assertFalse(possibleNextStates.isEmpty());
    assertEquals(2, possibleNextStates.size());
  }
 /**
  * returns active patient program corresponding to valid programId
  *
  * @param ppList
  * @param programIds
  * @return
  */
 private PatientProgram activePatientProgram(
     List<PatientProgram> ppList, Set<Integer> programIds) {
   if (ppList != null) {
     for (PatientProgram pp : ppList) {
       if (pp.getActive() && programIds.contains(pp.getProgram().getProgramId())) return pp;
     }
   }
   return null;
 }
  @Override
  public String getOverrideContent(String str) {
    if (!Context.isAuthenticated()) {
      return "";
    }
    String gp =
        Context.getAdministrationService()
            .getGlobalProperty("htmlformflowsheet.patientChartFormIds");

    if (StringUtils.isEmpty(gp)) {
      return "";
    }

    StringBuilder sbExisting = new StringBuilder("");
    StringBuilder sbNonExisting = new StringBuilder("");
    try {
      String patientId = this.getParameterMap().get("patientId");
      Patient p = Context.getPatientService().getPatient(Integer.valueOf(patientId));

      for (StringTokenizer st = new StringTokenizer(gp, ","); st.hasMoreTokens(); ) {

        Map<Integer, Set<Integer>> progForms = new HashMap<Integer, Set<Integer>>();
        Set<Integer> programIds = new HashSet<Integer>();

        String formId = st.nextToken().trim();
        if (formId.contains(":")) {
          String[] formIdSplit = formId.split(":");
          formId = formIdSplit[0];
          // check for required programs:
          String programInfo = formIdSplit[1];
          if (programInfo.contains("|")) {
            for (StringTokenizer strTok = new StringTokenizer(programInfo, "|");
                strTok.hasMoreTokens(); ) {
              String sTmp = strTok.nextToken().trim();
              addFormToProgramList(progForms, Integer.valueOf(formId), Integer.valueOf(sTmp));
              programIds.add(Integer.valueOf(sTmp));
            }
          } else {
            // todo: support lookup programs by uuid and forms by uuid?
            addFormToProgramList(progForms, Integer.valueOf(formId), Integer.valueOf(programInfo));
            programIds.add(Integer.valueOf(programInfo));
          }
        }
        Form form = HtmlFormFlowsheetUtil.getFormFromString(formId);
        List<PatientProgram> pps =
            Context.getProgramWorkflowService()
                .getPatientPrograms(p, null, null, null, null, null, false);
        List<Encounter> encs =
            Context.getEncounterService()
                .getEncounters(
                    p, null, null, null, Collections.singletonList(form), null, null, false);

        //	            for (Map.Entry<Integer, Set<Integer>> m : progForms.entrySet()){
        //	            	System.out.println(m.getKey()+ ":" + m.getValue());
        //	            }

        // 1. no program association to form.  always show.
        if (progForms.get(Integer.valueOf(formId)) == null
            || progForms.get(Integer.valueOf(formId)).size() == 0) {
          if (encs.size() == 0) {
            // if no encs, show add new
            sbNonExisting.append(
                " | <a href=\"/"
                    + WebConstants.WEBAPP_NAME
                    + "/module/htmlformentry/htmlFormEntry.form?personId="
                    + p.getPersonId()
                    + "&patientId="
                    + p.getPatientId()
                    + "&returnUrl=&formId="
                    + form.getFormId()
                    + "\">"
                    + form.getName()
                    + "</a> | ");
          } else {
            // if encs, show existing flowsheet parent(s)
            for (Encounter e : encs) {
              sbExisting.append(
                  " | <a href=\"/"
                      + WebConstants.WEBAPP_NAME
                      + "/module/htmlformentry/htmlFormEntry.form?encounterId="
                      + e.getEncounterId()
                      + "&mode=EDIT\">"
                      + form.getName()
                      + " "
                      + "("
                      + Context.getDateFormat().format(e.getEncounterDatetime())
                      + ")</a> | ");
            }
          }
        } else {
          // 2. program(s) specified for form
          // this builds a map of encounter corresponding to the parent form creation to the
          // patientProgram is was created in.
          Map<Encounter, PatientProgram> encounterToPatientProgram =
              new HashMap<Encounter, PatientProgram>();
          for (Encounter e : encs) {
            for (PatientProgram pp : pps) {

              // if encounter is later than start date and less than end date or end date is null
              if (programIds.contains(pp.getProgram().getProgramId())
                  && e.getEncounterDatetime().getTime() >= pp.getDateEnrolled().getTime()
                  && ((pp.getDateCompleted() == null
                      || pp.getDateCompleted().getTime() >= e.getEncounterDatetime().getTime()))) {
                // encounter is in patientprogram
                encounterToPatientProgram.put(e, pp);
              }
            }
          }
          // show existing based on the map
          for (Map.Entry<Encounter, PatientProgram> m : encounterToPatientProgram.entrySet()) {
            sbExisting.append(
                " | <a href=\"/"
                    + WebConstants.WEBAPP_NAME
                    + "/module/htmlformentry/htmlFormEntry.form?encounterId="
                    + m.getKey().getEncounterId()
                    + "&mode=EDIT\">"
                    + form.getName());
            if (m.getValue() != null) {
              sbExisting.append(
                  " "
                      + "("
                      + Context.getDateFormat().format(m.getValue().getDateEnrolled())
                      + " - ");
              if (m.getValue().getDateCompleted() != null)
                sbExisting.append(Context.getDateFormat().format(m.getValue().getDateCompleted()));
              sbExisting.append(")");
            }
            sbExisting.append("</a> | ");
          }

          // show add new
          // if patient is in program currently, AND patient doesn't have an encounter for this
          // program
          PatientProgram ppActive = activePatientProgram(pps, programIds);
          boolean found = false;
          if (ppActive != null) {
            for (Map.Entry<Encounter, PatientProgram> m : encounterToPatientProgram.entrySet()) {
              if (m.getValue() != null && m.getValue().equals(ppActive)) found = true;
            }
            if (!found)
              sbNonExisting.append(
                  " | <a href=\"/"
                      + WebConstants.WEBAPP_NAME
                      + "/module/htmlformentry/htmlFormEntry.form?personId="
                      + p.getPersonId()
                      + "&patientId="
                      + p.getPatientId()
                      + "&returnUrl=&formId="
                      + form.getFormId()
                      + "\"> "
                      + form.getName()
                      + "</a> | ");
          }
        }
      }
      String retString = "<table><tr><td>";
      if (!sbExisting.toString().equals(""))
        retString += "Existing Patient Chart(s): " + sbExisting.toString();
      retString += "</td></tr><tr><td>";
      if (!sbNonExisting.toString().equals(""))
        retString += "Create A New Patient Charts: " + sbNonExisting.toString();
      retString += "</td></tr></table>";
      return retString.replace("|  |", " | ");

    } catch (Exception ex) {
      ex.printStackTrace();
      return "";
    }
  }