Package org.openmrs

Examples of org.openmrs.Person


            Date dateAndTime = HtmlFormEntryUtil.combineDateAndTime(e.getEncounterDatetime(), time);
            e.setEncounterDatetime(dateAndTime);
        }
        if (providerWidget != null) {
            Object value = providerWidget.getValue(session.getContext(), submission);
            Person person = (Person) convertValueToProvider(value);
            session.getSubmissionActions().getCurrentEncounter().setProvider(person);
        }
        if (locationWidget != null) {
            Object value = locationWidget.getValue(session.getContext(), submission);
            Location location = (Location) HtmlFormEntryUtil.convertToType(value.toString().trim(), Location.class);
View Full Code Here


    if (!stackContains(Person.class))
      throw new InvalidActionException("No Person on the stack");
    if (group.getObsId() == null && !obsToCreate.contains(group)) {
      obsToCreate.add(group);
    }
    Person person = highestOnStack(Person.class);
    Encounter encounter = highestOnStack(Encounter.class);
    group.setPerson(person);
    if (encounter != null) {
      addObsToEncounterIfNotAlreadyThere(encounter, group);
    }
View Full Code Here

  public Obs createObs(Concept concept, Object value, Date datetime, String accessionNumber, String comment) {
    if (value == null || "".equals(value))
      throw new IllegalArgumentException("Cannot create Obs with null or blank value");
    Obs obs = HtmlFormEntryUtil.createObs(concept, value, datetime, accessionNumber);
   
    Person person = highestOnStack(Person.class);
    if (person == null)
      throw new IllegalArgumentException("Cannot create an Obs outside of a Person.");
    Encounter encounter = highestOnStack(Encounter.class);
    Obs obsGroup = highestOnStack(Obs.class);
   
View Full Code Here

         
          // If specific persons are specified, display only those persons in order
          String personsParam = (String) parameters.get("persons");
          if (personsParam != null) {
            for (String s : personsParam.split(",")) {
              Person p = HtmlFormEntryUtil.getPerson(s);
              if (p == null) {
                throw new RuntimeException("Cannot find Person: " + s);
              }
              options.add(new PersonStub(p));
            }
          }
         
          // Only if specific person ids are not passed in do we get by user Role
          if (options.isEmpty()) {
           
            List<PersonStub> users = new ArrayList<PersonStub>();
           
            // If the "role" attribute is passed in, limit to users with this role
            if (parameters.get("role") != null) {
              Role role = Context.getUserService().getRole((String) parameters.get("role"));
              if (role == null) {
                throw new RuntimeException("Cannot find role: " + parameters.get("role"));
              } else {
                users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
              }
            }

            // Otherwise, limit to users with the default OpenMRS PROVIDER role,
            else {
              String defaultRole = OpenmrsConstants.PROVIDER_ROLE;
              Role role = Context.getUserService().getRole(defaultRole);
              if (role != null) {
                users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
              }
              // If this role isn't used, default to all Users
              if (users.isEmpty()) {
                users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(null);
              }
            }
            options.addAll(users);
            //              sortOptions = true;
          }

          valueWidget = new PersonStubWidget(options);

        } else {
          if (textAnswers.size() == 0) {
            Integer rows = null;
            Integer cols = null;
            try {
              rows = Integer.valueOf(parameters.get("rows"));
            }
            catch (Exception ex) {}
            try {
              cols = Integer.valueOf(parameters.get("cols"));
            }
            catch (Exception ex) {}
            if (rows != null || cols != null || "textarea".equals(parameters.get("style"))) {
              valueWidget = new TextFieldWidget(rows, cols);
            } else {
              Integer textFieldSize = null;
              try {
                                textFieldSize = Integer.valueOf(parameters.get("size"));
              }
              catch (Exception ex) {}
              valueWidget = new TextFieldWidget(textFieldSize);
            }
                        ((TextFieldWidget) valueWidget).setPlaceholder(parameters.get("placeholder"));
                    } else {
            if ("radio".equals(parameters.get("style"))) {
              valueWidget = new RadioButtonsWidget();
              if (answerSeparator != null) {
                ((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator);
                            }
            } else { // dropdown
              valueWidget =buildDropdownWidget(size);
            }
            // need to make sure we have the initialValue too
            String lookFor = existingObs == null ? null : existingObs.getValueText();
            for (int i = 0; i < textAnswers.size(); ++i) {
              String s = textAnswers.get(i);
              if (lookFor != null && lookFor.equals(s))
                lookFor = null;
              String label = null;
              if (answerLabels != null && i < answerLabels.size()) {
                label = answerLabels.get(i);
              } else {
                label = s;
              }
              ((SingleOptionWidget) valueWidget).addOption(new Option(label, s, false));
            }
            // if lookFor is still non-null, we need to add it directly
            // as an option:
            if (lookFor != null)
              ((SingleOptionWidget) valueWidget).addOption(new Option(lookFor, lookFor, true));
          }
        }

        if (initialValue != null) {
          if (isLocationObs) {
            Location l = HtmlFormEntryUtil.getLocation(initialValue, context);
            if (l == null) {
              throw new RuntimeException("Cannot find Location: " + initialValue);
            }
            valueWidget.setInitialValue(l);
          } else if ("person".equals(parameters.get("style"))) {
            Person p = HtmlFormEntryUtil.getPerson(initialValue);
            if (p == null) {
              throw new RuntimeException("Cannot find Person: " + initialValue);
            }
            valueWidget.setInitialValue(new PersonStub(p));
          } else {
View Full Code Here

    } else if (dt.isText()) {
      if (value instanceof Location) {
        Location location = (Location) value;
        obs.setValueText(location.getId().toString() + " - " + location.getName());
      } else if (value instanceof Person) {
        Person person = (Person) value;
        obs.setValueText(person.getId().toString() + " - " + person.getPersonName().toString());
      } else {
        obs.setValueText(value.toString());
      }
    } else if (dt.isCoded()) {
            if (value instanceof Drug) {
View Full Code Here

   * @should find a person by username of corresponding user
   * @should return null otherwise
   */
  public static Person getPerson(String id) {
   
    Person person = null;
   
    if (id != null) {

            id = id.trim();

View Full Code Here

        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

  @ResponseBody
  public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response)
          throws ResponseException {
    initPatientController();
    validatePost(post);
    Person person = new Person();
    addNames(person, post);
    person.setGender(post.get("gender").toString());
    if (post.get("birthdate") != null) {
      if (post.get("time") != null) {
        String[] supportedFormats = { "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 date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString());
            person.setBirthdate(date);
            person.setBirthdateEstimated(Boolean.FALSE);
          }
          catch (Exception ex) {}
        }
      }
    } else if (post.get("age") != null) {
      person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date());
      person.setBirthdateEstimated(Boolean.TRUE);
    }
    //Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString());
    Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid(
        Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue());
    Location location = Context.getLocationService().getLocation(userLocation);
    PersonAttribute locationAttribute = new PersonAttribute();
    locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center"));
    locationAttribute.setValue(location.getId().toString());
    person.addAttribute(locationAttribute);
    if (post.get("attributes") != null) {
      addAttributes(person, post);
    }
    if (post.get("addresses") != null) {
      addAddresses(person, post);
View Full Code Here

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

  @ResponseBody()
  public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response)
          throws ResponseException {
    initUserController();
    validatePost(post);
    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])) {
View Full Code Here

TOP

Related Classes of org.openmrs.Person

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.