Package org.openmrs

Examples of org.openmrs.Person


      @Override
      public Patient getPatient() {
        // preemptively create a relationship
        RelationshipType type = Context.getPersonService().getRelationshipType(1);
        Patient parent = Context.getPatientService().getPatient(2);
        Person child = Context.getPersonService().getPerson(6);
       
        Relationship rel = new Relationship(parent, child, type);
        Context.getPersonService().saveRelationship(rel);
       
        Assert.assertEquals(1, Context.getPersonService().getRelationships(parent, child, type).size());
View Full Code Here


    if(results != null)
    {
      //now iterate through the results, returning person stubs
      for(Integer id : results)
      {
        Person person = Context.getPersonService().getPerson(id);
        if(person != null && !personsToExclude.contains(person))
        {
          PersonStub pStub = new PersonStub();
          pStub.setGivenName(person.getGivenName());
          pStub.setFamilyName(person.getFamilyName());
          pStub.setMiddleName(person.getMiddleName());
        pStub.setId(id);
          stubs.add(pStub);
        }
      }
    }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testCreatePatientBirthdateByAge() throws Exception {
    final Integer expectedAge = 42;
    Person person = new Person();
    person.setBirthdateFromAge(expectedAge, new Date());
    final Date expectedBirthDate = person.getBirthdate();
   
    new RegressionTestHelper() {
     
      @Override
      public String getFormName() {
View Full Code Here

     *
     * @see org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction#handleSubmission(org.openmrs.module.htmlformentry.FormEntrySession, javax.servlet.http.HttpServletRequest)
     */
    @Override
    public void handleSubmission(FormEntrySession session, HttpServletRequest submission) {
        Person relatedPerson = null;

        if (personWidget != null && personWidget.getValue(session.getContext(), submission) != null) {
            relatedPerson = ((Person) personWidget.getValue(session.getContext(), submission));
        }
        if (personStubWidget != null && personStubWidget.getValue(session.getContext(), submission) != null) {
View Full Code Here

                                sb.append("$j('#" + widgetFieldName + "_hid" + "').val(\""
                                        + (location == null ? "" : JavaScriptUtils.javaScriptEscape(location.getId().toString())) + "\");\n");
                                sb.append("$j('#" + widgetFieldName + "').change();\n");

                            } else if (widgetClass.getSimpleName().equals("Person")) {
                                Person provider = null;
                                if (returnedObj != null) {
                                    provider = (Person) returnedObj;
                                } else {
                                    //This should typically never happen,why is there no provider with this id, we
                                    //should set val(providerid) to blank so that the hidden form field is blank too
                                    val = "";
                                }
                                sb.append("$j('#" + widgetFieldName + "').val(\""
                                        + (provider == null ? "" : JavaScriptUtils.javaScriptEscape(provider.getPersonName().getFullName())) + "\");\n");
                                sb.append("$j('#" + widgetFieldName + "_hid" + "').val(\""
                                        + (provider == null ? "" : JavaScriptUtils.javaScriptEscape(provider.getId().toString())) + "\");\n");
                                sb.append("$j('#" + widgetFieldName + "').change();\n");
                            }
                        }
                    }
View Full Code Here

            List<Option> providerOptions = new ArrayList<Option>();
            // 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);
                    }
                    String label = p.getPersonName().getFullName();
                    providerOptions.add(new Option(label, p.getId().toString(), false));
                }
                removeNonProviders(providerOptions);
            }

            // Only if specific person ids are not passed in do we get by user Role
            if (providerOptions.isEmpty()) {

                List<PersonStub> users = new ArrayList<PersonStub>();
                List<Option> providerUsers = new ArrayList<Option>();

                // 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, use default options appropriate to the underlying OpenMRS version
                else {
                    if (openmrsVersionDoesNotSupportProviders()) {
                        // limit to users with the default OpenMRS PROVIDER role,
                        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);
                        }
                    } else {
                        // in OpenMRS 1.9+, get all suitable providers
                        users = getAllProvidersThatArePersonsAsPersonStubs();
                    }
                }

                for (PersonStub personStub : users) {

                    Option option = new Option(personStub.toString(), personStub.getId().toString(), false);
                    providerUsers.add(option);
                }
                providerOptions.addAll(providerUsers);

            }

            // Set default values as appropriate
            Person defaultProvider = null;
            Option defProviderOption;
            if (context.getExistingEncounter() != null) {
                defaultProvider = context.getExistingEncounter().getProvider();
                // this is done to avoid default provider being added twice due to that it can be added from the
                // users = getAllProvidersThatArePersonsAsPersonStubs(); section with selected="false", therefore this can't be caught when
                // searching whether the options list contains the 'defaultProvider'
            boolean defaultOptionPresent = false;
              if(defaultProvider != null){
                for(Option option: providerOptions){
                  if(option.getValue().equals(defaultProvider.getId().toString())){
                      defaultOptionPresent = true;
                      providerOptions.remove(option);
                      break;
                  }
                }
              }
              if(defaultOptionPresent)  {
                  defProviderOption
                     = new Option(defaultProvider.getPersonName().getFullName(), defaultProvider.getId().toString(), true);
                   providerOptions.add(defProviderOption);
              }

            } else {
                String defParam = (String) parameters.get("default");
                if (StringUtils.hasText(defParam)) {
                    if ("currentuser".equalsIgnoreCase(defParam)) {
                        defaultProvider = Context.getAuthenticatedUser().getPerson();
                    } else {
                        defaultProvider = HtmlFormEntryUtil.getPerson(defParam);
                    }
                    if (defaultProvider == null) {
                        throw new IllegalArgumentException("Invalid default provider specified for encounter: " + defParam);
                    } else {
                        defProviderOption
                                = new Option(defaultProvider.getPersonName().getFullName(), defaultProvider.getId().toString(), true);
                        for (Option option : providerOptions) {
                            if (option.getValue().equals(defProviderOption.getValue())) {
                                providerOptions.remove(option);
                                break;
                            }
View Full Code Here

            Method getProvidersMethod = providerService.getClass().getMethod("getAllProviders");
            @SuppressWarnings("rawtypes")
            List allProviders = (List) getProvidersMethod.invoke(providerService);
            List<Object> ret = new ArrayList<Object>();
            for (Object provider : allProviders) {
                Person person = (Person) PropertyUtils.getProperty(provider, "person");
                if (person != null)
                    ret.add(provider);
            }
            return ret;
        } catch (Exception ex) {
View Full Code Here

     */
    private List<PersonStub> getAllProvidersThatArePersonsAsPersonStubs() {
        try {
            List<PersonStub> ret = new ArrayList<PersonStub>();
            for (Object provider : getAllProvidersThatArePersons()) {
                Person person = (Person) PropertyUtils.getProperty(provider, "person");
                ret.add(new PersonStub(person));
            }
            return ret;
        } catch (Exception ex) {
            throw new RuntimeException("Programming error in HTML Form Entry module. This method should be safe!", ex);
View Full Code Here

     */
    private Set<Integer> getAllProviderPersonIds() {
        try {
            Set<Integer> ret = new HashSet<Integer>();
            for (Object candidate : getAllProvidersThatArePersons()) {
                Person person = (Person) PropertyUtils.getProperty(candidate, "person");
                if (person != null)
                    ret.add(person.getPersonId());
            }
            return ret;
        } catch (Exception ex) {
            throw new RuntimeException("Programming error in HTML Form Entry module. This method should be safe!", ex);
        }
View Full Code Here

        }

        try {
            if (providerWidget != null) {
                Object value = providerWidget.getValue(context, submission);
                Person provider = (Person) convertValueToProvider(value);
                if (provider == null)
                    throw new Exception("required");
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context.getFieldName(providerErrorWidget), Context.getMessageSourceService()
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.