Changeset 3911


Ignore:
Timestamp:
May 2, 2016, 8:51:56 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #883: Add support for progress reporting to the Reggie wizard API

Added progress reporter to the 'Sample source report' wizard. The "Missing sample data report" needed a bit of refactoring to get rid of multiple loops.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/reports/samplereportgenerator.js

    r2842 r3911  
    201201    url += '&bloodsamplefilter='+frm.bloodsamplefilter.value;
    202202
    203     Wizard.showLoadingAnimation('Generating report...');
     203    Wizard.showLoadingAnimation('Generating report...', frm.reporttype.value+'-progress');
    204204    Wizard.asyncJsonRequest(url, report.onReportGenerated);
    205205  }
  • extensions/net.sf.basedb.reggie/trunk/resources/reports/samplereportgenerator.jsp

    r2611 r3911  
    172172     
    173173    <div id="wizard-status"></div>
     174    <div id="wizard-progress"></div>
    174175
    175176    <table class="navigation" id="navigation">
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r3572 r3911  
    2323import net.sf.basedb.core.ItemSubtype;
    2424import net.sf.basedb.core.MeasuredBioMaterial;
     25import net.sf.basedb.core.ProgressReporter;
    2526import net.sf.basedb.core.Sample;
    2627import net.sf.basedb.core.SessionControl;
     28import net.sf.basedb.core.SimpleProgressReporter;
    2729import net.sf.basedb.core.query.Hql;
    2830import net.sf.basedb.core.query.Orders;
     
    7880   
    7981    final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr());
    80     DbControl dc = null;   
     82    DbControl dc = null;
     83    ProgressReporter progress = new SimpleProgressReporter(null);
     84   
    8185    dc = sc.newDbControl();       
    8286   
    8387    try
    8488    {
     89      sc.setSessionSetting(cmd+"-progress", progress);
    8590      if ("samplecount".equals(cmd))
    8691      {       
     
    166171        }
    167172
    168         json = createConsentCountReport(dc, json, startDate, endDate);
     173        json = createConsentCountReport(dc, json, startDate, endDate, progress);
    169174      }
    170175      else if ("patientcount".equals(cmd))
     
    205210        }
    206211
    207         json = createPatientCountReport(dc, json, startDate, endDate, viewType);
     212        json = createPatientCountReport(dc, json, startDate, endDate, viewType, progress);
    208213      }
    209214      else if ("overviewreport".equals(cmd))
     
    240245        }
    241246
    242         json = createOverviewReport(dc, json, startDate, endDate, bloodSampleFilter);
     247        json = createOverviewReport(dc, json, startDate, endDate, bloodSampleFilter, progress);
    243248      }
    244249      else if ("missingsampledatareport".equals(cmd))
     
    281286        }
    282287
    283         json = createMissingSampleDataReport(dc, json, startDate, endDate, sampleType, bloodSampleFilter);
     288        json = createMissingSampleDataReport(dc, json, startDate, endDate, sampleType, bloodSampleFilter, progress);
    284289      }
    285290    }
     
    295300    {
    296301      if (dc != null) dc.close();
     302      if (sc != null) sc.setSessionSetting(cmd+"-progress", null);
    297303      json.writeJSONString(resp.getWriter());
    298304    }
     
    450456   
    451457  @SuppressWarnings({ "unchecked"})
    452   private JSONObject createPatientCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType)
     458  private JSONObject createPatientCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String viewType, ProgressReporter progress)
    453459    throws ServletException, IOException
    454460  {
     
    469475    sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));
    470476    sampleQuery.setCacheResult(true);
     477   
     478    progress.display(1, "Loading samples...");
     479    long totalCount = sampleQuery.count(dc);
     480    long count = 0;
     481   
    471482    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
    472483                 
     
    481492    while (sampleIterator.hasNext())
    482493    {
     494      if (count % 100 == 0)
     495            {
     496        progress.display(5 + (int)((95 * count) / totalCount),
     497            "Processing " + Reggie.formatCount(count) + " of " + Reggie.formatCount(totalCount) + " items");
     498            }
     499      count++;
    483500      Sample s = sampleIterator.next();
    484501      BioMaterialEvent creationEvent = s.getCreationEvent();
     
    556573    jsonReport.put("latestDate", latestDateStr);
    557574    json.put("report", jsonReport);
     575    progress.display(100, "Done");
    558576    return json;
    559577  }
    560578   
    561579  @SuppressWarnings({ "unchecked"})
    562   private JSONObject createConsentCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate)
     580  private JSONObject createConsentCountReport(DbControl dc, JSONObject json, Date startDate, Date endDate, ProgressReporter progress)
    563581      throws ServletException, IOException
    564582  {
     
    579597    sampleQuery.setCacheResult(true);
    580598    //List<Sample> samples = sampleQuery.list(dc);
     599   
     600    progress.display(1, "Loading samples...");
     601    long totalCount = sampleQuery.count(dc);
     602    long count = 0;
     603   
    581604    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
    582605    // Use stored annotation snapshots for performance reasons
     
    677700    while (sampleIterator.hasNext())
    678701    {
     702      if (count % 100 == 0)
     703            {
     704        progress.display(5 + (int)((95 * count) / totalCount),
     705            "Processing " + Reggie.formatCount(count) + " of " + Reggie.formatCount(totalCount) + " items");
     706            }
     707      count++;
    679708      Sample s = sampleIterator.next();
    680709/*
     
    897926    jsonReport.put(permissionDeniedForPatientNameKey, permissionDeniedForPatientName);
    898927    json.put("report", jsonReport);
     928    progress.display(100, "Done");
    899929    return json;
    900930  }
    901931
    902932  @SuppressWarnings({ "unchecked" })
    903   private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String bloodSampleFilter)
     933  private JSONObject createOverviewReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String bloodSampleFilter, ProgressReporter progress)
    904934      throws ServletException, IOException
    905935  {
     
    921951    sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));
    922952    sampleQuery.setCacheResult(true);
     953   
     954    progress.display(1, "Loading samples...");
     955    long totalCount = sampleQuery.count(dc);
     956    long count = 0;
     957   
    923958    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);       
    924959    // Use stored annotation snapshots for performance reasons
     
    10311066    while (sampleIterator != null && sampleIterator.hasNext())
    10321067    {
     1068      if (count % 100 == 0)
     1069            {
     1070        progress.display(5 + (int)((95 * count) / totalCount),
     1071            "Processing " + Reggie.formatCount(count) + " of " + Reggie.formatCount(totalCount) + " items");
     1072            }
     1073      count++;
    10331074      Sample s = sampleIterator.next();
    10341075      BioMaterialEvent creationEvent = s.getCreationEvent();
     
    14681509    jsonReport.put("latestDate", latestDateStr);
    14691510    json.put("report", jsonReport);
     1511    progress.display(100, "Done");
    14701512    return json;
    14711513  }
    14721514
    14731515  @SuppressWarnings({ "unchecked" })
    1474   private JSONObject createMissingSampleDataReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String sampleType, String bloodSampleFilter)
     1516  private JSONObject createMissingSampleDataReport(DbControl dc, JSONObject json, Date startDate, Date endDate, String sampleType, String bloodSampleFilter, ProgressReporter progress)
    14751517      throws ServletException, IOException
    14761518  {
    1477     List<Sample> sampleList = createSampleListForMissingSampleDataReport(dc, sampleType, bloodSampleFilter);
    1478     // Use stored annotation snapshots for performance reasons
    1479     SnapshotManager manager = new SnapshotManager();       
    1480 
     1519    ItemQuery<Sample> sampleQuery = Sample.getQuery();
     1520    sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
     1521    // Select what sample subtype to include in database search
     1522    // Fetch Joining parent CASE and PATIENT should improve performance
     1523    if (sampleType.equals("nospecimen"))
     1524    {
     1525      Subtype.NO_SPECIMEN.addFilter(dc, sampleQuery);
     1526      sampleQuery.join(Hql.innerJoin(null, "parent", "cse", true));
     1527      sampleQuery.join(Hql.innerJoin("cse", "parent", "pat", true));
     1528    }
     1529    else if (sampleType.equals("blood"))
     1530    {
     1531      Subtype.BLOOD.addFilter(dc, sampleQuery);
     1532      sampleQuery.join(Hql.innerJoin(null, "parent", "pat", true));
     1533    }
     1534    else
     1535    {
     1536      Subtype.SPECIMEN.addFilter(dc, sampleQuery);
     1537      sampleQuery.join(Hql.innerJoin(null, "parent", "cse", true));
     1538      sampleQuery.join(Hql.innerJoin("cse", "parent", "pat", true));
     1539    }
     1540    sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     1541    sampleQuery.order(Orders.asc(Hql.property("name")));
     1542    sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));
     1543    sampleQuery.setCacheResult(true);
     1544   
     1545    progress.display(1, "Loading samples...");
     1546    long totalCount = sampleQuery.count(dc);
     1547    long count = 0;
     1548   
    14811549    JSONObject jsonReport = new JSONObject();
    14821550    jsonReport.put("sites", ReportTableUtil.getJSONSites(Site.SORT_BY_NAME));
     
    15411609    }
    15421610   
    1543     //
    1544     for (Sample s: sampleList)
    1545     {
    1546       BioMaterialEvent creationEvent = s.getCreationEvent();
    1547       Date creationDate = creationEvent.getEventDate();
    1548 
    1549       // Find patient id
    1550       BioMaterial patient = null;
    1551       if (s.getItemSubtype().equals(subtypeBlood))
    1552       {
    1553         // The parent is the 'Patient' for blood samples and cases
    1554         patient = s.getParent();
    1555       }
    1556       else if (s.getItemSubtype().equals(subtypeSpecimen) || s.getItemSubtype().equals(subtypeNoSpecimen))
    1557       {
    1558         // The grandparent is the 'Patient' for specimens and no specimens
    1559         MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent();
    1560         if (parent != null)
    1561         {
    1562           patient = parent.getParent();
    1563         }
    1564       }
    1565 
    1566       // Initialize sample data
    1567       String allFirstNames = null;
    1568       String familyName = null;
    1569       String pad = null;
    1570       String laterality = null;
    1571       Date samplingDate = null;
    1572       Date rnaLaterDate = null;
    1573       Date bloodSamplingDate = null;
    1574       Date bloodFreezerDate = null;
    1575 
    1576       if (patient != null)
    1577       {
    1578         if (!permissionDeniedForPatientName)
    1579         {
    1580           // Get patient all first names
    1581           allFirstNames = (String) Annotationtype.ALL_FIRST_NAMES.getAnnotationValue(dc, manager, patient);
    1582           // Get patient family name
    1583           familyName = (String) Annotationtype.FAMILY_NAME.getAnnotationValue(dc, manager, patient);
    1584         }
    1585       }
    1586       if (sampleType.equals("specimen"))
    1587       {
    1588         // Get PAD reference
    1589         if (!permissionDeniedForPad)
    1590         {
    1591           pad = (String) Annotationtype.PAD.getAnnotationValue(dc, manager, s);
    1592         }
    1593         // Get laterality
    1594         laterality = (String) Annotationtype.LATERALITY.getAnnotationValue(dc, manager, s);
    1595         // Get sampling date
    1596         samplingDate = (Date) Annotationtype.SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
    1597         // Get RNALater date
    1598         rnaLaterDate = (Date) Annotationtype.RNALATER_DATETIME.getAnnotationValue(dc, manager, s);
    1599       }
    1600       else if (sampleType.equals("nospecimen"))
    1601       {
    1602         // Get PAD reference
    1603         if (!permissionDeniedForPad)
    1604         {
    1605           pad = (String) Annotationtype.PAD.getAnnotationValue(dc, manager, s);
    1606         }
    1607         // Get laterality
    1608         laterality = (String) Annotationtype.LATERALITY.getAnnotationValue(dc, manager, s);
    1609         // Get sampling date
    1610         samplingDate = (Date) Annotationtype.SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
    1611       }
    1612       else if (sampleType.equals("blood"))
    1613       {
    1614         // Get blood sampling date
    1615         bloodSamplingDate = (Date) Annotationtype.BLOOD_SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
    1616         // Get blood freezer date
    1617         bloodFreezerDate = (Date) Annotationtype.BLOOD_FREEZER_DATETIME.getAnnotationValue(dc, manager, s);
    1618       }
    1619       // Update statistics for sample type
    1620       Site site = Site.findByCaseName(s.getName());
    1621       if (site == Site.UNKNOWN)
    1622       {
    1623         String key = "unknownSite";
    1624         jsonStatistics = tableUtil.updateJSONObjectCounter(jsonStatistics, key);
    1625       }
    1626       else
    1627       {
    1628         // Get site info           
    1629         JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix());
    1630         if (jsonSite == null)
    1631         {
    1632           jsonSite = new JSONObject();
    1633           jsonStatistics.put(site.getPrefix(), jsonSite);
    1634         }
    1635 
    1636         if (patient != null && !permissionDeniedForPatientName)
    1637         {
    1638           // Update missing patient name data, provided the user has permission to check it
    1639           if (allFirstNames == null || allFirstNames.equals("")
    1640               || familyName == null || familyName.equals(""))
    1641           {
    1642             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPatientNameKey);
    1643             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPatientNameKey);
     1611   
     1612    ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);
     1613   
     1614    // Use stored annotation snapshots for performance reasons
     1615    SnapshotManager manager = new SnapshotManager();       
     1616    while (sampleIterator.hasNext())
     1617    {
     1618      if (count % 100 == 0)
     1619            {
     1620        progress.display(5 + (int)((95 * count) / totalCount),
     1621            "Processing " + Reggie.formatCount(count) + " of " + Reggie.formatCount(totalCount) + " items");
     1622            }
     1623      count++;
     1624      Sample s = sampleIterator.next();
     1625      // Optional blood sample filter (true if no filter, sample not blood, or blood sample passes filter)
     1626      boolean passedBloodSampleFilter = passBloodSampleFilter(dc, manager, bloodSampleFilter, s);
     1627      if (passedBloodSampleFilter)
     1628      {
     1629        BioMaterialEvent creationEvent = s.getCreationEvent();
     1630        Date creationDate = creationEvent.getEventDate();
     1631
     1632        // Find patient id
     1633        BioMaterial patient = null;
     1634        if (s.getItemSubtype().equals(subtypeBlood))
     1635        {
     1636          // The parent is the 'Patient' for blood samples and cases
     1637          patient = s.getParent();
     1638        }
     1639        else if (s.getItemSubtype().equals(subtypeSpecimen) || s.getItemSubtype().equals(subtypeNoSpecimen))
     1640        {
     1641          // The grandparent is the 'Patient' for specimens and no specimens
     1642          MeasuredBioMaterial parent = (MeasuredBioMaterial) s.getParent();
     1643          if (parent != null)
     1644          {
     1645            patient = parent.getParent();
     1646          }
     1647        }
     1648
     1649        // Initialize sample data
     1650        String allFirstNames = null;
     1651        String familyName = null;
     1652        String pad = null;
     1653        String laterality = null;
     1654        Date samplingDate = null;
     1655        Date rnaLaterDate = null;
     1656        Date bloodSamplingDate = null;
     1657        Date bloodFreezerDate = null;
     1658
     1659        if (patient != null)
     1660        {
     1661          if (!permissionDeniedForPatientName)
     1662          {
     1663            // Get patient all first names
     1664            allFirstNames = (String) Annotationtype.ALL_FIRST_NAMES.getAnnotationValue(dc, manager, patient);
     1665            // Get patient family name
     1666            familyName = (String) Annotationtype.FAMILY_NAME.getAnnotationValue(dc, manager, patient);
    16441667          }
    16451668        }
    16461669        if (sampleType.equals("specimen"))
    16471670        {
    1648           // Update missing PAD reference data
     1671          // Get PAD reference
    16491672          if (!permissionDeniedForPad)
    16501673          {
    1651             if (pad == null || pad.equals(""))
    1652             {
    1653               jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPadReferenceKey);
    1654               jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPadReferenceKey);
    1655             }
    1656           }
    1657           // Update missing laterality data
    1658           if (laterality == null || laterality.equals(""))
    1659           {
    1660             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingLateralityKey);
    1661             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingLateralityKey);
    1662           }
    1663           // Update missing sampling date data
    1664           if (samplingDate == null)
    1665           {
    1666             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingSamplingDateTimeKey);
    1667             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingSamplingDateTimeKey);
    1668           }
    1669           // Update missing RNALater date data
    1670           if (rnaLaterDate == null)
    1671           {
    1672             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingRnaLaterDateTimeKey);
    1673             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingRnaLaterDateTimeKey);
    1674           }
     1674            pad = (String) Annotationtype.PAD.getAnnotationValue(dc, manager, s);
     1675          }
     1676          // Get laterality
     1677          laterality = (String) Annotationtype.LATERALITY.getAnnotationValue(dc, manager, s);
     1678          // Get sampling date
     1679          samplingDate = (Date) Annotationtype.SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
     1680          // Get RNALater date
     1681          rnaLaterDate = (Date) Annotationtype.RNALATER_DATETIME.getAnnotationValue(dc, manager, s);
    16751682        }
    16761683        else if (sampleType.equals("nospecimen"))
    16771684        {
    1678           // Update missing PAD reference data
     1685          // Get PAD reference
    16791686          if (!permissionDeniedForPad)
    16801687          {
    1681             if (pad == null || pad.equals(""))
    1682             {
    1683               jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPadReferenceKey);
    1684               jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPadReferenceKey);
    1685             }
    1686           }
    1687           // Update missing laterality data
    1688           if (laterality == null || laterality.equals(""))
    1689           {
    1690             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingLateralityKey);
    1691             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingLateralityKey);
    1692           }
    1693           // Update missing sampling date data
    1694           if (samplingDate == null)
    1695           {
    1696             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingSamplingDateTimeKey);
    1697             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingSamplingDateTimeKey);
    1698           }
     1688            pad = (String) Annotationtype.PAD.getAnnotationValue(dc, manager, s);
     1689          }
     1690          // Get laterality
     1691          laterality = (String) Annotationtype.LATERALITY.getAnnotationValue(dc, manager, s);
     1692          // Get sampling date
     1693          samplingDate = (Date) Annotationtype.SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
    16991694        }
    17001695        else if (sampleType.equals("blood"))
    17011696        {
    1702           // Update missing blood sampling date data
    1703           if (bloodSamplingDate == null)
    1704           {
    1705             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingBloodSamplingDateTimeKey);
    1706             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingBloodSamplingDateTimeKey);
    1707           }
    1708           // Update missing blood freezer date data
    1709           if (bloodFreezerDate == null)
    1710           {
    1711             jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingBloodFreezerDateTimeKey);
    1712             jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingBloodFreezerDateTimeKey);
    1713           }
    1714         }
    1715 
    1716         // Keep track of latest item date for site
    1717         if (creationDate != null)
    1718         {
    1719           Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());
    1720           if (siteLatestDate == null || siteLatestDate.before(creationDate))
    1721           {
    1722             sitePrefixDateHashMap.put(site.getPrefix(), creationDate);
    1723           }
    1724           // Keep track of latest item date so far
    1725           if (latestDate == null || latestDate.before(creationDate))
    1726           {
    1727             latestDate = creationDate;
    1728           }
    1729         }
    1730       }
    1731     }
     1697          // Get blood sampling date
     1698          bloodSamplingDate = (Date) Annotationtype.BLOOD_SAMPLING_DATETIME.getAnnotationValue(dc, manager, s);
     1699          // Get blood freezer date
     1700          bloodFreezerDate = (Date) Annotationtype.BLOOD_FREEZER_DATETIME.getAnnotationValue(dc, manager, s);
     1701        }
     1702        // Update statistics for sample type
     1703        Site site = Site.findByCaseName(s.getName());
     1704        if (site == Site.UNKNOWN)
     1705        {
     1706          String key = "unknownSite";
     1707          jsonStatistics = tableUtil.updateJSONObjectCounter(jsonStatistics, key);
     1708        }
     1709        else
     1710        {
     1711          // Get site info           
     1712          JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix());
     1713          if (jsonSite == null)
     1714          {
     1715            jsonSite = new JSONObject();
     1716            jsonStatistics.put(site.getPrefix(), jsonSite);
     1717          }
     1718
     1719          if (patient != null && !permissionDeniedForPatientName)
     1720          {
     1721            // Update missing patient name data, provided the user has permission to check it
     1722            if (allFirstNames == null || allFirstNames.equals("")
     1723                || familyName == null || familyName.equals(""))
     1724            {
     1725              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPatientNameKey);
     1726              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPatientNameKey);
     1727            }
     1728          }
     1729          if (sampleType.equals("specimen"))
     1730          {
     1731            // Update missing PAD reference data
     1732            if (!permissionDeniedForPad)
     1733            {
     1734              if (pad == null || pad.equals(""))
     1735              {
     1736                jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPadReferenceKey);
     1737                jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPadReferenceKey);
     1738              }
     1739            }
     1740            // Update missing laterality data
     1741            if (laterality == null || laterality.equals(""))
     1742            {
     1743              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingLateralityKey);
     1744              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingLateralityKey);
     1745            }
     1746            // Update missing sampling date data
     1747            if (samplingDate == null)
     1748            {
     1749              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingSamplingDateTimeKey);
     1750              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingSamplingDateTimeKey);
     1751            }
     1752            // Update missing RNALater date data
     1753            if (rnaLaterDate == null)
     1754            {
     1755              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingRnaLaterDateTimeKey);
     1756              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingRnaLaterDateTimeKey);
     1757            }
     1758          }
     1759          else if (sampleType.equals("nospecimen"))
     1760          {
     1761            // Update missing PAD reference data
     1762            if (!permissionDeniedForPad)
     1763            {
     1764              if (pad == null || pad.equals(""))
     1765              {
     1766                jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingPadReferenceKey);
     1767                jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingPadReferenceKey);
     1768              }
     1769            }
     1770            // Update missing laterality data
     1771            if (laterality == null || laterality.equals(""))
     1772            {
     1773              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingLateralityKey);
     1774              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingLateralityKey);
     1775            }
     1776            // Update missing sampling date data
     1777            if (samplingDate == null)
     1778            {
     1779              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingSamplingDateTimeKey);
     1780              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingSamplingDateTimeKey);
     1781            }
     1782          }
     1783          else if (sampleType.equals("blood"))
     1784          {
     1785            // Update missing blood sampling date data
     1786            if (bloodSamplingDate == null)
     1787            {
     1788              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingBloodSamplingDateTimeKey);
     1789              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingBloodSamplingDateTimeKey);
     1790            }
     1791            // Update missing blood freezer date data
     1792            if (bloodFreezerDate == null)
     1793            {
     1794              jsonSite = tableUtil.updateJSONObjectCounter(jsonSite, missingBloodFreezerDateTimeKey);
     1795              jsonSitesCombined = tableUtil.updateJSONObjectCounter(jsonSitesCombined, missingBloodFreezerDateTimeKey);
     1796            }
     1797          }
     1798
     1799          // Keep track of latest item date for site
     1800          if (creationDate != null)
     1801          {
     1802            Date siteLatestDate = sitePrefixDateHashMap.get(site.getPrefix());
     1803            if (siteLatestDate == null || siteLatestDate.before(creationDate))
     1804            {
     1805              sitePrefixDateHashMap.put(site.getPrefix(), creationDate);
     1806            }
     1807            // Keep track of latest item date so far
     1808            if (latestDate == null || latestDate.before(creationDate))
     1809            {
     1810              latestDate = creationDate;
     1811            }
     1812          }
     1813        }
     1814       
     1815      }
     1816    }
     1817
     1818
    17321819    // Add latest item date for site to site JSON object
    17331820    DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
     
    17571844    jsonReport.put(permissionDeniedForPadKey, permissionDeniedForPad);
    17581845    json.put("report", jsonReport);
     1846    progress.display(100, "Done");
    17591847    return json;
    1760   }
    1761 
    1762   /**
    1763    * Creates sample list for missing sample data report.
    1764    *
    1765    * @param dc DbControl The DbControl to use.
    1766    * @param sampleType String The sample type for included samples.
    1767    * @param bloodSampleFilter String Optional blood sample filter.
    1768    * @return List<Sample> Sample list for missing sample data report.
    1769    * @throws ServletException
    1770    * @throws IOException
    1771    */
    1772   private List<Sample> createSampleListForMissingSampleDataReport(DbControl dc, String sampleType, String bloodSampleFilter)
    1773       throws ServletException, IOException
    1774   {
    1775     ItemQuery<Sample> sampleQuery = Sample.getQuery();
    1776     sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
    1777     // Select what sample subtype to include in database search
    1778     // Fetch Joining parent CASE and PATIENT should improve performance
    1779     if (sampleType.equals("nospecimen"))
    1780     {
    1781       Subtype.NO_SPECIMEN.addFilter(dc, sampleQuery);
    1782       sampleQuery.join(Hql.innerJoin(null, "parent", "cse", true));
    1783       sampleQuery.join(Hql.innerJoin("cse", "parent", "pat", true));
    1784     }
    1785     else if (sampleType.equals("blood"))
    1786     {
    1787       Subtype.BLOOD.addFilter(dc, sampleQuery);
    1788       sampleQuery.join(Hql.innerJoin(null, "parent", "pat", true));
    1789     }
    1790     else
    1791     {
    1792       Subtype.SPECIMEN.addFilter(dc, sampleQuery);
    1793       sampleQuery.join(Hql.innerJoin(null, "parent", "cse", true));
    1794       sampleQuery.join(Hql.innerJoin("cse", "parent", "pat", true));
    1795     }
    1796     sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    1797     sampleQuery.order(Orders.asc(Hql.property("name")));
    1798     sampleQuery.order(Orders.asc(Hql.property("ce", "eventDate")));
    1799     sampleQuery.setCacheResult(true);
    1800     ItemResultIterator<Sample> sampleIterator = sampleQuery.iterate(dc);
    1801    
    1802     // Create sample list
    1803     List<Sample> sampleList = new ArrayList<Sample>();
    1804     // Use stored annotation snapshots for performance reasons
    1805     SnapshotManager manager = new SnapshotManager();       
    1806     while (sampleIterator != null && sampleIterator.hasNext())
    1807     {
    1808       Sample s = sampleIterator.next();
    1809       // Optional blood sample filter (true if no filter, sample not blood, or blood sample passes filter)
    1810       boolean passedBloodSampleFilter = passBloodSampleFilter(dc, manager, bloodSampleFilter, s);
    1811       if (passedBloodSampleFilter)
    1812       {
    1813         // Add sample to list
    1814         sampleList.add(s);
    1815       }
    1816     }
    1817     return sampleList;
    18181848  }
    18191849
Note: See TracChangeset for help on using the changeset viewer.