Package org.openmrs.module.webservices.rest.web.response

Examples of org.openmrs.module.webservices.rest.web.response.ResponseException


  }
 
  private void validatePost(SimpleObject post) throws ResponseException {
    for (int i = 0; i < REQUIRED_FIELDS.length; i++) {
      if (post.get(REQUIRED_FIELDS[i]) == null) {
        throw new ResponseException(
                                    "Required field " + REQUIRED_FIELDS[i] + " not found") {};
      }
    }
  }
View Full Code Here


  }
 
  private void validatePost(SimpleObject post) throws ResponseException {
    for (int i = 0; i < REQUIRED_FIELDS.length; i++) {
      if (post.get(REQUIRED_FIELDS[i]) == null) {
        throw new ResponseException(
                                    "Required field " + REQUIRED_FIELDS[i] + " not found") {};
      }
    }
  }
View Full Code Here

            //check that that this value has no invalid units
            try {
              Double.parseDouble(originalValue);
            }
            catch (NumberFormatException e) {
              throw new ResponseException(
                                          originalValue + " has invalid units", e) {};
            }
          }
        }
      }
      try {
        if (obs.getConcept().getDatatype().getHl7Abbreviation().equals("ZZ")) {
          obs.setValueText(value.toString());
        } else {
          obs.setValueAsString(value.toString());
        }
      }
      catch (Exception e) {
        throw new ResponseException(
                                    "Unable to convert obs value " + e.getMessage()) {};
      }
    }
    return obs;
  }
View Full Code Here

  }
 
  private boolean validatePost(SimpleObject post) throws ResponseException {
    for (int i = 0; i < REQUIREDFIELDS.length; i++) {
      if (post.get(REQUIREDFIELDS[i]) == null) {
        throw new ResponseException(
                                    "Required field " + REQUIREDFIELDS[i] + " not found") {};
      }
    }
    if (service.getUserByUsername(post.get("userName").toString()) != null) {
      throw new ResponseException(
                                  "User name must be unique") {};
    }
    OpenmrsUtil.validatePassword(post.get("userName").toString(), post.get("password").toString(), null);
    for (int j = 0; j < TYPE.length; j++) {
      if (post.get("type").equals(TYPE[j])) {
        return true;
      }
    }
    throw new ResponseException(
                                "User type is unsupported") {};
  }
View Full Code Here

    name.setPreferred(true);
    person.addName(name);
    person.setGender(post.get("gender").toString());
    Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString());
    if (location == null) {
      throw new ResponseException(
                                  "Location uuid not found") {};
    }
    PersonAttribute locationAttribute = new PersonAttribute();
    locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center"));
    locationAttribute.setValue(location.getId().toString());
View Full Code Here

  }
 
  private boolean validatePost(SimpleObject post) throws ResponseException {
    for (int i = 0; i < REQUIREDFIELDS.length; i++) {
      if (post.get(REQUIREDFIELDS[i]) == null) {
        throw new ResponseException(
                                    "Required field " + REQUIREDFIELDS[i] + " not found") {};
      }
    }
    User u = Context.getAuthenticatedUser();
    Person p = Context.getPersonService().getPersonByUuid(u.getPerson().getUuid());
    if (p.getAttribute("Health Center") == null) {
      throw new ResponseException(
                                  "Current user needs Health Center attribute") {};
    }
    return true;
  }
View Full Code Here

      if (attributeObjects.get(i).get("attributeType") != null && attributeObjects.get(i).get("value") != null) {
        PersonAttribute pa = new PersonAttribute();
        PersonAttributeType paType = Context.getPersonService().getPersonAttributeTypeByUuid(
            attributeObjects.get(i).get("attributeType").toString());
        if (paType == null) {
          throw new ResponseException(
                                      "Person Attribute Type not found") {};
        }
        pa.setAttributeType(paType);
        String paValue = attributeObjects.get(i).get("value").toString();
        if (paValue == null) {
          throw new ResponseException(
                                      "Person Attribute Value cannot be null") {};
        }
        pa.setValue(paValue);
        p.addAttribute(pa);
      }
View Full Code Here

      obj.add("roles", u.getAllRoles());
      obj.add("privileges", u.getPrivileges());
      obj.add("serverTime", Calendar.getInstance().getTime());
      return gson.toJson(obj);
    } else {
      throw new ResponseException(
                                  "Not Authenticated") {};
    }
  }
View Full Code Here

        di.setDrugPurchaseOrderId(purchaseOrder.getId());
        if (inventoryObjects.get(i).get("batchUuid") != null) {
          DrugInventory batchDrugInv = Context.getService(DrugInventoryService.class).getDrugInventoryByUuid(
              inventoryObjects.get(i).get("batchUuid").toString());
          if (batchDrugInv == null) {
            throw new ResponseException(
                                        "Batch uuid not found") {};
          }
          if (batchDrugInv.getQuantity() < di.getQuantity()) {
            throw new ResponseException(
                                        "Requested quantity cannot exceed batch quantity") {};
          }
          batchDrugInv.setQuantity(batchDrugInv.getQuantity() - di.getQuantity());
          if (batchDrugInv.getQuantity() == 0)
            batchDrugInv.setStatus("out");
View Full Code Here

      drugInventory.setDescription(postFields.get("description").toString());
    }
    if (postFields.get("drug") != null) {
      Drug d = Context.getConceptService().getDrugByUuid(postFields.get("drug").toString());
      if (d == null) {
        throw new ResponseException(
                                    "Drug uuid not found") {};
      }
      drugInventory.setDrugId(d.getDrugId());
      drugInventory.setDrug(d);
    }
    if (postFields.get("quantity") != null) {
      drugInventory.setQuantity(Integer.parseInt(postFields.get("quantity").toString()));
    }
    if (postFields.get("originalQuantity") != null) {
      drugInventory.setOriginalQuantity(Integer.parseInt(postFields.get("originalQuantity").toString()));
    }
    if (postFields.get("expiryDate") != null) {
      Date date = null;
      String[] supportedFormats = { "EEE MMM dd yyyy HH:mm:ss z (zzzz)", "EEE MMM dd yyyy HH:mm:ss z (zzzz)",
              "MMM dd, yyyy HH:mm:ss a", "EEE MMM dd yyyy HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
              "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss",
              "yyyy-MM-dd" };
      for (int i = 0; i < supportedFormats.length; i++) {
        try {
          date = new SimpleDateFormat(supportedFormats[i]).parse(postFields.get("expiryDate").toString());
          drugInventory.setExpiryDate(date);
        }
        catch (Exception ex) {}
      }
      if (date == null) {
        throw new ResponseException(
                                    "Invalid date " + postFields.get("expiryDate")) {};
      }
    }
    if (postFields.get("batch") != null) {
      drugInventory.setBatch(postFields.get("batch").toString());
    }
    if (postFields.get("supplier") != null) {
      drugInventory.setSupplier(postFields.get("supplier").toString());
    }
    if (postFields.get("roomLocation") != null) {
      drugInventory.setRoomLocation(postFields.get("roomLocation").toString());
    }
    if (postFields.get("value") != null) {
      drugInventory.setValue(Integer.parseInt(postFields.get("value").toString()));
    }
    if (postFields.get("status") != null) {
      drugInventory.setStatus(postFields.get("status").toString());
    }
    if (postFields.get("provider") != null) {
      Provider p = Context.getProviderService().getProviderByUuid(postFields.get("provider").toString());
      if (p == null) {
        throw new ResponseException(
                                    "Provider uuid not found") {};
      }
      drugInventory.setProviderId(p.getId());
      drugInventory.setProvider(p);
    }
    if (postFields.get("location") != null) {
      Location l = Context.getLocationService().getLocationByUuid(postFields.get("location").toString());
      if (l == null) {
        throw new ResponseException(
                                    "Location uuid not found") {};
      }
      drugInventory.setLocationId(l.getId());
      drugInventory.setLocation(l);
    }
    if (postFields.get("drugPurchaseOrder") != null) {
      DrugPurchaseOrder dPOrder = Context.getService(DrugPurchaseOrderService.class).getDrugPurchaseOrderByUuid(
          postFields.get("drugPurchaseOrder").toString());
      if (dPOrder == null) {
        throw new ResponseException(
                                    "DrugPurchaseOrder uuid not found") {};
      }
      drugInventory.setDrugPurchaseOrderId(dPOrder.getId());
      drugInventory.setDrugPurchaseOrder(dPOrder);
    }
View Full Code Here

TOP

Related Classes of org.openmrs.module.webservices.rest.web.response.ResponseException

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.