Package org.openmrs

Examples of org.openmrs.DrugOrder


      for (RegimenSuggestion rs :  regimenCandidates){
        List<DrugOrder> matchHolder = new ArrayList<DrugOrder>(); //collects drug matches between encounter and RegimenSuggestion
        boolean allFound = true; //true until a DrugSuggestion from the RegimenSuggestion isn't matched.
        Date startDate = null//if all DrugSuggestions are matched but have different start dates, we can't match.
        for (DrugSuggestion dc : rs.getDrugComponents()){
          DrugOrder dorToInspect = drugIdFoundInDrugSet(dc, drugOrders); //assumes patient will never have multiple drug orders of same drug in same encounter...
          if (dorToInspect != null){ // there was a match by drug
            if (startDate == null) // setup standard regimen start date
              startDate = dorToInspect.getDateActivated();
            if (startDate.equals(dorToInspect.getDateActivated())) //this will always be true for first drug matched.
              matchHolder.add(drugIdFoundInDrugSet(dc, drugOrders));
            else {
              //the drug was matched on drug type, but the start date was different.  This tag assumes equal start and stop dates to be a standard regimen.
              allFound = false;
              break;
View Full Code Here


   *
   */
  private static DrugOrder drugIdFoundInDrugSet(DrugSuggestion ds, List<Order> dors){
    for (Order or : dors){
      if (or instanceof DrugOrder){
        DrugOrder dor = (DrugOrder) or;
        if (dor.getDrug() != null && !dor.isVoided() && (dor.getDrug().getDrugId().toString().equals(ds.getDrugId()) || dor.getDrug().getUuid().toString().equals(ds.getDrugId())))
          return dor;
      }
    }
    return null;
  }
View Full Code Here

    Set<Order> ret = new HashSet<Order>();
    if (rs != null){
      OrderService orderService = Context.getOrderService();
      ConceptService conceptService = Context.getConceptService();
      for (DrugSuggestion ds : rs.getDrugComponents()){
        DrugOrder dor = new DrugOrder();
        Drug drug = Context.getConceptService().getDrugByNameOrId(ds.getDrugId());
        if (drug == null)
          drug = Context.getConceptService().getDrugByUuid(ds.getDrugId());
        if (drug == null)
          throw new RuntimeException("Your standard regimen xml file constains a drugId that can't be found, for regimen " + rs.getCodeName() + ", DrugComponent.id = " + ds.getDrugId());
        dor.setDrug(drug);
       
        OrderFrequency frequency = findFrequency(orderService, ds.getFrequency());
        dor.setFrequency(frequency);
        dor.setInstructions(ds.getInstructions());
        dor.setDose(Double.valueOf(ds.getDose()));
        dor.setDoseUnits(conceptService.getConceptByName(ds.getUnits()));
        dor.setRoute(Context.getConceptService().getConceptByName("UNKNOWN"));
        dor.setDateActivated(startDate);
        dor.setPatient(patient);
        dor.setDateChanged(new Date());
        dor.setCreator(Context.getAuthenticatedUser());
        dor.setOrderType(Context.getOrderService().getOrderTypeByUuid(DrugOrderSubmissionElement1_10.DRUG_ORDER_TYPE_UUID));
        ret.add(dor);
      }
    } 
    return ret;
  }
View Full Code Here

    // populate values drug order from database (VIEW, EDIT)
    if (context.getMode() != Mode.ENTER && context.getExistingOrders() != null) {
      for (Drug drug : drugsUsedAsKey) {
        if (context.getExistingOrders().containsKey(drug.getConcept())) {
          //this will return null if Order is not a DrugOrder even if matched by Concept
          DrugOrder drugOrder = (DrugOrder) context.removeExistingDrugOrder(drug);
         
          if (drugOrder != null) {
            //start from the first order for that drug
            while (drugOrder.getPreviousOrder() != null) {
              drugOrder = (DrugOrder) drugOrder.getPreviousOrder();
            }
           
            //get the latest revision or discontinuation order
            DrugOrder lastRevision = drugOrder;
            while (true) {
              DrugOrder revisedOrder = (DrugOrder) Context.getOrderService().getRevisionOrder(drugOrder);
              if (revisedOrder != null) {
                drugOrder = revisedOrder;
                lastRevision = revisedOrder;
                continue;
              }
              DrugOrder discontinuationOrder = (DrugOrder) Context.getOrderService().getDiscontinuationOrder(
                  drugOrder);
              if (discontinuationOrder != null) {
                drugOrder = discontinuationOrder;
                continue;
              }
             
              break;
            }
           
            existingOrder = drugOrder;
            if (drugWidget instanceof DropdownWidget) {
              drugWidget.setInitialValue(drugOrder.getDrug().getDrugId());
            } else {
              if (((CheckboxWidget) drugWidget).getValue().equals(drugOrder.getDrug().getDrugId().toString()))
                ((CheckboxWidget) drugWidget).setInitialValue("CHECKED");
            }
           
            if (!existingOrder.getAction().equals(Action.DISCONTINUE)) {
              lastRevision = drugOrder;
            }
           
            startDateWidget.setInitialValue(lastRevision.getDateActivated());
           
            routeWidget.setInitialValue(lastRevision.getRoute().getId());
           
            careSettingWidget.setInitialValue(lastRevision.getCareSetting().getId());
           
            dosingTypeWidget.setInitialValue(lastRevision.getDosingType().toString());
           
            doseWidget.setInitialValue(lastRevision.getDose());

                        numRefillsWidget.setInitialValue(lastRevision.getNumRefills());
           
            if (lastRevision.getDoseUnits() != null) {
              doseUnitsWidget.setInitialValue(lastRevision.getDoseUnits().getId());
            }
           
            quantityWidget.setInitialValue(lastRevision.getQuantity());
           
            if (lastRevision.getQuantityUnits() != null) {
              quantityUnitsWidget.setInitialValue(lastRevision.getQuantityUnits().getId());
            }
           
            durationWidget.setInitialValue(lastRevision.getDuration());
           
            if (lastRevision.getDurationUnits() != null) {
              durationUnitsWidget.setInitialValue(lastRevision.getDurationUnits().getId());
            }
           
            frequencyWidget.setInitialValue(lastRevision.getFrequency().getConcept().getId());
           
            if (!usingDurationField) {
              discontinuedDateWidget.setInitialValue(drugOrder.getDateStopped());
              Order discontinuationOrder = Context.getOrderService().getDiscontinuationOrder(drugOrder);
              if (discontinuedReasonWidget != null && discontinuationOrder != null)
                discontinuedReasonWidget.setInitialValue(discontinuationOrder.getOrderReason()
                        .getConceptId());
            }
            break;
          }
         
View Full Code Here

 
  @Override
  protected void enterOrder(FormEntrySession session, OrderTag oldOrderTag) {
    OrderTag1_10 orderTag = (OrderTag1_10) oldOrderTag;
   
    DrugOrder drugOrder = new DrugOrder();
    setOrderer(session, drugOrder);
   
    drugOrder.setDrug(orderTag.drug);
    drugOrder.setConcept(orderTag.drug.getConcept());
    drugOrder.setPatient(session.getPatient());
    drugOrder.setDosingType(orderTag.dosingType);
    drugOrder.setDose(orderTag.dose);
    drugOrder.setDoseUnits(orderTag.doseUnits);
    drugOrder.setQuantity(orderTag.quantity);
    drugOrder.setQuantityUnits(orderTag.quantityUnits);
    drugOrder.setDuration(orderTag.duration);
    drugOrder.setDurationUnits(orderTag.durationUnits);
    drugOrder.setRoute(orderTag.route);
    drugOrder.setCareSetting(Context.getOrderService().getCareSetting(orderTag.careSettingId));
    OrderFrequency orderFrequency = Context.getOrderService().getOrderFrequency(Integer.valueOf(orderTag.frequency));
    drugOrder.setFrequency(orderFrequency);
    drugOrder.setDateActivated(orderTag.startDate);
        drugOrder.setNumRefills(orderTag.numRefills);
    //order duration:
    if (orderTag.orderDuration != null)
      drugOrder.setAutoExpireDate(calculateAutoExpireDate(orderTag.startDate, orderTag.orderDuration));
    drugOrder.setVoided(false);
    drugOrder.setOrderType(Context.getOrderService().getOrderTypeByUuid(DRUG_ORDER_TYPE_UUID));
    if (!StringUtils.isEmpty(orderTag.instructions))
      drugOrder.setInstructions((String) orderTag.instructions);
   
    DrugOrder discontinuationOrder = createDiscontinuationOrderIfNeeded(drugOrder, orderTag.discontinuedDate,
        orderTag.discontinuedReasonStr);
   
    log.debug("adding new drug order, drugId is " + orderTag.drugId + " and startDate is " + orderTag.startDate);
    session.getSubmissionActions().getCurrentEncounter().addOrder(drugOrder);
    if (discontinuationOrder != null) {
View Full Code Here

      for (RegimenSuggestion rs :  regimenCandidates){
        List<DrugOrder> matchHolder = new ArrayList<DrugOrder>(); //collects drug matches between encounter and RegimenSuggestion
        boolean allFound = true; //true until a DrugSuggestion from the RegimenSuggestion isn't matched.
        Date startDate = null//if all DrugSuggestions are matched but have different start dates, we can't match.
        for (DrugSuggestion dc : rs.getDrugComponents()){
          DrugOrder dorToInspect = drugIdFoundInDrugSet(dc, drugOrders); //assumes patient will never have multiple drug orders of same drug in same encounter...
          if (dorToInspect != null){ // there was a match by drug
            if (startDate == null) // setup standard regimen start date
              startDate = dorToInspect.getStartDate();
            if (startDate.equals(dorToInspect.getStartDate())) //this will always be true for first drug matched.
              matchHolder.add(drugIdFoundInDrugSet(dc, drugOrders));
            else {
              //the drug was matched on drug type, but the start date was different.  This tag assumes equal start and stop dates to be a standard regimen.
              allFound = false;
              break;
View Full Code Here

   */
  private void createOrdersFromPost(SimpleObject post, Encounter encounter) throws ResponseException {
    List<LinkedHashMap> orderObjects = (List<LinkedHashMap>) post.get("orders");
    for (int i = 0; i < orderObjects.size(); i++) {
      //only setting drug orders now
      DrugOrder order = new DrugOrder();
      order.setPatient(encounter.getPatient());
      order.setConcept(Context.getConceptService().getConceptByUuid(orderObjects.get(i).get("concept").toString()));
      order.setOrderType(Context.getOrderService().getOrderType(OpenmrsConstants.ORDERTYPE_DRUG));
      if (orderObjects.get(i).get("instructions") != null) {
        order.setInstructions(orderObjects.get(i).get("instructions").toString());
      }
      if (orderObjects.get(i).get("drug") != null) {
        order.setDrug(Context.getConceptService().getDrugByUuid(orderObjects.get(i).get("drug").toString()));
      }
      if (orderObjects.get(i).get("instructions") != null) {
        order.setInstructions(orderObjects.get(i).get("instructions").toString());
      }
      if (orderObjects.get(i).get("frequency") != null) {
        order.setFrequency(orderObjects.get(i).get("frequency").toString());
      }
      if (orderObjects.get(i).get("quantity") != null) {
        order.setQuantity((Integer) orderObjects.get(i).get("quantity"));
      }
      if (orderObjects.get(i).get("dose") != null) {
        order.setDose((Double) orderObjects.get(i).get("dose"));
      }
      if (orderObjects.get(i).get("startDate") != null) {
        for (int j = 0; j < DATE_FORMATS.length; j++) {
          try {
            Date date = new SimpleDateFormat(DATE_FORMATS[j]).parse(orderObjects.get(i).get("startDate")
                    .toString());
            order.setStartDate(date);
          }
          catch (Exception ex) {}
        }
      }
      if (orderObjects.get(i).get("autoExpireDate") != null) {
        for (int j = 0; j < DATE_FORMATS.length; j++) {
          try {
            Date date = new SimpleDateFormat(DATE_FORMATS[j]).parse(orderObjects.get(i).get("autoExpireDate")
                    .toString());
            order.setAutoExpireDate(date);
          }
          catch (Exception ex) {}
        }
      }
      order.setEncounter(encounter);
      if (encounter.getProvider() != null) {
        order.setOrderer(Context.getAuthenticatedUser());
      }
      Context.getOrderService().saveOrder(order);
    }
  }
View Full Code Here

    SimpleObject orderConcept = new SimpleObject();
    orderConcept.add("uuid", order.getConcept().getUuid());
    orderConcept.add("display", order.getConcept().getName().getName());
    newOrderObject.add("concept", orderConcept);
    if (order.isDrugOrder()) {
      DrugOrder currentDrugOrder = (DrugOrder) order;
      newOrderObject.add("instructions", currentDrugOrder.getInstructions());
      newOrderObject.add("startDate", currentDrugOrder.getStartDate().toString());
      newOrderObject.add("autoExpireDate", currentDrugOrder.getAutoExpireDate().toString());
      newOrderObject.add("dose", currentDrugOrder.getDose());
      newOrderObject.add("units", currentDrugOrder.getUnits());
      newOrderObject.add("frequency", currentDrugOrder.getFrequency());
      newOrderObject.add("quantity", currentDrugOrder.getQuantity());
      SimpleObject drugObj = new SimpleObject();
      drugObj.add("uuid", currentDrugOrder.getDrug().getUuid());
      drugObj.add("display", currentDrugOrder.getDrug().getName());
      newOrderObject.add("drug", drugObj);
    }
    return newOrderObject;
  }
View Full Code Here

   */
  protected void populateDrugOrderValuesFromDB(FormEntryContext context, Boolean usingDurationField) {
      for (Drug drug : drugsUsedAsKey) {
          if (context.getExistingOrders().containsKey(drug.getConcept())) {
              //this will return null if Order is not a DrugOrder even if matched by Concept
              DrugOrder drugOrder = (DrugOrder) context.removeExistingDrugOrder(drug);
              if (drugOrder != null){
              existingOrder = drugOrder;
              if (drugWidget instanceof DropdownWidget){
                  drugWidget.setInitialValue(drugOrder.getDrug().getDrugId());
              } else {
                  if (((CheckboxWidget) drugWidget).getValue().equals(drugOrder.getDrug().getDrugId().toString()))
                      ((CheckboxWidget) drugWidget).setInitialValue("CHECKED");
              }
              startDateWidget.setInitialValue(drugOrder.getStartDate());
              if (!hideDoseAndFrequency){
                  doseWidget.setInitialValue(drugOrder.getDose());
                  frequencyWidget.setInitialValue(parseFrequencyDays(drugOrder.getFrequency()));
                  frequencyWeekWidget.setInitialValue(parseFrequencyWeek(drugOrder.getFrequency()));
              }
              if (!usingDurationField){
                  discontinuedDateWidget.setInitialValue(drugOrder.getDiscontinuedDate());
                  if (discontinuedReasonWidget != null && drugOrder.getDiscontinuedReason() != null)
                      discontinuedReasonWidget.setInitialValue(drugOrder.getDiscontinuedReason().getConceptId());
              }
              break;
              }

          }
View Full Code Here

      existingOrder = setDiscontinueDateFromAutoExpire(existingOrder);
      session.getSubmissionActions().getCurrentEncounter().setDateChanged(new Date());
    }

  protected void enterOrder(FormEntrySession session, OrderTag orderTag) {
      DrugOrder drugOrder = new DrugOrder();
      if (drugOrder.getDateCreated() == null)
          drugOrder.setDateCreated(new Date());
      if (drugOrder.getCreator() == null)
          drugOrder.setCreator(Context.getAuthenticatedUser());
      if (drugOrder.getUuid() == null)
          drugOrder.setUuid(UUID.randomUUID().toString());
      drugOrder.setDrug(orderTag.drug);
      drugOrder.setPatient(session.getPatient());
      drugOrder.setDose(orderTag.dose);
      drugOrder.setFrequency(orderTag.frequency);
      drugOrder.setStartDate(orderTag.startDate);
      //order duration:
      if (orderTag.orderDuration != null)
          drugOrder.setAutoExpireDate(calculateAutoExpireDate(orderTag.startDate, orderTag.orderDuration));
      drugOrder.setVoided(false);
      drugOrder.setDrug(orderTag.drug);
      drugOrder.setConcept(orderTag.drug.getConcept());
      drugOrder.setOrderType(Context.getOrderService().getOrderType(OpenmrsConstants.ORDERTYPE_DRUG));
      if (!StringUtils.isEmpty(orderTag.instructions))
          drugOrder.setInstructions((String) orderTag.instructions);
      if (orderTag.discontinuedDate != null){
          drugOrder.setDiscontinuedDate(orderTag.discontinuedDate);
          drugOrder.setDiscontinued(true);
      }   
      if (!StringUtils.isEmpty(orderTag.discontinuedReasonStr))
          drugOrder.setDiscontinuedReason(HtmlFormEntryUtil.getConcept(orderTag.discontinuedReasonStr));
      log.debug("adding new drug order, drugId is " + orderTag.drugId + " and startDate is " + orderTag.startDate);
      drugOrder = setDiscontinueDateFromAutoExpire(drugOrder);
      session.getSubmissionActions().getCurrentEncounter().addOrder(drugOrder);
    }
View Full Code Here

TOP

Related Classes of org.openmrs.DrugOrder

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.