Package org.openmrs

Examples of org.openmrs.OpenmrsObject


   @Override
    public OpenmrsObject getItemByUuid(Class<? extends OpenmrsObject> type, String uuid) {
    try {
      Criteria criteria = sessionFactory.getCurrentSession().createCriteria(type);
      criteria.add(Expression.eq("uuid", uuid));
      OpenmrsObject result = (OpenmrsObject) criteria.uniqueResult();
      return result;
    }
    catch(Exception e) {
        log.error("Error fetching item by uuid:" + e);
        return null;
View Full Code Here


    public OpenmrsObject getItemById(Class<? extends OpenmrsObject> type, Integer id) {
       try {
         String idProperty = sessionFactory.getClassMetadata(type).getIdentifierPropertyName();
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(type);
        criteria.add(Expression.eq(idProperty, id));
        OpenmrsObject result = (OpenmrsObject) criteria.uniqueResult();
        return result;
       }
       catch(Exception e) {
         log.error("Error fetching item by id:" + e);
         return null;
View Full Code Here

    public OpenmrsObject getItemByName(Class<? extends OpenmrsMetadata> type, String name) {
      // we use a try/catch here to handle oddities like "Role" which don't have a directly-referenceable name property
      try {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(type);
        criteria.add(Expression.eq("name", name));
        OpenmrsObject result = (OpenmrsObject) criteria.uniqueResult();
        return result;
      }
      catch(Exception e) {
        log.error("Error fetching item by name:" + e);
        return null;
View Full Code Here

    // if this is not a reference to an OpenMRS object, no substitution to perform
    if (!OpenmrsObject.class.isAssignableFrom(clazz)) {
      return value;
    }
   
    OpenmrsObject object = null;
     
      // if this appears to be an id, try to find the OpenmrsObject referenced by this id
      if (value.matches("^\\d+$") && !HtmlFormEntryUtil.isValidUuidFormat(value)) {
        object = Context.getService(HtmlFormEntryService.class).getItemById((Class<? extends OpenmrsObject>) clazz, Integer.valueOf(value));
      }
     
      // if we have found an object, return the uuid and use it for substitution, otherwise don't do any substitution
      if (object != null) {
        return object.getUuid();
      }
      else {
        return value;
      }
   
View Full Code Here

              String[] ids = matcher.group(1).split(",");
             
              for (String id : ids) {
                // if this id matches a uuid pattern, try to fetch the object by uuid
                if (HtmlFormEntryUtil.isValidUuidFormat(id) && OpenmrsObject.class.isAssignableFrom(attributeDescriptor.getClazz())) {
                  OpenmrsObject object = Context.getService(HtmlFormEntryService.class).getItemByUuid(
                      (Class<? extends OpenmrsObject>) attributeDescriptor.getClazz(), id);
                  if (object != null) {
                    //special handling of Form -- if passed a Form, see if it can be passed along as  HtmlForm
                    if (Form.class.equals(attributeDescriptor.getClazz())) {
                      Form form = (Form) object;
                      HtmlForm htmlForm = Context.getService(HtmlFormEntryService.class).getHtmlFormByForm(form);
                      if (htmlForm != null){
                        dependencies.add(htmlForm);
                        continue;
                      }
                    }
                    dependencies.add(object);
                    continue;
                  }
                }
               
                // if we haven't found anything by uuid, try by name
                if (OpenmrsMetadata.class.isAssignableFrom(attributeDescriptor.getClazz())) {
                  OpenmrsObject object = Context.getService(HtmlFormEntryService.class).getItemByName(
                      (Class<? extends OpenmrsMetadata>) attributeDescriptor.getClazz(), id);
                  if (object != null) {
                    dependencies.add(object);
                    continue;
                  }
View Full Code Here

TOP

Related Classes of org.openmrs.OpenmrsObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.