Package org.openmrs

Examples of org.openmrs.Location


    Person person = new Person();
    PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString());
    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());
    person.addAttribute(locationAttribute);
    if (post.get("email") != null) {
      PersonAttribute emailAttribute = new PersonAttribute();
      emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email"));
      emailAttribute.setValue(post.get("email").toString());
      person.addAttribute(emailAttribute);
    }
    if (post.get("phone") != null) {
      PersonAttribute phoneAttribute = new PersonAttribute();
      phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact"));
      phoneAttribute.setValue(post.get("phone").toString());
      person.addAttribute(phoneAttribute);
    }
    if (post.get("donateOrgans") != null) {
      PersonAttribute donateOrgansAttribute = new PersonAttribute();
      donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs"));
      donateOrgansAttribute.setValue(post.get("donateOrgans").toString());
      person.addAttribute(donateOrgansAttribute);
    }
    String type = post.get("type").toString();
    if (type.equals(TYPE[0])) {
      person = savePatient(person, post, location);
    } else if (type.equals(TYPE[1])) {
      saveProvider(person, post);
    }
    User user = new User(person);
    user.setUsername(post.get("userName").toString());
    if (type.equals(TYPE[1])) {
      user.addRole(Context.getUserService().getRole("System Developer"));
      user.addRole(Context.getUserService().getRole("Provider"));
    }
    User newUser = service.saveUser(user, post.get("password").toString());
    service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString());
    return RestUtil.created(response, getUserAsSimpleObject(newUser));
    //    return RestUtil.created(response, getDrugAsSimpleObject(drugJustCreated));
  }
View Full Code Here


  public void testsaveDrugPurchaseOrder() {
    DrugPurchaseOrder dpOrder = new DrugPurchaseOrder();
   
    Provider provider = new Provider(1);
    provider.setDateCreated(new Date());
    Location location = new Location(1);
    location.setDateCreated(new Date());
   
    //NOTE: never set Id, will be generated automatically (when saving)
   
    dpOrder.setName("TestList4");
    dpOrder.setDescription("Third Test List");
View Full Code Here

  public void testDeleteDrugPurchaseOrder() {
    DrugPurchaseOrder dpOrder = new DrugPurchaseOrder();
   
    Provider provider = new Provider(1);
    provider.setDateCreated(new Date());
    Location location = new Location(1);
    location.setDateCreated(new Date());
   
    //NOTE: never set Id, will be generated automatically (when saving)
   
    dpOrder.setName("TestList4");
    dpOrder.setDescription("Third Test List");
View Full Code Here

      Provider p = Context.getProviderService().getProviderByUuid(post.get("provider").toString());
      purchaseOrder.setProviderId(p.getId());
      purchaseOrder.setProvider(p);
    }
    if (post.get("dispenseLocation") != null) {
      Location l = Context.getLocationService().getLocationByUuid(post.get("dispenseLocation").toString());
      purchaseOrder.setDispenseLocationId(l.getId());
      purchaseOrder.setDispenseLocation(l);
    }
    if (post.get("stockLocation") != null) {
      Location l = Context.getLocationService().getLocationByUuid(post.get("stockLocation").toString());
      purchaseOrder.setStockLocationId(l.getId());
      purchaseOrder.setStockLocation(l);
    }
    return purchaseOrder;
  }
View Full Code Here

      }
      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());
View Full Code Here

      pObj.add("display", p.getName());
    }
    obj.add("provider", pObj);
    obj.add("date", dpo.getDrugPurchaseOrderDate());
    SimpleObject dispenseObj = new SimpleObject();
    Location dispenseLoc = dpo.getDispenseLocation();
    if (dispenseLoc != null) {
      dispenseObj.add("uuid", dispenseLoc.getUuid());
      dispenseObj.add("display", dispenseLoc.getName());
    }
    obj.add("dispenseLocation", dispenseObj);
    SimpleObject stockObj = new SimpleObject();
    Location stockLoc = dpo.getStockLocation();
    if (stockLoc != null) {
      stockObj.add("uuid", stockLoc.getUuid());
      stockObj.add("display", stockLoc.getName());
    }
    obj.add("stockLocation", stockObj);
    //getting all associated drug inventories:
    List<DrugInventory> inventories = Context.getService(DrugInventoryService.class)
            .getDrugInventoriesByDrugPurchaseOrder(dpo.getId());
    if (!inventories.isEmpty()) {
      ArrayList invObjs = new ArrayList();
      //List<SimpleObject> invObjs = new ArrayList();
      for (int i = 0; i < inventories.size(); i++) {
        SimpleObject newInvObj = new SimpleObject();
        newInvObj.add("name", inventories.get(i).getName());
        newInvObj.add("description", inventories.get(i).getDescription());
        newInvObj.add("uuid", inventories.get(i).getUuid());
        SimpleObject drugObj = new SimpleObject();
        Drug d = inventories.get(i).getDrug();
        if (d != null) {
          drugObj.add("uuid", d.getUuid());
          drugObj.add("display", d.getName());
        }
        newInvObj.add("drug", drugObj);
        newInvObj.add("quantity", inventories.get(i).getQuantity());
        newInvObj.add("originalQuantity", inventories.get(i).getOriginalQuantity());
        newInvObj.add("expiryDate", inventories.get(i).getExpiryDate());
        newInvObj.add("batch", inventories.get(i).getBatch());
        newInvObj.add("supplier", inventories.get(i).getSupplier());
        newInvObj.add("roomLocation", inventories.get(i).getRoomLocation());
        newInvObj.add("value", inventories.get(i).getValue());
        newInvObj.add("status", inventories.get(i).getStatus());
        SimpleObject providerObj = new SimpleObject();
        Provider provider = inventories.get(i).getProvider();
        if (provider != null) {
          providerObj.add("uuid", provider.getUuid());
          providerObj.add("display", provider.getName());
        }
        newInvObj.add("provider", providerObj);
        SimpleObject locObj = new SimpleObject();
        Location l = inventories.get(i).getLocation();
        if (l != null) {
          locObj.add("uuid", l.getUuid());
          locObj.add("display", l.getName());
        }
        newInvObj.add("location", locObj);
        invObjs.add(newInvObj);
      }
      obj.add("inventories", invObjs);
View Full Code Here

TOP

Related Classes of org.openmrs.Location

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.