Changeset 3814


Ignore:
Timestamp:
Mar 23, 2016, 2:36:51 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #861: YellowLabel? tracking wizard

When filtering on the "Completed date" column a new database request is made to load items matching the filter.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/yellowlabel/list.js

    r3813 r3814  
    2222    Events.addEventHandler('rawBioAssayDateFilter', 'change', yellow.filterOnChange);
    2323    Events.addEventHandler('pilotReportDateFilter', 'change', yellow.filterOnChange);
    24     Events.addEventHandler('completedDateFilter', 'change', yellow.filterOnChange);
     24    Events.addEventHandler('completedDateFilter', 'change', yellow.completedDateFilterOnChange);
    2525
    2626    Buttons.addClickHandler('check_uncheck', yellow.selectAll);
     
    4646  {
    4747    specimen = response.specimen;
    48     if (specimen.length == 0)
    49     {
    50       Wizard.setFatalError('No YellowLabel specimen is currently available.');
    51       return;
    52     }
    5348    var frm = document.forms['reggie'];
    5449   
     
    116111    }
    117112   
    118     for (var siteNo = 0; siteNo < sites.length; siteNo++)
    119     {
    120       var site = sites[siteNo];
    121       frm.siteFilter[frm.siteFilter.length] = new Option(site.name + ' (' + siteCount[site.prefix]+')', site.prefix);
     113    if (frm.siteFilter.length < sites.length)
     114    {
     115      for (var siteNo = 0; siteNo < sites.length; siteNo++)
     116      {
     117        var site = sites[siteNo];
     118        frm.siteFilter[frm.siteFilter.length] = new Option(site.name + ' (' + siteCount[site.prefix]+')', site.prefix);
     119      }
    122120    }
    123121   
     
    145143      Events.addEventHandler(linkedFiles[fileNo], 'click', Files.viewFileOnClick);
    146144    }
     145   
     146    yellow.filterOnChange();
    147147
    148148  }
     
    177177  }
    178178 
    179 
     179  yellow.completedDateFilterOnChange = function()
     180  {
     181    var frm = document.forms['reggie'];
     182    var url = '../YellowLabel.servlet?ID='+App.getSessionId();
     183    var completedDate = frm.completedDateFilter.value.replace(/\-/g, '');
     184    url += '&cmd=LoadActiveYellowSpecimen&completedDateFilter='+encodeURIComponent(completedDate);
     185    Wizard.showLoadingAnimation('Loading YellowLabel specimen...');
     186    Wizard.asyncJsonRequest(url, yellow.onSpecimenLoaded);
     187  }
     188 
    180189  yellow.filterOnChange = function()
    181190  {
     
    431440/**
    432441  Functions for extracting various properties from
    433   RNA items. Each method accepts a single RNA as a parameter
    434   and return a value from the RNA item. The methods
     442  specimen items. Each method accepts a single specimen as a parameter
     443  and return a value from the specimen item. The methods
    435444  are used as parameters to Filter.add*Criteria() methods.
    436445*/
     
    540549  cmp.gt = function(v1, v2)
    541550  {
    542     return v1 >= v2;
     551    return v1 != null && v2 != null && v1 >= v2;
    543552  }
    544553 
     
    546555  cmp.lt = function(v1, v2)
    547556  {
    548     return v1 <= v2;
     557    return v1 != null && v2 != null && v1 <= v2;
    549558  }
    550559 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/YellowLabelServlet.java

    r3810 r3814  
    2222import net.sf.basedb.core.Item;
    2323import net.sf.basedb.core.ItemQuery;
     24import net.sf.basedb.core.Operator;
    2425import net.sf.basedb.core.RawBioAssay;
    2526import net.sf.basedb.core.Sample;
     
    2829import net.sf.basedb.core.plugin.ExportOutputStream;
    2930import net.sf.basedb.core.query.Annotations;
     31import net.sf.basedb.core.query.Expression;
    3032import net.sf.basedb.core.query.Expressions;
    3133import net.sf.basedb.core.query.Hql;
    3234import net.sf.basedb.core.query.Orders;
     35import net.sf.basedb.core.query.Restriction;
    3336import net.sf.basedb.core.query.Restrictions;
    3437import net.sf.basedb.core.snapshot.SnapshotManager;
     
    8487      {
    8588        dc = sc.newDbControl();
    86        
    8789        ItemQuery<Sample> query = Sample.getQuery();
    8890        Subtype.SPECIMEN.addFilter(dc, query);
     
    9092        query.join(Annotations.innerJoin(Annotationtype.YELLOW_LABEL.get(dc), "yl"));
    9193        query.join(Annotations.innerJoin(Annotationtype.ARRIVAL_DATE.get(dc), "ad"));
    92         // Not completed or completed with last 48 hours
    93         long twoDaysAgo = System.currentTimeMillis()-48*3600*1000;
    9494        query.join(Annotations.leftJoin(Annotationtype.COMPLETED_DATE.get(dc), "cd"));
    95         query.restrict(
    96           Restrictions.or(
    97             Restrictions.eq(Hql.alias("cd"), null),
    98             Restrictions.gteq(Hql.alias("cd"), Expressions.parameter("recent", new Date(twoDaysAgo),  Type.DATE))
    99         ));
     95       
     96        String completedDateFilter = Values.getStringOrNull(req.getParameter("completedDateFilter"));
     97        query.restrict(getCompletedDateRestriction(completedDateFilter));
     98       
    10099        query.order(Orders.asc(Hql.alias("ad")));
    101100        query.order(Orders.asc(Hql.property("name")));
     
    265264      json.writeJSONString(resp.getWriter());
    266265    }
    267    
     266  }
     267
     268  /**
     269    Generate a filter restriction for the given completed date.
     270    * If not date is given, the restriction return items without a
     271      completed date or with a completed date within the last 2 days
     272    * Only the operators > and < are supported
     273    * The filter may be for a year only or for a year+month only
     274  */
     275  private Restriction getCompletedDateRestriction(String completedDateFilter)
     276  {
     277    Restriction r = null;
     278    if (completedDateFilter != null)
     279    {
     280      try
     281      {
     282        Operator op = Operator.EQ;
     283        String lastDateFilter = completedDateFilter;
     284        if (completedDateFilter.startsWith(">"))
     285        {
     286          // Later than given date
     287          completedDateFilter = completedDateFilter.substring(1);
     288          op = Operator.GTEQ;
     289          // Fill in month and day if needed
     290          if (completedDateFilter.length() == 4) completedDateFilter += "0101";
     291          if (completedDateFilter.length() == 6) completedDateFilter += "01";
     292        }
     293        else if (completedDateFilter.startsWith("<"))
     294        {
     295          // Before given date
     296          completedDateFilter = completedDateFilter.substring(1);
     297          op = Operator.LTEQ;
     298          // Fill in month and day if needed
     299          if (completedDateFilter.length() == 4) completedDateFilter += "0101";
     300          if (completedDateFilter.length() == 6) completedDateFilter += "01";
     301        }
     302        else
     303        {
     304          if (completedDateFilter.length() == 4)
     305          {
     306            // Only year is given, we check dates between 01/01 and 12/31
     307            op = Operator.BETWEEN;
     308            completedDateFilter += "0101";
     309            lastDateFilter += "1231";
     310          }
     311          else if (completedDateFilter.length() == 6)
     312          {
     313            // Only year+month is given, we check dates between 01 and 31
     314            op = Operator.BETWEEN;
     315            completedDateFilter += "01";
     316            lastDateFilter += "31";
     317          }
     318        }
     319        Date completedDate = Reggie.CONVERTER_STRING_TO_DATE.convert(completedDateFilter);
     320        if (op == Operator.BETWEEN)
     321        {
     322          Date lastDate = Reggie.CONVERTER_STRING_TO_DATE.convert(lastDateFilter);
     323          r = op.getRestriction(Hql.alias("cd"), new Expression[] { Expressions.parameter("completed", completedDate, Type.DATE), Expressions.parameter("lastCompleted", lastDate, Type.DATE)});
     324        }
     325        else
     326        {
     327          r = op.getRestriction(Hql.alias("cd"), Expressions.parameter("completed", completedDate, Type.DATE));
     328        }
     329      }
     330      catch (RuntimeException ex)
     331      {} // Ignore the filter
     332    }
     333    if (r == null)
     334    {
     335      // Default filter: not completed or completed with last two days
     336      long twoDaysAgo = System.currentTimeMillis()-48*3600*1000;
     337      r = Restrictions.or(
     338          Restrictions.eq(Hql.alias("cd"), null),
     339          Restrictions.gteq(Hql.alias("cd"), Expressions.parameter("twoDaysAgo", new Date(twoDaysAgo),  Type.DATE))
     340      );
     341    }
     342    return r;
    268343  }
    269344 
Note: See TracChangeset for help on using the changeset viewer.