Search in sources :

Example 36 with APIException

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);
    }
}
Also used : APIException(org.openmrs.api.APIException) NameSupportCompatibility(org.openmrs.module.coreapps.NameSupportCompatibility) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) APIException(org.openmrs.api.APIException) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with APIException

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;
}
Also used : APIException(org.openmrs.api.APIException) Criteria(org.hibernate.Criteria) GlobalProperty(org.openmrs.GlobalProperty)

Example 38 with APIException

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;
}
Also used : APIException(org.openmrs.api.APIException) AccountDomainWrapper(org.openmrs.module.emrapi.account.AccountDomainWrapper) Person(org.openmrs.Person)

Example 39 with APIException

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) APIException(org.openmrs.api.APIException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) VisitType(org.openmrs.VisitType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 40 with APIException

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);
}
Also used : BindingResult(org.springframework.validation.BindingResult) APIException(org.openmrs.api.APIException) SimpleObject(org.openmrs.ui.framework.SimpleObject) VisitAttributeType(org.openmrs.VisitAttributeType) ObjectResult(org.openmrs.ui.framework.fragment.action.ObjectResult)

Aggregations

APIException (org.openmrs.api.APIException)84 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 File (java.io.File)9 Obs (org.openmrs.Obs)7 List (java.util.List)6 Map (java.util.Map)6 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Concept (org.openmrs.Concept)5 OpenmrsObject (org.openmrs.OpenmrsObject)5 User (org.openmrs.User)5 InputStream (java.io.InputStream)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Order (org.openmrs.Order)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MessageDigest (java.security.MessageDigest)3 HashMap (java.util.HashMap)3