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;
}
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());
}
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());
}
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);
}
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";
}
Aggregations