Package org.openmrs

Examples of org.openmrs.User


        role.setName("Clinician");
        role.setDateCreated(new Date());
        role.setDescription("boo");
        role.setCreator(Context.getAuthenticatedUser());
        Context.getUserService().saveRole(role);
        User user = Context.getUserService().getUser(userId);
        user.addRole(role);
        user.getPersonName().setFamilyName(null);
        user.getPersonName().setGivenName(null);
        user.getPersonName().setMiddleName("middleName");
        Context.getUserService().saveUser(user, null);
        Assert.assertEquals(1, service.getUsersAsPersonStubs("Clinician").size());
       
        //lets look at the PersonStub for the Clinician:
        PersonStub ps = service.getUsersAsPersonStubs("Clinician").get(0);
View Full Code Here


        boolean excluderesult = true;

        if (includeOrExcludeTestIndex >= 0) { // contains list of roles in 'include'
            testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex));
            testRoles = testStr.split(",");
            User currentUser = Context.getUserContext().getAuthenticatedUser();
            try {
                Set<Role> assignedRoles = currentUser.getAllRoles();
                for (Role role : assignedRoles) {
                    for (String testRole : testRoles) {
                        if (role.getRole().equals(testRole)) {
                            includeresult = true;
                        }
                    }
                }
            } catch (Exception ex) {
                throw new BadFormDesignException("The " + testStr + "contains an invalid user Role");
            }

            return includeresult;
        } else {
            includeOrExcludeTestIndex = includeStr.indexOf("exclude");
            if (includeOrExcludeTestIndex != -1) { // contains list of roles in 'exclude'
                testStr = HtmlFormEntryUtil.getTestStr(includeStr.substring(includeOrExcludeTestIndex)) ;
                testRoles = testStr.split(",");
                User currentUser = Context.getUserContext().getAuthenticatedUser();
                try {
                    Set<Role> assignedRoles = currentUser.getAllRoles();
                    for (Role role : assignedRoles) {
                        for (String testRole : testRoles) {
                            if (role.getRole().equals(testRole)) {
                                excluderesult = false;
                            }
View Full Code Here

          return person;
        }
      }
     
      // handle username
      User personByUsername = Context.getUserService().getUserByUsername(id);
      if (personByUsername != null) {
        return personByUsername.getPerson();
      }
     
      // try the "5090 - Bob Jones" case
      if (id.contains(" ")) {
        String[] values = id.split(" ");
View Full Code Here

    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 testCreateNewPatientUser() throws Exception {
    String json = "{\"firstName\":\"john\",\"lastName\":\"James\",\"gender\":\"M\",\"userName\":\"johnJames\",\"password\":\"Hello123\",\"type\":\"patient\",\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\"} }";
    SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
    Object user = controller.createNewUser(post, request, response);
    System.out.println(user);
    User u = Context.getUserService().getUserByUsername("johnJames");
    Assert.assertEquals("john", u.getGivenName());
    Assert.assertEquals("1", u.getPerson().getAttribute("Health Center").getValue());
  }
View Full Code Here

  public void testCreateNewProviderUser() throws Exception {
    String json = "{\"firstName\":\"Darth\",\"lastName\":\"Vader\",\"gender\":\"M\",\"userName\":\"johnJames\",\"password\":\"Hello123\",\"type\":\"provider\",\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\"} }";
    SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
    Object user = controller.createNewUser(post, request, response);
    System.out.println(user);
    User u = Context.getUserService().getUserByUsername("johnJames");
    Provider p = Context.getProviderService().getProviders("Darth Vader", null, null, null).iterator().next();
    Assert.assertEquals("Darth Vader", p.getName());
    Assert.assertEquals("1", u.getPerson().getAttribute("Health Center").getValue());
  }
View Full Code Here

      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

  @WSDoc("Get Login information")
  @ResponseBody()
  public String getLoginInfo(HttpServletRequest request, HttpServletResponse response) throws ResponseException {
    SimpleObject obj = new SimpleObject();
    if (Context.isAuthenticated()) {
      User u = Context.getAuthenticatedUser();
      Person p = Context.getPersonService().getPersonByUuid(u.getPerson().getUuid());
      Provider provider = Context.getProviderService().getProvidersByPerson(p).iterator().next();
      obj.add("personUuid", p.getUuid());
      if (provider != null) {
        obj.add("providerUuid", provider.getUuid());
        ArrayList attributesObj = new ArrayList();
        Iterator<ProviderAttribute> attributesIterator = provider.getActiveAttributes().iterator();
        while (attributesIterator.hasNext()) {
          SimpleObject attributeObj = new SimpleObject();
          ProviderAttribute pAttribute = attributesIterator.next();
          attributeObj.add("attributeType", pAttribute.getAttributeType().getName());
          attributeObj.add("value", pAttribute.getValue());
          attributesObj.add(attributeObj);
        }
        obj.add("providerAttributes", attributesObj);
      }
      obj.add("display", p.getPersonName().getFullName());
      if (p.getAttribute("Health Center") != null) {
        obj.add("location", Context.getLocationService().getLocation(
            Integer.parseInt(p.getAttribute("Health Center").getValue())).getUuid());
      }
      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

   * PatientListServiceImpl.
   */
  @Test
  public void testGetEncountersInPatientListShouldReturnEncounters() {
    PatientList p = new PatientList();
    p.setCreator(new User());
    p.setName("GetPatientsTestList");
    p.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1"
            + "&startDate=2000-01-01T00:00:00&endDate=2012-01-02T00:00:00");
    List<Encounter> encs = s.getEncountersInPatientList(p);
    //testing encounterType
View Full Code Here

   * PatientListServiceImpl.
   */
  @Test
  public void testGetEncountersInPatientListShouldNotReturnEncountersWithInvalidDates() {
    PatientList p = new PatientList();
    p.setCreator(new User());
    p.setName("GetPatientsTestList");
    //setting start + end dates same time, should return nothing
    p.setSearchQuery("?encounterType=61ae96f4-6afe-4351-b6f8-cd4fc383cce1"
            + "&startDate=2012-01-02T00:00:0&endDate=2012-01-01T00:00:00");
    List<Encounter> encs = s.getEncountersInPatientList(p);
View Full Code Here

TOP

Related Classes of org.openmrs.User

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.