Search in sources :

Example 86 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PersonVoidHandlerTest method handle_shouldNotSetPersonVoidedByIfNonNull.

/**
 * @see PersonVoidHandler#handle(Person,User,Date,String)
 */
@Test
public void handle_shouldNotSetPersonVoidedByIfNonNull() {
    VoidHandler<Person> handler = new PersonVoidHandler();
    Person person = new Person();
    person.setPersonVoidedBy(new User(3));
    handler.handle(person, new User(2), null, " ");
    assertEquals(3, person.getPersonVoidedBy().getId().intValue());
}
Also used : User(org.openmrs.User) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 87 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class RequiredReasonVoidSaveHandlerTest method handle_shouldNotThrowExceptionIfVoidReasonIsNullForUnsupportedTypes.

/**
 * @see RequireVoidReasonSaveHandler#handle(Voidable,User,Date,String)
 */
@Test
public void handle_shouldNotThrowExceptionIfVoidReasonIsNullForUnsupportedTypes() {
    Person p = Context.getPersonService().getPerson(1);
    p.setVoided(true);
    p.setVoidReason(null);
    p.setVoidReason("voidReason");
    Context.getPersonService().savePerson(p);
}
Also used : Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 88 with Person

use of org.openmrs.Person in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivatorComponentTest method verifyMirebalaisProviderIdentifierGeneratorConfigured.

private void verifyMirebalaisProviderIdentifierGeneratorConfigured() {
    Person person = Context.getPersonService().getPerson(2);
    AccountDomainWrapper account = accountService.getAccountByPerson(person);
    accountService.saveAccount(account);
    assertEquals("MCEPM", account.getProvider().getIdentifier());
}
Also used : AccountDomainWrapper(org.openmrs.module.emrapi.account.AccountDomainWrapper) Person(org.openmrs.Person)

Example 89 with Person

use of org.openmrs.Person in project openmrs-module-coreapps by openmrs.

the class EditProviderPageController method getAccount.

public AccountDomainWrapper getAccount(@RequestParam(value = "personId", required = false) Person person, @RequestParam(value = "personUuid", required = false) String personUuid, @SpringBean("accountService") AccountService accountService) {
    AccountDomainWrapper account;
    Person newPerson = person;
    if (newPerson == null) {
        if (StringUtils.isNotBlank(personUuid)) {
            newPerson = Context.getPersonService().getPersonByUuid(personUuid);
        }
        if (newPerson == null) {
            newPerson = new Person();
        }
    }
    account = accountService.getAccountByPerson(newPerson);
    if (account == null)
        throw new APIException("Failed to find user account matching person with id:" + person.getPersonId());
    return account;
}
Also used : APIException(org.openmrs.api.APIException) AccountDomainWrapper(org.openmrs.module.emrapi.account.AccountDomainWrapper) Person(org.openmrs.Person)

Example 90 with Person

use of org.openmrs.Person in project openmrs-module-coreapps by openmrs.

the class EditProviderPageController method post.

public String post(@MethodParam("getAccount") @BindParams AccountDomainWrapper account, BindingResult errors, @RequestParam(value = "userEnabled", defaultValue = "false") boolean userEnabled, @RequestParam(value = "providerIdentifier", required = false) String providerIdentifier, @ModelAttribute("personAddress") @BindParams PersonAddress address, @SpringBean("providerService") ProviderService providerService, @SpringBean("messageSource") MessageSource messageSource, @SpringBean("messageSourceService") MessageSourceService messageSourceService, @SpringBean("accountService") AccountService accountService, @SpringBean("adminService") AdministrationService administrationService, @SpringBean("providerManagementService") ProviderManagementService providerManagementService, @SpringBean("accountValidator") AccountValidator accountValidator, PageModel model, HttpServletRequest request) {
    accountValidator.validate(account, errors);
    Map<Integer, String> attributesMap = getAttributeMap("providerAttributeId_", request);
    Map<Integer, String> attributeTypesMap = getAttributeMap("attributeTypeId_", request);
    if (!errors.hasErrors()) {
        try {
            Person person = account.getPerson();
            if (address != null) {
                address.setPreferred(true);
                person.addAddress(address);
            }
            Provider provider = account.getProvider();
            if (StringUtils.isNotBlank(providerIdentifier)) {
                provider.setIdentifier(providerIdentifier);
            }
            if (attributesMap.size() > 0) {
                for (Integer id : attributesMap.keySet()) {
                    ProviderAttribute providerAttribute = providerService.getProviderAttribute(id);
                    if (providerAttribute != null) {
                        providerAttribute.setValueReferenceInternal(attributesMap.get(id));
                    }
                }
            }
            if (attributeTypesMap.size() > 0) {
                for (Integer typeId : attributeTypesMap.keySet()) {
                    ProviderAttributeType providerAttributeType = providerService.getProviderAttributeType(typeId);
                    if (providerAttributeType != null) {
                        ProviderAttribute attr = new ProviderAttribute();
                        attr.setAttributeType(providerAttributeType);
                        attr.setValueReferenceInternal(attributeTypesMap.get(typeId));
                        provider.addAttribute(attr);
                    }
                }
            }
            accountService.saveAccount(account);
            request.getSession().setAttribute(UiCommonsConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, messageSourceService.getMessage("Provider saved"));
            request.getSession().setAttribute(UiCommonsConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
            return "redirect:/coreapps/providermanagement/editProvider.page?personId=" + person.getId();
        } catch (Exception e) {
            log.warn("Some error occurred while saving account details:", e);
            request.getSession().setAttribute(UiCommonsConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, messageSourceService.getMessage("Failed to save provider", new Object[] { e.getMessage() }, Context.getLocale()));
        }
    } else {
        sendErrorMessage(errors, messageSource, request);
    }
    model.addAttribute("errors", errors);
    model.addAttribute("account", account);
    model.addAttribute("providerRoles", providerManagementService.getAllProviderRoles(false));
    return "redirect:/coreapps/providermanagement/editProvider.page";
}
Also used : ProviderAttribute(org.openmrs.ProviderAttribute) Person(org.openmrs.Person) ProviderAttributeType(org.openmrs.ProviderAttributeType) PersonIsNotProviderException(org.openmrs.module.providermanagement.exception.PersonIsNotProviderException) APIException(org.openmrs.api.APIException) InvalidRelationshipTypeException(org.openmrs.module.providermanagement.exception.InvalidRelationshipTypeException) SuggestionEvaluationException(org.openmrs.module.providermanagement.exception.SuggestionEvaluationException) Provider(org.openmrs.module.providermanagement.Provider)

Aggregations

Person (org.openmrs.Person)172 Test (org.junit.Test)140 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)107 PersonName (org.openmrs.PersonName)41 User (org.openmrs.User)36 Date (java.util.Date)33 Relationship (org.openmrs.Relationship)19 Obs (org.openmrs.Obs)16 Patient (org.openmrs.Patient)15 BindException (org.springframework.validation.BindException)15 Message (ca.uhn.hl7v2.model.Message)14 Concept (org.openmrs.Concept)14 Provider (org.openmrs.Provider)14 Voidable (org.openmrs.Voidable)14 Errors (org.springframework.validation.Errors)14 ArrayList (java.util.ArrayList)10 PersonMergeLog (org.openmrs.person.PersonMergeLog)9 RelationshipType (org.openmrs.RelationshipType)8 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)7 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)7