Search in sources :

Example 6 with Provider

use of org.openmrs.module.providermanagement.Provider 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)

Example 7 with Provider

use of org.openmrs.module.providermanagement.Provider in project openmrs-module-pihcore by PIH.

the class PihProviderIdentifierGeneratorTest method shouldGenerateAppropriateIdentifierForProvider.

@Test
public void shouldGenerateAppropriateIdentifierForProvider() {
    when(config.getProviderIdentifierPrefix()).thenReturn("M");
    Provider provider = new Provider();
    provider.setId(4);
    String identifier = (generator).generateIdentifier(provider);
    Assert.assertEquals("MAAFD", identifier);
}
Also used : Provider(org.openmrs.module.providermanagement.Provider) Test(org.junit.Test)

Example 8 with Provider

use of org.openmrs.module.providermanagement.Provider in project openmrs-module-pihcore by PIH.

the class PihProviderIdentifierGeneratorComponentTest method shouldGenerateAppropriateIdentifierForProvider.

@Test
public void shouldGenerateAppropriateIdentifierForProvider() {
    Provider provider = new Provider();
    provider.setId(4);
    String identifier = (Context.getRegisteredComponents(ProviderIdentifierGenerator.class).get(0)).generateIdentifier(provider);
    Assert.assertEquals("MAAFD", identifier);
}
Also used : ProviderIdentifierGenerator(org.openmrs.module.emrapi.account.ProviderIdentifierGenerator) Provider(org.openmrs.module.providermanagement.Provider) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Aggregations

Provider (org.openmrs.module.providermanagement.Provider)8 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 ProviderAttribute (org.openmrs.ProviderAttribute)2 ProviderAttributeType (org.openmrs.ProviderAttributeType)2 ProviderRole (org.openmrs.module.providermanagement.ProviderRole)2 ProviderPersonRelationship (org.openmrs.module.providermanagement.relationship.ProviderPersonRelationship)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Person (org.openmrs.Person)1 RelationshipType (org.openmrs.RelationshipType)1 APIException (org.openmrs.api.APIException)1 ProviderIdentifierGenerator (org.openmrs.module.emrapi.account.ProviderIdentifierGenerator)1 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)1 ProviderManagementService (org.openmrs.module.providermanagement.api.ProviderManagementService)1 InvalidRelationshipTypeException (org.openmrs.module.providermanagement.exception.InvalidRelationshipTypeException)1 PersonIsNotProviderException (org.openmrs.module.providermanagement.exception.PersonIsNotProviderException)1 SuggestionEvaluationException (org.openmrs.module.providermanagement.exception.SuggestionEvaluationException)1