コード例 #1
0
 private Encounter buildEncounter(
     EncounterType encounterType,
     Patient patient,
     Location location,
     Form form,
     Date when,
     List<Obs> obsToCreate,
     List<Order> ordersToCreate) {
   Encounter encounter = new Encounter();
   encounter.setPatient(patient);
   encounter.setEncounterType(encounterType);
   encounter.setLocation(location);
   encounter.setForm(form);
   encounter.setEncounterDatetime(when);
   if (obsToCreate != null) {
     for (Obs obs : obsToCreate) {
       obs.setObsDatetime(new Date());
       encounter.addObs(obs);
     }
   }
   if (ordersToCreate != null) {
     for (Order order : ordersToCreate) {
       encounter.addOrder(order);
     }
   }
   return encounter;
 }
コード例 #2
0
  /**
   * @see
   *     org.openmrs.module.htmlformentry.element.HtmlGeneratorElement#generateHtml(org.openmrs.module.htmlformentry.FormEntryContext)
   */
  @Override
  public String generateHtml(FormEntryContext context) {
    if (context.getExistingPatient() == null) {
      return "";
    }

    KenyaUiUtils kenyaui = Context.getRegisteredComponents(KenyaUiUtils.class).get(0);

    PatientWrapper patient = new PatientWrapper(context.getExistingPatient());

    Obs obs = patient.lastObs(MetadataUtils.getConcept(conceptId));

    StringBuilder sb = new StringBuilder("<span>");

    if (obs != null) {
      sb.append(kenyaui.formatObsValue(obs));

      if (showDate) {
        sb.append(" <small>(" + kenyaui.formatDate(obs.getObsDatetime()) + ")</small>");
      }
    } else if (noneMessage != null) {
      sb.append(noneMessage);
    }

    sb.append("</span>");
    return sb.toString();
  }
コード例 #3
0
  private int calculateDecline(List<Obs> obs) {
    Obs lastOb = null;
    Obs nextToLastOb = null;

    if (obs.size() > 0) {
      lastOb = obs.get(obs.size() - 1);
    }

    if (obs.size() > 1) {
      nextToLastOb = obs.get(obs.size() - 2);
    }

    if (lastOb != null && nextToLastOb != null) {
      Double firstVal = lastOb.getValueNumeric();
      Double nextToLastVal = nextToLastOb.getValueNumeric();

      if (firstVal != null && nextToLastVal != null) {
        double decline = nextToLastVal - firstVal;

        return (int) decline;
      }
    }

    return -1;
  }
コード例 #4
0
  /** @see Encounter#getObsAtTopLevel(null) */
  @Test
  @Verifies(
      value = "should get both child and parent obs after removing child from parent grouping",
      method = "getObsAtTopLevel(null)")
  public void getObsAtTopLevel_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping()
      throws Exception {
    Encounter enc = new Encounter();

    // create and add an Obs
    Obs parentObs = new Obs();
    enc.addObs(parentObs);

    // add a child to the obs and make sure that now that the Obs is an ObsGroup with one child:
    Obs childObs = new Obs();
    parentObs.addGroupMember(childObs);

    // add the child obs directly to the encounter as well
    childObs.setEncounter(enc);
    enc.addObs(childObs);

    // remove the obsGrouping, so that both obs are now just children of the Encounter
    parentObs.removeGroupMember(childObs);

    assertEquals(2, enc.getObsAtTopLevel(false).size());
  }
  public void saveAndTransferFileComplexObs() {

    try {
      List<Encounter> encounters =
          Context.getEncounterService().getEncounters(null, null, null, null, null, null, true);
      Encounter lastEncounter = encounters.get(encounters.size() - 1);

      Person patient = lastEncounter.getPatient();
      ConceptComplex conceptComplex = Context.getConceptService().getConceptComplex(17);
      Location location = Context.getLocationService().getDefaultLocation();
      Obs obs = new Obs(patient, conceptComplex, new Date(), location);

      String mergedUrl = tempFile.getCanonicalPath();
      InputStream out1 = new FileInputStream(new File(mergedUrl));

      ComplexData complexData = new ComplexData(tempFile.getName(), out1);
      obs.setComplexData(complexData);
      obs.setEncounter(lastEncounter);

      Context.getObsService().saveObs(obs, null);
      tempFile.delete();

    } catch (Exception e) {
      log.error(e);
    }
  }
コード例 #6
0
 public void printEncounterCreated() {
   if (encounterCreated == null) {
     System.out.println("No encounter created");
   } else {
     System.out.println("=== Encounter created ===");
     System.out.println(
         "Created: "
             + encounterCreated.getDateCreated()
             + "  Edited: "
             + encounterCreated.getDateChanged());
     System.out.println("Date: " + encounterCreated.getEncounterDatetime());
     System.out.println("Location: " + encounterCreated.getLocation().getName());
     System.out.println("Provider: " + encounterCreated.getProvider().getPersonName());
     System.out.println("    (obs)");
     Collection<Obs> obs = encounterCreated.getAllObs(false);
     if (obs == null) {
       System.out.println("None");
     } else {
       for (Obs o : obs) {
         System.out.println(
             o.getConcept().getName() + " -> " + o.getValueAsString(Context.getLocale()));
       }
     }
   }
 }
コード例 #7
0
  /** @see org.openmrs.api.EncounterService#unvoidEncounter(org.openmrs.Encounter) */
  public Encounter unvoidEncounter(Encounter encounter) throws APIException {

    // if authenticated user is not supposed to edit encounter of certain type
    if (!canEditEncounter(encounter, null)) {
      throw new APIException(
          "Encounter.error.privilege.required.unvoid",
          new Object[] {encounter.getEncounterType().getEditPrivilege()});
    }

    String voidReason = encounter.getVoidReason();
    if (voidReason == null) {
      voidReason = "";
    }

    ObsService os = Context.getObsService();
    for (Obs o : encounter.getObsAtTopLevel(true)) {
      if (voidReason.equals(o.getVoidReason())) {
        os.unvoidObs(o);
      }
    }

    OrderService orderService = Context.getOrderService();
    for (Order o : encounter.getOrders()) {
      if (voidReason.equals(o.getVoidReason())) {
        orderService.unvoidOrder(o);
      }
    }

    encounter.setVoided(false);
    encounter.setVoidedBy(null);
    encounter.setDateVoided(null);
    encounter.setVoidReason(null);
    Context.getEncounterService().saveEncounter(encounter);
    return encounter;
  }
コード例 #8
0
  /**
   * Calculates the postpartum end date as 6 months past the delivery date.
   *
   * <p>NOTE: In the absence of a delivery date, the EDC is used.
   *
   * @return The end date of the postpartum stage
   */
  public Date getPostpartumStageEndDate() {
    Date deliveryDate = null;
    if (Functions.observation(mcProgramObs.getObs(), MCDeliveryReportConcepts.DELIVERY_REPORT)
        != null) {
      final Obs deliveryDateObs =
          mcProgramObs.getDeliveryReport().getMember(MCDeliveryReportConcepts.DELIVERY_DATE);
      if (deliveryDateObs != null) {
        deliveryDate = deliveryDateObs.getValueDatetime();
      }
    }

    if (deliveryDate == null) {
      // use EDC
      deliveryDate = mcProgramObs.getEstimatedDateOfConfinement();
    }

    if (deliveryDate != null) {
      final Calendar sixMonthsAfterDeliveryDate = Calendar.getInstance();
      sixMonthsAfterDeliveryDate.setTime(DateUtil.stripTime(deliveryDate));
      sixMonthsAfterDeliveryDate.add(Calendar.MONTH, 6);

      // return the calculated postpartum stage end date
      return sixMonthsAfterDeliveryDate.getTime();
    }

    // postpartum stage end date is not available
    return null;
  }
コード例 #9
0
  private int calculatePercentageDecline(List<Obs> obs) {
    Obs lastOb = null;
    Obs nextToLastOb = null;

    if (obs.size() > 0) {
      lastOb = obs.get(obs.size() - 1);
    }

    if (obs.size() > 1) {
      nextToLastOb = obs.get(obs.size() - 2);
    }

    if (lastOb != null && nextToLastOb != null) {
      Double firstVal = lastOb.getValueNumeric();
      Double nextToLastVal = nextToLastOb.getValueNumeric();

      if (firstVal != null && nextToLastVal != null) {
        double decline = 100 - ((firstVal / nextToLastVal) * 100);

        if (decline > 0) {
          return (int) decline;
        }
      }
    }

    return 0;
  }
  /**
   * @see RadiologyObsFormController#unvoidObs(HttpServletRequest, HttpServletResponse, Obs, String)
   */
  @Test
  @Verifies(
      value = "should unvoid voided obs for given request, response and obs",
      method = "unvoidObs(HttpServletRequest, HttpServletResponse, Obs, String)")
  public void unvoidObs_shouldUnvoidVoidedObsForGivenRequestResponseAndObs() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("unvoidObs", "unvoidObs");
    mockRequest.setSession(mockSession);
    when(obsErrors.hasErrors()).thenReturn(false);

    mockObs.setVoided(true);

    ModelAndView modelAndView = radiologyObsFormController.unvoidObs(mockRequest, null, mockObs);
    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
    assertThat(
        (String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
        is("Obs.unvoidedSuccessfully"));
  }
  /**
   * @see RadiologyObsFormController#saveObs(HttpServletRequest, HttpServletResponse, String,
   *     RadiologyOrder, Obs Obs, BindingResult)
   */
  @Test
  @Verifies(
      value = "should edit obs with edit reason and complex concept",
      method =
          "saveObs(HttpServletRequest, HttpServletResponse, String, RadiologyOrder, Obs Obs, BindingResult)")
  public void saveObs_ShouldEditObsWithEditReasonAndComplexConcept() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("saveObs", "saveObs");
    mockRequest.setSession(mockSession);

    when(obsErrors.hasErrors()).thenReturn(false);
    ConceptComplex concept = new ConceptComplex();
    ConceptDatatype cdt = new ConceptDatatype();
    cdt.setHl7Abbreviation("ED");
    concept.setDatatype(cdt);
    mockObs.setConcept(concept);

    ModelAndView modelAndView =
        radiologyObsFormController.saveObs(
            mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors);

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Obs.saved"));
    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
  }
コード例 #12
0
  private Obs getObsGroup() {
    ConceptDatatype datatype = new ConceptDatatype();
    datatype.setUuid(ConceptDatatype.CODED_UUID);
    datatype.setHl7Abbreviation(ConceptDatatype.CODED);

    Concept concept = new Concept(1);
    concept.setDatatype(datatype);
    concept.addName(new ConceptName("MedSet", Locale.ENGLISH));

    ConceptSource source = new ConceptSource();
    source.setName("LOCAL");

    ConceptMap map = new ConceptMap();
    map.setSourceCode("100");
    map.setSource(source);

    concept.addConceptMapping(map);

    Date dateCreated = new Date(213231421890234L);

    Obs obs = new Obs(1);
    obs.setConcept(concept);
    obs.setDateCreated(dateCreated);

    return obs;
  }
コード例 #13
0
 private ArrayList<String> getValuCodedNames(Set<Obs> diagnosisObservationGroupMembers) {
   ArrayList<String> valueCodedNames = new ArrayList<String>();
   for (Obs diagnosisObservationGroupMember : diagnosisObservationGroupMembers) {
     valueCodedNames.add(diagnosisObservationGroupMember.getValueCoded().getName().getName());
   }
   return valueCodedNames;
 }
  @Test
  public void shouldCreateNewObservationWithNamespace() throws ParseException {
    initMocks(this);
    obsMapper1_12 = new ObsMapper1_12(conceptService, emrApiProperties, obsService, orderService);
    EncounterObservationServiceHelper encounterObservationServiceHelper =
        new EncounterObservationServiceHelper(
            conceptService, emrApiProperties, obsService, orderService, obsMapper1_12);

    newConcept(new ConceptDataTypeBuilder().text(), TEXT_CONCEPT_UUID);
    List<EncounterTransaction.Observation> observations =
        asList(
            new EncounterTransaction.Observation()
                .setConcept(getConcept(TEXT_CONCEPT_UUID))
                .setValue("text value")
                .setComment("overweight")
                .setFormNamespace("formNamespace")
                .setFormFieldPath("formFieldPath"));

    Date encounterDateTime =
        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse("2005-01-01T00:00:00.000+0000");
    Patient patient = new Patient();

    Encounter encounter = new Encounter();
    encounter.setUuid("e-uuid");
    encounter.setPatient(patient);
    encounter.setEncounterDatetime(encounterDateTime);

    encounterObservationServiceHelper.update(encounter, observations);

    assertEquals(1, encounter.getObs().size());
    Obs textObservation = encounter.getObs().iterator().next();
    assertEquals("formNamespace", textObservation.getFormFieldNamespace());
    assertEquals("formFieldPath", textObservation.getFormFieldPath());
  }
コード例 #15
0
  /** @see Encounter#addObs(Obs) */
  @Test
  @Verifies(
      value = "should add encounter attrs to obs if attributes are null",
      method = "addObs(Obs)")
  public void addObs_shouldAddEncounterAttrsToObsIfAttributesAreNull() throws Exception {
    /// an encounter that will hav the date/location/patient on it
    Encounter encounter = new Encounter();

    Date date = new Date();
    encounter.setEncounterDatetime(date);

    Location location = new Location(1);
    encounter.setLocation(location);

    Patient patient = new Patient(1);
    encounter.setPatient(patient);

    // add an obs that doesn't have date/location/patient set on it.
    Obs obs = new Obs(123);
    encounter.addObs(obs);

    // make sure it was added
    assertEquals(1, encounter.getAllObs(true).size());

    // check the values of the obs attrs to see if they were added
    assertTrue(obs.getObsDatetime().equals(date));
    assertTrue(obs.getLocation().equals(location));
    assertTrue(obs.getPerson().equals(patient));
  }
コード例 #16
0
 /** @see Encounter#addObs(Obs) */
 @Test
 @Verifies(value = "should set encounter attribute on obs", method = "addObs(Obs)")
 public void addObs_shouldSetEncounterAttributeOnObs() throws Exception {
   Encounter encounter = new Encounter();
   Obs obs = new Obs();
   encounter.addObs(obs);
   assertTrue(obs.getEncounter().equals(encounter));
 }
コード例 #17
0
    public boolean matches(Obs obs) {

      if (!obs.getConcept().getConceptId().equals(conceptId)) {
        return false;
      }

      return OpenmrsUtil.nullSafeEquals(
          TestUtil.valueAsStringHelper(value), obs.getValueAsString(Context.getLocale()));
    }
  private Obs doNotGoToServiceToFormatMembers(Obs obsGroup) {
    Set<Obs> replacements = new HashSet<Obs>();
    for (Obs member : obsGroup.getGroupMembers()) {
      replacements.add(new DoNotGoToServiceWhenFormatting(member));
    }

    obsGroup.setGroupMembers(replacements);
    return obsGroup;
  }
コード例 #19
0
 private List<Obs> getSavedDocuments(Set<Obs> allObs, String conceptUuid) {
   List<Obs> obsList = new ArrayList<>();
   for (Obs obs : allObs) {
     if (obs.getConcept().getUuid().equals(conceptUuid)) {
       obsList.add(obs);
     }
   }
   Collections.sort(obsList, new IdBasedComparator());
   return obsList;
 }
コード例 #20
0
 void updateDiagnosisStatus(
     Obs diagnosisObs, BahmniDiagnosis bahmniDiagnosis, Concept bahmniDiagnosisStatusConcept) {
   Obs obs = findOrCreateObs(diagnosisObs, bahmniDiagnosisStatusConcept);
   if (bahmniDiagnosis.getDiagnosisStatusConcept() != null) {
     Concept statusConcept =
         conceptService.getConcept(bahmniDiagnosis.getDiagnosisStatusConcept().getName());
     obs.setValueCoded(statusConcept);
     addToObsGroup(diagnosisObs, obs);
   }
 }
 @Override
 public String getValueAsString(Locale locale) {
   if (obs.getValueCoded() != null) {
     return obs.getValueCoded().getNames(false).iterator().next().getName();
   } else if (obs.getValueDate() != null) {
     return new SimpleDateFormat("dd MMM yyyy hh:mm a", locale).format(obs.getValueDate());
   } else {
     return obs.getValueAsString(locale);
   }
 }
コード例 #22
0
 private Obs findOrCreateObs(Obs diagnosisObs, Concept concept) {
   for (Obs o : diagnosisObs.getGroupMembers()) {
     if (concept.equals(o.getConcept())) {
       return o;
     }
   }
   Obs obs = new Obs();
   obs.setConcept(concept);
   return obs;
 }
  /**
   * Get new obs corresponding to given radiologyOrder
   *
   * @param radiologyOrder radiology order for which the obs should be returned
   * @return model and view populated with a new obs
   * @should populate model and view with new obs given a valid radiology order
   */
  @RequestMapping(value = "/module/radiology/radiologyObs.form", method = RequestMethod.GET)
  protected ModelAndView getNewObs(
      @RequestParam(value = "orderId", required = true) RadiologyOrder radiologyOrder) {

    Obs obs = new Obs();
    obs.setOrder(radiologyOrder);
    obs.setPerson(radiologyOrder.getPatient());
    obs.setEncounter(radiologyOrder.getEncounter());
    return populateModelAndView(radiologyOrder, obs);
  }
コード例 #24
0
 /** @return the number of obs groups in encounterCreated (0 if no encounter was created) */
 public int getObsGroupCreatedCount() {
   if (encounterCreated == null) return 0;
   Collection<Obs> temp = encounterCreated.getAllObs();
   if (temp == null) return 0;
   int count = 0;
   for (Obs o : temp) {
     if (o.isObsGrouping()) ++count;
   }
   return count;
 }
コード例 #25
0
  public QueueItem saveQueueItem(QueueItem queueItem) {
    log.debug("saveQueueItem(). Entering");
    boolean isNew = false;
    Date newDate = queueItem.getEncounter().getEncounterDatetime();
    log.debug("Encounter date: " + newDate);
    Date originalDate = null;

    if (queueItem.getQueueItemId() == null) {
      isNew = true;
      log.debug("Got a  new queue item");
    }

    // Not new we update some of the Encounter info
    if (!isNew) {
      log.info("Updating previously queued encounter!");
      Encounter encounter = queueItem.getEncounter();
      Patient p = encounter.getPatient();
      originalDate = encounter.getEncounterDatetime();
      if (OpenmrsUtil.compare(originalDate, newDate) != 0) {

        // if the obs datetime is the same as the
        // original encounter datetime, fix it
        if (OpenmrsUtil.compare(queueItem.getDateCreated(), originalDate) == 0) {
          encounter.setEncounterDatetime(newDate);
        }
      }

      // if the Person in the encounter doesn't match the Patient in the ,
      // fix it
      if (!encounter.getPatient().getPersonId().equals(p.getPatientId())) {
        encounter.setPatient(p);
      }

      for (Obs obs : encounter.getAllObs(true)) {
        // if the date was changed
        if (OpenmrsUtil.compare(originalDate, newDate) != 0) {

          // if the obs datetime is the same as the
          // original encounter datetime, fix it
          if (OpenmrsUtil.compare(obs.getObsDatetime(), originalDate) == 0) {
            obs.setObsDatetime(newDate);
          }
        }

        // if the Person in the obs doesn't match the Patient in the
        // encounter, fix it
        if (!obs.getPerson().getPersonId().equals(p.getPatientId())) {
          obs.setPerson(p);
        }
      }
    }
    log.debug("Saving queu item.");
    dao.saveQueueItem(queueItem);
    return queueItem;
  }
コード例 #26
0
 private void addToObsGroup(Obs obsGroup, Obs member) {
   member.setPerson(obsGroup.getPerson());
   member.setObsDatetime(obsGroup.getObsDatetime());
   member.setLocation(obsGroup.getLocation());
   member.setEncounter(obsGroup.getEncounter());
   obsGroup.addGroupMember(member);
 }
コード例 #27
0
  @Test
  @Verifies(
      value = "should return encounter with all child objects voided according to schema",
      method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderCorrectly() throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 1, 5000, date); // a matching obs

    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setStartDate(new Date());
    e.addOrder(dor);

    Context.getEncounterService().saveEncounter(e);

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));

    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, "test void reason");

    // this is going to test out the voided state of the obs in the encounter after processing:
    // order was matched, so order was voided, and because that's the only thing in the encounter,
    // encounter was voided too.
    Assert.assertTrue(e.isVoided());
    Assert.assertTrue(e.getVoidReason().equals("test void reason"));
    for (Order o : e.getOrders()) {
      Assert.assertTrue(o.isVoided());
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
    for (Obs o : e.getAllObs(true)) {
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
  }
  /**
   * @see org.openmrs.calculation.patient.PatientCalculation#evaluate(java.util.Collection,
   *     java.util.Map, org.openmrs.calculation.patient.PatientCalculationContext)
   */
  @Override
  public CalculationResultMap evaluate(
      Collection<Integer> cohort,
      Map<String, Object> parameterValues,
      PatientCalculationContext context) {

    Program mchcsProgram = MetadataUtils.getProgram(MchMetadata._Program.MCHCS);

    // Get all patients who are alive and in MCH-CS program
    Set<Integer> alive = Filters.alive(cohort, context);
    Set<Integer> inMchcsProgram = Filters.inProgram(mchcsProgram, alive, context);

    // get wheather the child is HIV Exposed
    CalculationResultMap lastChildHivStatus =
        Calculations.lastObs(
            Dictionary.getConcept(Dictionary.CHILDS_CURRENT_HIV_STATUS), inMchcsProgram, context);
    CalculationResultMap medOrdersObss =
        Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), cohort, context);

    // Get concepts for  medication prophylaxis
    Concept nvp = Dictionary.getConcept(Dictionary.NEVIRAPINE);
    Concept nvpazt3tc = Dictionary.getConcept(Dictionary.LAMIVUDINE_NEVIRAPINE_ZIDOVUDINE);
    Concept hivExposed = Dictionary.getConcept(Dictionary.EXPOSURE_TO_HIV);

    CalculationResultMap ret = new CalculationResultMap();

    for (Integer ptId : cohort) {
      boolean notOnPcp = false;

      // checking wheather the infant is in mchcs program, alive and HEI
      Obs hivStatusObs = EmrCalculationUtils.obsResultForPatient(lastChildHivStatus, ptId);
      if (inMchcsProgram.contains(ptId)
          && lastChildHivStatus != null
          && hivStatusObs != null
          && (hivStatusObs.getValueCoded().equals(hivExposed))) {
        notOnPcp = true;
        ListResult patientMedOrders = (ListResult) medOrdersObss.get(ptId);
        if (patientMedOrders != null) {
          // Look through list of medication order obs for any  CTX
          List<Obs> medOrderObsList = CalculationUtils.extractResultValues(patientMedOrders);
          for (Obs medOrderObs : medOrderObsList) {
            if (medOrderObs.getValueCoded().equals(nvp)
                || medOrderObs.getValueCoded().equals(nvpazt3tc)) {
              notOnPcp = false;
              break;
            }
          }
        }
      }
      ret.put(ptId, new BooleanResult(notOnPcp, this, context));
    }

    return ret;
  }
コード例 #29
0
  @Test
  @Verifies(value = "should delete encounter correctly", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldDeleteEncounter() throws Exception {
    executeDataSet(
        XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 3, 5000, date); // adding an un-matched, voided Obs
    for (Obs o : e.getAllObs(true)) {
      o.setVoided(true);
      o.setVoidedBy(Context.getUserService().getUser(1));
      o.setVoidReason("blah");
      o.setDateVoided(new Date());
    }

    // and adding a voided drug order
    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setVoided(true);
    dor.setVoidedBy(Context.getUserService().getUser(1));
    dor.setVoidReason("blah");
    dor.setDateVoided(new Date());
    dor.setStartDate(new Date());
    e.addOrder(dor);

    Context.getEncounterService().saveEncounter(e);

    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(
        new TestUtil()
            .loadXmlFromFile(
                XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));

    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);

    // encounter had no non-voided objects, should be voided
    Assert.assertTrue(e.isVoided());
  }
コード例 #30
0
 static Obs orderUuidToObs(
     String orderUuid, Patient patient, Date encounterTime, Location location) {
   Order order = Context.getOrderService().getOrderByUuid(orderUuid);
   if (order == null) {
     log.warn("Order not found: " + orderUuid);
     return null;
   }
   Obs obs = new Obs(patient, DbUtil.getOrderExecutedConcept(), encounterTime, location);
   obs.setOrder(order);
   obs.setValueNumeric(1d);
   return obs;
 }