Search in sources :

Example 1 with ProviderAttribute

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

the class ProviderValidatorTest method makeAttribute.

private ProviderAttribute makeAttribute(String serializedValue) {
    ProviderAttribute attr = new ProviderAttribute();
    attr.setAttributeType(providerService.getProviderAttributeType(1));
    attr.setValueReferenceInternal(serializedValue);
    return attr;
}
Also used : ProviderAttribute(org.openmrs.ProviderAttribute)

Example 2 with ProviderAttribute

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

the class ProviderServiceTest method getProviderAttribute_shouldGetProviderAttributeGivenID.

/**
 * @see ProviderService#getProviderAttribute(Integer)
 */
@Test
public void getProviderAttribute_shouldGetProviderAttributeGivenID() {
    ProviderAttribute providerAttribute = service.getProviderAttribute(321);
    assertEquals("Mr. Horatio Test Hornblower", providerAttribute.getProvider().getName());
}
Also used : ProviderAttribute(org.openmrs.ProviderAttribute) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with ProviderAttribute

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

the class ProviderServiceTest method getProviderAttributeByUuid_shouldGetProviderAttributeGivenUuid.

/**
 * @see ProviderService#getProviderAttributeByUuid(String)
 */
@Test
public void getProviderAttributeByUuid_shouldGetProviderAttributeGivenUuid() {
    ProviderAttribute providerAttribute = service.getProviderAttributeByUuid("823382cd-5faa-4b57-8b34-fed33b9c8c65");
    assertEquals("Mr. Horatio Test Hornblower", providerAttribute.getProvider().getName());
}
Also used : ProviderAttribute(org.openmrs.ProviderAttribute) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with ProviderAttribute

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

the class EditProviderPageController method get.

public void get(PageModel model, @MethodParam("getAccount") AccountDomainWrapper account, @ModelAttribute("patientId") @BindParams Patient patient, @SpringBean("patientService") PatientService patientService, @SpringBean("accountService") AccountService accountService, @SpringBean("adminService") AdministrationService administrationService, @SpringBean("providerManagementService") ProviderManagementService providerManagementService) throws PersonIsNotProviderException, InvalidRelationshipTypeException, SuggestionEvaluationException {
    model.addAttribute("account", account);
    List<ProviderRole> allProviderRoles = providerManagementService.getRestrictedProviderRoles(false);
    model.addAttribute("providerRoles", allProviderRoles);
    List<ProviderPersonRelationship> patientsList = new ArrayList<ProviderPersonRelationship>();
    List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>();
    Set<ProviderAttributeType> providerAttributeTypes = new HashSet<ProviderAttributeType>();
    List<ProviderPersonRelationship> supervisorsForProvider = null;
    List<ProviderPersonRelationship> superviseesForSupervisor = null;
    boolean isSupervisor = false;
    Provider provider = account.getProvider();
    if (provider != null) {
        if (!provider.getProviderRole().getSuperviseeProviderRoles().isEmpty()) {
            isSupervisor = true;
        }
        supervisorsForProvider = ProviderManagementUtils.getSupervisors(provider);
        superviseesForSupervisor = ProviderManagementUtils.getSupervisees(provider);
        ProviderRole providerRole = provider.getProviderRole();
        if (providerRole != null && providerRole.getRelationshipTypes() != null) {
            providerAttributeTypes = providerRole.getProviderAttributeTypes();
            Set<ProviderAttribute> attributes = provider.getAttributes();
            for (ProviderAttribute attribute : attributes) {
                // remove from the list of Attribute Types the ones that are already entered for this provider
                providerAttributeTypes.remove(attribute.getAttributeType());
            }
            for (RelationshipType relationshipType : provider.getProviderRole().getRelationshipTypes()) {
                if (!relationshipType.isRetired()) {
                    relationshipTypes.add(relationshipType);
                }
            }
            patientsList = ProviderManagementUtils.getAssignedPatients(provider);
        }
    } else {
        for (ProviderRole providerRole : allProviderRoles) {
            providerAttributeTypes.addAll(providerRole.getProviderAttributeTypes());
        }
    }
    boolean useAddressHierarchy = false;
    if (ModuleFactory.isModuleStarted("addresshierarchy")) {
        useAddressHierarchy = true;
    }
    model.addAttribute("relationshipTypes", relationshipTypes);
    model.addAttribute("patientsList", patientsList);
    model.addAttribute("providerAttributeTypes", providerAttributeTypes);
    model.addAttribute("isSupervisor", isSupervisor);
    model.addAttribute("supervisorsForProvider", supervisorsForProvider);
    model.addAttribute("superviseesForSupervisor", superviseesForSupervisor);
    model.addAttribute("superviseesForSupervisor", superviseesForSupervisor);
    model.addAttribute("useAddressHierarchy", useAddressHierarchy);
}
Also used : ProviderRole(org.openmrs.module.providermanagement.ProviderRole) ArrayList(java.util.ArrayList) RelationshipType(org.openmrs.RelationshipType) ProviderPersonRelationship(org.openmrs.module.providermanagement.relationship.ProviderPersonRelationship) Provider(org.openmrs.module.providermanagement.Provider) ProviderAttribute(org.openmrs.ProviderAttribute) ProviderAttributeType(org.openmrs.ProviderAttributeType) HashSet(java.util.HashSet)

Example 5 with ProviderAttribute

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

ProviderAttribute (org.openmrs.ProviderAttribute)5 Test (org.junit.Test)2 ProviderAttributeType (org.openmrs.ProviderAttributeType)2 Provider (org.openmrs.module.providermanagement.Provider)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Person (org.openmrs.Person)1 RelationshipType (org.openmrs.RelationshipType)1 APIException (org.openmrs.api.APIException)1 ProviderRole (org.openmrs.module.providermanagement.ProviderRole)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 ProviderPersonRelationship (org.openmrs.module.providermanagement.relationship.ProviderPersonRelationship)1