use of org.openmrs.api.APIException in project openmrs-module-coreapps by openmrs.
the class PatientHeaderFragmentController method getNames.
private Map<String, String> getNames(PersonName personName) {
NameSupportCompatibility nameSupport = Context.getRegisteredComponent("coreapps.NameSupportCompatibility", NameSupportCompatibility.class);
Map<String, String> nameFields = new LinkedHashMap<String, String>();
List<List<Map<String, String>>> lines = nameSupport.getLines();
String layoutToken = nameSupport.getLayoutToken();
// note that the assumption is one one field per "line", otherwise the labels that appear under each field may not render properly
try {
for (List<Map<String, String>> line : lines) {
String nameLabel = "";
String nameLine = "";
Boolean hasToken = false;
for (Map<String, String> lineToken : line) {
if (lineToken.get("isToken").equals(layoutToken)) {
String tokenValue = BeanUtils.getProperty(personName, lineToken.get("codeName"));
nameLabel = nameSupport.getNameMappings().get(lineToken.get("codeName"));
if (StringUtils.isNotBlank(tokenValue)) {
hasToken = true;
nameLine += tokenValue;
}
} else {
nameLine += lineToken.get("displayText");
}
}
// only display a line if there's a token within it we've been able to resolve
if (StringUtils.isNotBlank(nameLine) && hasToken) {
nameFields.put(nameLabel, nameLine);
}
}
return nameFields;
} catch (Exception e) {
throw new APIException("Unable to generate name fields for patient header", e);
}
}
use of org.openmrs.api.APIException in project openmrs-module-mirebalais by PIH.
the class HibernateMirebalaisHospitalDAO method getNextRadiologyOrderNumberSeedSequenceValue.
/**
* @see org.openmrs.api.db.OrderDAO#getNextRadiologyOrderNumberSeedSequenceValue()
*/
@Override
public Long getNextRadiologyOrderNumberSeedSequenceValue() {
Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class);
searchCriteria.add(Restrictions.eq("property", MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED));
GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED, LockOptions.UPGRADE);
if (globalProperty == null) {
throw new APIException("Missing global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
}
String gpTextValue = globalProperty.getPropertyValue();
if (StringUtils.isBlank(gpTextValue)) {
throw new APIException("Invalid value for global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
}
Long gpNumericValue = null;
try {
gpNumericValue = Long.parseLong(gpTextValue);
} catch (NumberFormatException ex) {
throw new APIException("Invalid value for global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
}
globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
sessionFactory.getCurrentSession().save(globalProperty);
return gpNumericValue;
}
use of org.openmrs.api.APIException 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;
}
use of org.openmrs.api.APIException in project openmrs-module-coreapps by openmrs.
the class VisitTypeHelper method getOrderedVisitTypes.
/**
* Returns a list of ordered visit types.
*
* @param visitTypes All the visit types
* @param propertyValue The visit types to order in JSON-like format
* @param visitService
* @return visitTypesOrdered The visit types ordered and merged with the input visit type list
*/
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes, String propertyValue, VisitService visitService) {
Map<Integer, String> order = null;
List<VisitType> visitTypesOrdered = new ArrayList<VisitType>();
if (propertyValue != null) {
try {
order = new ObjectMapper().readValue(propertyValue, HashMap.class);
} catch (JsonParseException e) {
VisitTypeHelper.LOG.error("Unable to parse global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (JsonMappingException e) {
VisitTypeHelper.LOG.error("Unable to map global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (APIException e) {
VisitTypeHelper.LOG.error("Unable to load global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (IOException e) {
VisitTypeHelper.LOG.error("Unable to read global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
}
}
if (order != null) {
for (int i = 1; i <= order.size(); i++) {
String typeUuid = order.get(Integer.toString(i));
VisitType type = visitService.getVisitTypeByUuid(typeUuid);
if (visitTypes.contains(type)) {
visitTypesOrdered.add(visitService.getVisitTypeByUuid(typeUuid));
}
}
for (VisitType type : visitTypes) {
if (!order.containsValue(type.getUuid())) {
visitTypesOrdered.add(type);
}
}
}
if (!(visitTypes.size() == visitTypesOrdered.size())) {
VisitTypeHelper.LOG.warn("Visit Types order property is not used.");
return visitTypes;
}
return visitTypesOrdered;
}
use of org.openmrs.api.APIException in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentController method update.
public FragmentActionResult update(@SpringBean("visitService") VisitService visitService, @RequestParam("patientId") Patient patient, @RequestParam("visitId") Visit visit, @RequestParam(value = "selectedTypeId", required = false) VisitType selectedType, UiUtils uiUtils, HttpServletRequest request) {
BindingResult bindingResult = null;
if (selectedType != null) {
visit.setVisitType(selectedType);
}
if (request.getParameterNames() != null && request.getParameterNames().hasMoreElements()) {
List<VisitAttributeType> attributeTypes = visitService.getAllVisitAttributeTypes();
WebAttributeUtil.handleSubmittedAttributesForType(visit, bindingResult, VisitAttribute.class, request, attributeTypes);
}
try {
visitService.saveVisit(visit);
} catch (APIException e) {
request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Visit.save.error");
}
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, uiUtils.message("coreapps.visit.updateVisit.successMessage", uiUtils.format(patient)));
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
SimpleObject result = SimpleObject.create("success", true, "search", "?patientId=" + visit.getPatient().getId() + "&visitId=" + visit.getId());
return new ObjectResult(result);
}
Aggregations