Search in sources :

Example 6 with ProviderAttributeType

use of org.openmrs.ProviderAttributeType 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 ProviderAttributeType

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

the class ProviderRoleBundle method install.

/**
 * Performs the installation of the metadata items
 *
 * @throws Exception if an error occurs
 */
@Override
public void install() throws Exception {
    Set<RelationshipType> relationshipTypes = null;
    RelationshipType vhwToPatient = personService.getRelationshipTypeByUuid(RelationshipTypeBundle.RelationshipTypes.CHW_TO_PATIENT);
    if (vhwToPatient != null) {
        relationshipTypes = new HashSet<RelationshipType>();
        relationshipTypes.add(vhwToPatient);
    }
    Set<ProviderAttributeType> providerAttributes = new HashSet<ProviderAttributeType>();
    ProviderAttributeType providerAttributeType = providerService.getProviderAttributeTypeByUuid(ProviderAttributeTypeBundle.ProviderAttributeTypes.DATE_HIRED);
    if (providerAttributeType != null) {
        providerAttributes.add(providerAttributeType);
    }
    providerAttributeType = providerService.getProviderAttributeTypeByUuid(ProviderAttributeTypeBundle.ProviderAttributeTypes.NUMBER_OF_HOUSEHOLDS);
    if (providerAttributeType != null) {
        providerAttributes.add(providerAttributeType);
    }
    ProviderRole vhwSupervisee = install(providerRole("CHW", null, relationshipTypes, providerAttributes, ProviderRoles.CHW));
    Set<ProviderRole> superviseeRoles = null;
    if (vhwSupervisee != null) {
        superviseeRoles = new HashSet<ProviderRole>();
        superviseeRoles.add(vhwSupervisee);
    }
    install(providerRole("CHW Supervisor", superviseeRoles, relationshipTypes, providerAttributes, ProviderRoles.CHW_SUPERVISOR));
}
Also used : RelationshipType(org.openmrs.RelationshipType) ProviderRole(org.openmrs.module.providermanagement.ProviderRole) ProviderAttributeType(org.openmrs.ProviderAttributeType) HashSet(java.util.HashSet)

Example 8 with ProviderAttributeType

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

the class ProviderServiceTest method getProviderAttributeType_shouldGetProviderAttributeTypeForTheGivenId.

/**
 * @see ProviderService#getProviderAttributeType(Integer)
 */
@Test
public void getProviderAttributeType_shouldGetProviderAttributeTypeForTheGivenId() {
    ProviderAttributeType providerAttributeType = service.getProviderAttributeType(1);
    assertEquals("Audit Date", providerAttributeType.getName());
    assertEquals("9516cc50-6f9f-11e0-8414-001e378eb67e", providerAttributeType.getUuid());
}
Also used : ProviderAttributeType(org.openmrs.ProviderAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with ProviderAttributeType

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

the class ProviderServiceTest method purgeProviderAttributeType_shouldDeleteAProviderAttributeType.

/**
 * @see ProviderService#purgeProviderAttributeType(ProviderAttributeType)
 */
@Test
public void purgeProviderAttributeType_shouldDeleteAProviderAttributeType() {
    int size = service.getAllProviderAttributeTypes().size();
    ProviderAttributeType providerAttributeType = service.getProviderAttributeType(2);
    service.purgeProviderAttributeType(providerAttributeType);
    assertEquals(size - 1, service.getAllProviderAttributeTypes().size());
}
Also used : ProviderAttributeType(org.openmrs.ProviderAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with ProviderAttributeType

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

the class ProviderServiceTest method retireProviderAttributeType_shouldRetireProviderTypeAttribute.

/**
 * @see ProviderService#retireProviderAttributeType(ProviderAttributeType,String)
 */
@Test
public void retireProviderAttributeType_shouldRetireProviderTypeAttribute() {
    ProviderAttributeType providerAttributeType = service.getProviderAttributeType(1);
    assertFalse(providerAttributeType.getRetired());
    assertNull(providerAttributeType.getRetireReason());
    assertEquals(2, service.getAllProviderAttributeTypes(false).size());
    service.retireProviderAttributeType(providerAttributeType, "retire reason");
    assertTrue(providerAttributeType.getRetired());
    assertEquals("retire reason", providerAttributeType.getRetireReason());
    assertEquals(1, service.getAllProviderAttributeTypes(false).size());
}
Also used : ProviderAttributeType(org.openmrs.ProviderAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ProviderAttributeType (org.openmrs.ProviderAttributeType)14 Test (org.junit.Test)9 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 HashSet (java.util.HashSet)2 ProviderAttribute (org.openmrs.ProviderAttribute)2 RelationshipType (org.openmrs.RelationshipType)2 FreeTextDatatype (org.openmrs.customdatatype.datatype.FreeTextDatatype)2 Provider (org.openmrs.module.providermanagement.Provider)2 ProviderRole (org.openmrs.module.providermanagement.ProviderRole)2 ArrayList (java.util.ArrayList)1 Criteria (org.hibernate.Criteria)1 Person (org.openmrs.Person)1 Provider (org.openmrs.Provider)1 APIException (org.openmrs.api.APIException)1 DateDatatype (org.openmrs.customdatatype.datatype.DateDatatype)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