3779 |
10 Mar 16 |
nicklas |
1 |
package net.sf.basedb.reggie.servlet; |
3779 |
10 Mar 16 |
nicklas |
2 |
|
3779 |
10 Mar 16 |
nicklas |
3 |
import java.io.IOException; |
3789 |
17 Mar 16 |
nicklas |
4 |
import java.util.ArrayList; |
3784 |
16 Mar 16 |
nicklas |
5 |
import java.util.Date; |
4141 |
30 Sep 16 |
nicklas |
6 |
import java.util.HashSet; |
3780 |
10 Mar 16 |
nicklas |
7 |
import java.util.Iterator; |
4141 |
30 Sep 16 |
nicklas |
8 |
import java.util.Set; |
3779 |
10 Mar 16 |
nicklas |
9 |
import java.util.List; |
3779 |
10 Mar 16 |
nicklas |
10 |
|
3779 |
10 Mar 16 |
nicklas |
11 |
import javax.servlet.ServletException; |
3779 |
10 Mar 16 |
nicklas |
12 |
import javax.servlet.http.HttpServlet; |
3779 |
10 Mar 16 |
nicklas |
13 |
import javax.servlet.http.HttpServletRequest; |
3779 |
10 Mar 16 |
nicklas |
14 |
import javax.servlet.http.HttpServletResponse; |
3779 |
10 Mar 16 |
nicklas |
15 |
|
3779 |
10 Mar 16 |
nicklas |
16 |
import org.json.simple.JSONArray; |
3779 |
10 Mar 16 |
nicklas |
17 |
import org.json.simple.JSONObject; |
3779 |
10 Mar 16 |
nicklas |
18 |
|
3789 |
17 Mar 16 |
nicklas |
19 |
import net.sf.basedb.clients.web.util.ServletExportOutputStream; |
4188 |
28 Oct 16 |
nicklas |
20 |
import net.sf.basedb.core.AnyToAny; |
4188 |
28 Oct 16 |
nicklas |
21 |
import net.sf.basedb.core.ChangeHistory; |
3779 |
10 Mar 16 |
nicklas |
22 |
import net.sf.basedb.core.DbControl; |
4028 |
26 Jul 16 |
nicklas |
23 |
import net.sf.basedb.core.Directory; |
3779 |
10 Mar 16 |
nicklas |
24 |
import net.sf.basedb.core.Extract; |
3810 |
23 Mar 16 |
nicklas |
25 |
import net.sf.basedb.core.File; |
3782 |
11 Mar 16 |
nicklas |
26 |
import net.sf.basedb.core.Item; |
3779 |
10 Mar 16 |
nicklas |
27 |
import net.sf.basedb.core.ItemQuery; |
4188 |
28 Oct 16 |
nicklas |
28 |
import net.sf.basedb.core.ItemResultIterator; |
3814 |
23 Mar 16 |
nicklas |
29 |
import net.sf.basedb.core.Operator; |
4028 |
26 Jul 16 |
nicklas |
30 |
import net.sf.basedb.core.Path; |
4034 |
29 Jul 16 |
nicklas |
31 |
import net.sf.basedb.core.PluginExecutionRequest; |
4034 |
29 Jul 16 |
nicklas |
32 |
import net.sf.basedb.core.PluginResponse; |
3782 |
11 Mar 16 |
nicklas |
33 |
import net.sf.basedb.core.RawBioAssay; |
3779 |
10 Mar 16 |
nicklas |
34 |
import net.sf.basedb.core.Sample; |
3779 |
10 Mar 16 |
nicklas |
35 |
import net.sf.basedb.core.SessionControl; |
4141 |
30 Sep 16 |
nicklas |
36 |
import net.sf.basedb.core.SharedItem; |
3780 |
10 Mar 16 |
nicklas |
37 |
import net.sf.basedb.core.Type; |
4188 |
28 Oct 16 |
nicklas |
38 |
import net.sf.basedb.core.log.ChangeType; |
3789 |
17 Mar 16 |
nicklas |
39 |
import net.sf.basedb.core.plugin.ExportOutputStream; |
4034 |
29 Jul 16 |
nicklas |
40 |
import net.sf.basedb.core.plugin.Response; |
3779 |
10 Mar 16 |
nicklas |
41 |
import net.sf.basedb.core.query.Annotations; |
3814 |
23 Mar 16 |
nicklas |
42 |
import net.sf.basedb.core.query.Expression; |
3780 |
10 Mar 16 |
nicklas |
43 |
import net.sf.basedb.core.query.Expressions; |
3779 |
10 Mar 16 |
nicklas |
44 |
import net.sf.basedb.core.query.Hql; |
3779 |
10 Mar 16 |
nicklas |
45 |
import net.sf.basedb.core.query.Orders; |
3814 |
23 Mar 16 |
nicklas |
46 |
import net.sf.basedb.core.query.Restriction; |
3780 |
10 Mar 16 |
nicklas |
47 |
import net.sf.basedb.core.query.Restrictions; |
3779 |
10 Mar 16 |
nicklas |
48 |
import net.sf.basedb.core.snapshot.SnapshotManager; |
3779 |
10 Mar 16 |
nicklas |
49 |
import net.sf.basedb.reggie.JsonUtil; |
3779 |
10 Mar 16 |
nicklas |
50 |
import net.sf.basedb.reggie.Reggie; |
3779 |
10 Mar 16 |
nicklas |
51 |
import net.sf.basedb.reggie.Site; |
3782 |
11 Mar 16 |
nicklas |
52 |
import net.sf.basedb.reggie.XmlConfig; |
3779 |
10 Mar 16 |
nicklas |
53 |
import net.sf.basedb.reggie.counter.CounterService; |
3779 |
10 Mar 16 |
nicklas |
54 |
import net.sf.basedb.reggie.dao.Annotationtype; |
3780 |
10 Mar 16 |
nicklas |
55 |
import net.sf.basedb.reggie.dao.Library; |
3782 |
11 Mar 16 |
nicklas |
56 |
import net.sf.basedb.reggie.dao.Rawbioassay; |
4665 |
31 Jan 18 |
nicklas |
57 |
import net.sf.basedb.reggie.dao.Rawdatatype; |
3779 |
10 Mar 16 |
nicklas |
58 |
import net.sf.basedb.reggie.dao.ReggieRole; |
3780 |
10 Mar 16 |
nicklas |
59 |
import net.sf.basedb.reggie.dao.Rna; |
3827 |
05 Apr 16 |
nicklas |
60 |
import net.sf.basedb.reggie.dao.RnaQc; |
3779 |
10 Mar 16 |
nicklas |
61 |
import net.sf.basedb.reggie.dao.SpecimenTube; |
3779 |
10 Mar 16 |
nicklas |
62 |
import net.sf.basedb.reggie.dao.Subtype; |
3810 |
23 Mar 16 |
nicklas |
63 |
import net.sf.basedb.reggie.json.LoadMoreJson; |
3789 |
17 Mar 16 |
nicklas |
64 |
import net.sf.basedb.reggie.pdf.PdfCombiner; |
3789 |
17 Mar 16 |
nicklas |
65 |
import net.sf.basedb.reggie.pdf.PdfReportTemplate; |
3789 |
17 Mar 16 |
nicklas |
66 |
import net.sf.basedb.reggie.pdf.PdfToZipCombiner; |
3782 |
11 Mar 16 |
nicklas |
67 |
import net.sf.basedb.reggie.pdf.PilotReportWorker; |
3789 |
17 Mar 16 |
nicklas |
68 |
import net.sf.basedb.reggie.plugins.GeneReportsCombinerPlugin; |
4034 |
29 Jul 16 |
nicklas |
69 |
import net.sf.basedb.reggie.plugins.SetPermissionsForDeliveryPlugin; |
3789 |
17 Mar 16 |
nicklas |
70 |
import net.sf.basedb.util.Values; |
3779 |
10 Mar 16 |
nicklas |
71 |
import net.sf.basedb.util.error.ThrowableUtil; |
3779 |
10 Mar 16 |
nicklas |
72 |
|
3779 |
10 Mar 16 |
nicklas |
73 |
|
3779 |
10 Mar 16 |
nicklas |
74 |
public class YellowLabelServlet |
3779 |
10 Mar 16 |
nicklas |
75 |
extends HttpServlet |
3779 |
10 Mar 16 |
nicklas |
76 |
{ |
3779 |
10 Mar 16 |
nicklas |
77 |
|
3779 |
10 Mar 16 |
nicklas |
78 |
private static final long serialVersionUID = 6418083429277485013L; |
3779 |
10 Mar 16 |
nicklas |
79 |
|
3779 |
10 Mar 16 |
nicklas |
80 |
public YellowLabelServlet() |
3779 |
10 Mar 16 |
nicklas |
81 |
{} |
3779 |
10 Mar 16 |
nicklas |
82 |
|
3779 |
10 Mar 16 |
nicklas |
83 |
@Override |
3779 |
10 Mar 16 |
nicklas |
84 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) |
3779 |
10 Mar 16 |
nicklas |
85 |
throws ServletException, IOException |
3779 |
10 Mar 16 |
nicklas |
86 |
{ |
3779 |
10 Mar 16 |
nicklas |
87 |
String cmd = req.getParameter("cmd"); |
3779 |
10 Mar 16 |
nicklas |
88 |
JsonUtil.setJsonResponseHeaders(resp); |
3779 |
10 Mar 16 |
nicklas |
89 |
|
3779 |
10 Mar 16 |
nicklas |
90 |
JSONObject json = new JSONObject(); |
3779 |
10 Mar 16 |
nicklas |
91 |
json.put("status", "ok"); |
3779 |
10 Mar 16 |
nicklas |
92 |
|
3975 |
26 May 16 |
nicklas |
93 |
final SessionControl sc = Reggie.getSessionControl(req); |
3779 |
10 Mar 16 |
nicklas |
94 |
DbControl dc = null; |
3779 |
10 Mar 16 |
nicklas |
95 |
try |
3779 |
10 Mar 16 |
nicklas |
96 |
{ |
3815 |
23 Mar 16 |
nicklas |
97 |
if ("LoadSitesAndPermissions".equals(cmd)) |
3779 |
10 Mar 16 |
nicklas |
98 |
{ |
6336 |
16 Jun 21 |
nicklas |
99 |
dc = sc.newDbControl(":YellowLabel reporting"); |
3815 |
23 Mar 16 |
nicklas |
100 |
json.put("sites", ReportTableUtil.getJSONSites(Site.SORT_BY_NAME)); |
3815 |
23 Mar 16 |
nicklas |
101 |
json.put("permissions", JsonUtil.getPermissions(dc)); |
3815 |
23 Mar 16 |
nicklas |
102 |
} |
3815 |
23 Mar 16 |
nicklas |
103 |
else if ("LoadActiveYellowSpecimen".equals(cmd)) |
3815 |
23 Mar 16 |
nicklas |
104 |
{ |
6336 |
16 Jun 21 |
nicklas |
105 |
dc = sc.newDbControl(":YellowLabel reporting"); |
3779 |
10 Mar 16 |
nicklas |
106 |
ItemQuery<Sample> query = Sample.getQuery(); |
3779 |
10 Mar 16 |
nicklas |
107 |
Subtype.SPECIMEN.addFilter(dc, query); |
3779 |
10 Mar 16 |
nicklas |
108 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
3779 |
10 Mar 16 |
nicklas |
109 |
query.join(Annotations.innerJoin(Annotationtype.YELLOW_LABEL.get(dc), "yl")); |
3779 |
10 Mar 16 |
nicklas |
110 |
query.join(Annotations.innerJoin(Annotationtype.ARRIVAL_DATE.get(dc), "ad")); |
3784 |
16 Mar 16 |
nicklas |
111 |
query.join(Annotations.leftJoin(Annotationtype.COMPLETED_DATE.get(dc), "cd")); |
5334 |
28 Mar 19 |
nicklas |
112 |
query.restrict(Restrictions.like(Hql.property("bioWell.bioPlate.name"), Expressions.string("Sp%"))); |
3814 |
23 Mar 16 |
nicklas |
113 |
|
3814 |
23 Mar 16 |
nicklas |
114 |
String completedDateFilter = Values.getStringOrNull(req.getParameter("completedDateFilter")); |
3814 |
23 Mar 16 |
nicklas |
115 |
query.restrict(getCompletedDateRestriction(completedDateFilter)); |
3814 |
23 Mar 16 |
nicklas |
116 |
|
3779 |
10 Mar 16 |
nicklas |
117 |
query.order(Orders.asc(Hql.alias("ad"))); |
3779 |
10 Mar 16 |
nicklas |
118 |
query.order(Orders.asc(Hql.property("name"))); |
3779 |
10 Mar 16 |
nicklas |
119 |
|
3779 |
10 Mar 16 |
nicklas |
120 |
SnapshotManager manager = new SnapshotManager(); |
3779 |
10 Mar 16 |
nicklas |
121 |
List<SpecimenTube> result = SpecimenTube.toList(query.list(dc)); |
3779 |
10 Mar 16 |
nicklas |
122 |
JSONArray jsonSpecimen = new JSONArray(); |
3779 |
10 Mar 16 |
nicklas |
123 |
for (SpecimenTube sp : result) |
3779 |
10 Mar 16 |
nicklas |
124 |
{ |
3779 |
10 Mar 16 |
nicklas |
125 |
Site site = Site.findByCaseName(sp.getName()); |
3779 |
10 Mar 16 |
nicklas |
126 |
sp.loadAnnotations(dc, manager, "SamplingDate", Annotationtype.SAMPLING_DATETIME, Reggie.CONVERTER_DATE_TO_STRING); |
3779 |
10 Mar 16 |
nicklas |
127 |
sp.loadAnnotations(dc, manager, "ArrivalDate", Annotationtype.ARRIVAL_DATE, Reggie.CONVERTER_DATE_TO_STRING); |
4188 |
28 Oct 16 |
nicklas |
128 |
Date completedDate = (Date)Annotationtype.COMPLETED_DATE.getAnnotationValue(dc, manager, sp.getItem()); |
4188 |
28 Oct 16 |
nicklas |
129 |
sp.setAnnotation("CompletedDate", Reggie.CONVERTER_DATE_TO_STRING.convert(completedDate)); |
3826 |
05 Apr 16 |
nicklas |
130 |
|
3826 |
05 Apr 16 |
nicklas |
131 |
Sample theCase = (Sample)sp.getItem().getParent(); |
3826 |
05 Apr 16 |
nicklas |
132 |
sp.setAnnotation("ConsentDate", Reggie.CONVERTER_DATE_TO_STRING.convert((Date)Annotationtype.CONSENT_DATE.getAnnotationValue(dc, theCase))); |
3779 |
10 Mar 16 |
nicklas |
133 |
sp.setAnnotation("site", site.asJSONObject()); |
3779 |
10 Mar 16 |
nicklas |
134 |
|
3780 |
10 Mar 16 |
nicklas |
135 |
Rna rna = findLatestRnaForSpecimen(dc, sp.getName()); |
3780 |
10 Mar 16 |
nicklas |
136 |
if (rna != null) |
3780 |
10 Mar 16 |
nicklas |
137 |
{ |
3780 |
10 Mar 16 |
nicklas |
138 |
rna.loadAnnotations(dc, manager, "QiacubeDate", Annotationtype.QIACUBE_DATE, Reggie.CONVERTER_DATE_TO_STRING); |
3822 |
04 Apr 16 |
nicklas |
139 |
rna.loadAnnotations(dc, manager, "Flag", Annotationtype.FLAG, null); |
4993 |
02 Oct 18 |
nicklas |
140 |
rna.loadDoNotUseAnnotations(dc, manager); |
3780 |
10 Mar 16 |
nicklas |
141 |
sp.setAnnotation("rna", rna.asJSONObject()); |
3780 |
10 Mar 16 |
nicklas |
142 |
|
3827 |
05 Apr 16 |
nicklas |
143 |
RnaQc rnaQc = rna.findLastRnaQc(dc, manager); |
3827 |
05 Apr 16 |
nicklas |
144 |
if (rnaQc != null) |
3827 |
05 Apr 16 |
nicklas |
145 |
{ |
3827 |
05 Apr 16 |
nicklas |
146 |
rnaQc.loadAnnotations(dc, manager, "RIN", Annotationtype.BA_RIN, null); |
3827 |
05 Apr 16 |
nicklas |
147 |
rnaQc.loadAnnotations(dc, manager, "RQS", Annotationtype.CA_RQS, null); |
3827 |
05 Apr 16 |
nicklas |
148 |
sp.setAnnotation("rnaqc", rnaQc.asJSONObject()); |
3827 |
05 Apr 16 |
nicklas |
149 |
} |
3827 |
05 Apr 16 |
nicklas |
150 |
|
3780 |
10 Mar 16 |
nicklas |
// Use the RNA name here so we don't get a Library from a different RNA |
3780 |
10 Mar 16 |
nicklas |
152 |
Library lib = findLatestLibraryForSpecimen(dc, rna.getName()); |
3780 |
10 Mar 16 |
nicklas |
153 |
if (lib != null) |
3780 |
10 Mar 16 |
nicklas |
154 |
{ |
3780 |
10 Mar 16 |
nicklas |
155 |
lib.setAnnotation("creationDate", Reggie.CONVERTER_DATE_TO_STRING.convert(lib.getExtract().getCreationEvent().getEventDate())); |
3780 |
10 Mar 16 |
nicklas |
156 |
sp.setAnnotation("library", lib.asJSONObject()); |
3782 |
11 Mar 16 |
nicklas |
157 |
|
4665 |
31 Jan 18 |
nicklas |
158 |
Rawbioassay raw = findLatestRawBioAssayForLibrary(dc, lib, Rawdatatype.CUFFLINKS); |
3782 |
11 Mar 16 |
nicklas |
159 |
if (raw != null) |
3782 |
11 Mar 16 |
nicklas |
160 |
{ |
3782 |
11 Mar 16 |
nicklas |
161 |
RawBioAssay rba = raw.getRawBioAssay(); |
3782 |
11 Mar 16 |
nicklas |
162 |
raw.setAnnotation("creationDate", Reggie.CONVERTER_DATE_TO_STRING.convert(rba.getEntryDate())); |
4993 |
02 Oct 18 |
nicklas |
163 |
raw.loadDoNotUseAnnotations(dc, manager); |
3782 |
11 Mar 16 |
nicklas |
164 |
sp.setAnnotation("raw", raw.asJSONObject()); |
3782 |
11 Mar 16 |
nicklas |
165 |
|
3782 |
11 Mar 16 |
nicklas |
166 |
XmlConfig cfg = Reggie.getConfig(); |
3810 |
23 Mar 16 |
nicklas |
167 |
String pdfName = cfg.getConfig("rscript/pilot-report/pdf-name", null, PilotReportWorker.DEFAULT_PDF_NAME); |
3810 |
23 Mar 16 |
nicklas |
168 |
JSONObject jsonPilot = JsonUtil.loadLinkedItem(dc, rba, pdfName, Item.FILE, |
3810 |
23 Mar 16 |
nicklas |
169 |
new LoadMoreJson<File>() |
3810 |
23 Mar 16 |
nicklas |
170 |
{ |
3810 |
23 Mar 16 |
nicklas |
171 |
@Override |
3810 |
23 Mar 16 |
nicklas |
172 |
public void addMore(DbControl dc, JSONObject json, File file) |
3810 |
23 Mar 16 |
nicklas |
173 |
{ |
3810 |
23 Mar 16 |
nicklas |
174 |
json.put("lastUpdatedDate", Reggie.CONVERTER_DATE_TO_STRING.convert(file.getLastUpdate())); |
3810 |
23 Mar 16 |
nicklas |
175 |
} |
3810 |
23 Mar 16 |
nicklas |
176 |
|
3810 |
23 Mar 16 |
nicklas |
177 |
}); |
3782 |
11 Mar 16 |
nicklas |
178 |
if (jsonPilot != null) |
3782 |
11 Mar 16 |
nicklas |
179 |
{ |
3782 |
11 Mar 16 |
nicklas |
180 |
sp.setAnnotation("pilotReport", jsonPilot); |
4188 |
28 Oct 16 |
nicklas |
181 |
boolean pilotIsPublished = AnyToAny.exists(dc, sp.getItem(), pdfName); |
4188 |
28 Oct 16 |
nicklas |
182 |
jsonPilot.put("isPublished", pilotIsPublished); |
4188 |
28 Oct 16 |
nicklas |
183 |
|
4188 |
28 Oct 16 |
nicklas |
184 |
if (pilotIsPublished) |
4188 |
28 Oct 16 |
nicklas |
185 |
{ |
4188 |
28 Oct 16 |
nicklas |
186 |
ItemQuery<ChangeHistory> historyQuery = ChangeHistory.getHistoryOf(sp.getItem()); |
4188 |
28 Oct 16 |
nicklas |
187 |
historyQuery.restrict(Restrictions.eq(Hql.property("changeType"), Expressions.integer(ChangeType.DOWNLOAD.getValue()))); |
4188 |
28 Oct 16 |
nicklas |
188 |
historyQuery.order(Orders.desc(Hql.property("changeHistory.time"))); |
4188 |
28 Oct 16 |
nicklas |
189 |
historyQuery.setCacheResult(true); |
4188 |
28 Oct 16 |
nicklas |
190 |
historyQuery.setReturnTotalCount(true); |
4188 |
28 Oct 16 |
nicklas |
191 |
historyQuery.setMaxResults(1); |
4188 |
28 Oct 16 |
nicklas |
192 |
|
4188 |
28 Oct 16 |
nicklas |
193 |
ItemResultIterator<ChangeHistory> it = historyQuery.iterate(dc); |
4188 |
28 Oct 16 |
nicklas |
194 |
|
4188 |
28 Oct 16 |
nicklas |
195 |
long downloadCount = it.getTotalCount(); |
4188 |
28 Oct 16 |
nicklas |
196 |
jsonPilot.put("downloadCount", downloadCount); |
4188 |
28 Oct 16 |
nicklas |
197 |
if (downloadCount > 0) |
4188 |
28 Oct 16 |
nicklas |
198 |
{ |
4188 |
28 Oct 16 |
nicklas |
199 |
ChangeHistory ch = it.next(); |
4188 |
28 Oct 16 |
nicklas |
200 |
jsonPilot.put("downloadedDate", Reggie.CONVERTER_DATE_TO_STRING.convert(ch.getTime())); |
4188 |
28 Oct 16 |
nicklas |
201 |
} |
4188 |
28 Oct 16 |
nicklas |
202 |
} |
3782 |
11 Mar 16 |
nicklas |
203 |
} |
3782 |
11 Mar 16 |
nicklas |
204 |
} |
3780 |
10 Mar 16 |
nicklas |
205 |
} |
3780 |
10 Mar 16 |
nicklas |
206 |
} |
3780 |
10 Mar 16 |
nicklas |
207 |
|
3779 |
10 Mar 16 |
nicklas |
208 |
Sample specimen = sp.getSample(); |
3779 |
10 Mar 16 |
nicklas |
209 |
jsonSpecimen.add(sp.asJSONObject()); |
3779 |
10 Mar 16 |
nicklas |
210 |
} |
3779 |
10 Mar 16 |
nicklas |
211 |
|
3779 |
10 Mar 16 |
nicklas |
212 |
json.put("specimen", jsonSpecimen); |
3779 |
10 Mar 16 |
nicklas |
213 |
} |
3789 |
17 Mar 16 |
nicklas |
214 |
else if ("CreatePilotReportZip".equals(cmd)) |
3789 |
17 Mar 16 |
nicklas |
215 |
{ |
6336 |
16 Jun 21 |
nicklas |
216 |
dc = sc.newDbControl(":YellowLabel reporting"); |
3789 |
17 Mar 16 |
nicklas |
217 |
|
3789 |
17 Mar 16 |
nicklas |
218 |
ReggieRole.checkPermission(dc, "'" + cmd + "' wizard", ReggieRole.PATIENT_CURATOR, ReggieRole.ADMINISTRATOR); |
3789 |
17 Mar 16 |
nicklas |
219 |
|
3821 |
04 Apr 16 |
nicklas |
220 |
Date completedDate = Reggie.CONVERTER_STRING_TO_DATE.convert(req.getParameter("completedDate")); |
3821 |
04 Apr 16 |
nicklas |
221 |
if (completedDate != null) |
3821 |
04 Apr 16 |
nicklas |
222 |
{ |
3821 |
04 Apr 16 |
nicklas |
223 |
Integer[] ids = Values.getInt(req.getParameter("specimen").split(",")); |
3821 |
04 Apr 16 |
nicklas |
224 |
for (int id : ids) |
3821 |
04 Apr 16 |
nicklas |
225 |
{ |
3821 |
04 Apr 16 |
nicklas |
226 |
Sample specimen = Sample.getById(dc, id); |
3821 |
04 Apr 16 |
nicklas |
227 |
Annotationtype.COMPLETED_DATE.setAnnotationValue(dc, specimen, completedDate); |
3821 |
04 Apr 16 |
nicklas |
228 |
} |
3821 |
04 Apr 16 |
nicklas |
229 |
} |
3821 |
04 Apr 16 |
nicklas |
230 |
|
3823 |
04 Apr 16 |
nicklas |
231 |
String sitePrefix = Values.getStringOrNull(req.getParameter("site")); |
3823 |
04 Apr 16 |
nicklas |
232 |
Site commonSite = sitePrefix != null ? Site.findByCaseName(sitePrefix) : null; |
3823 |
04 Apr 16 |
nicklas |
233 |
|
3789 |
17 Mar 16 |
nicklas |
234 |
Integer[] ids = Values.getInt(req.getParameter("rawBioAssays").split(",")); |
3791 |
17 Mar 16 |
nicklas |
235 |
String password = Values.getStringOrNull(req.getParameter("password")); |
3789 |
17 Mar 16 |
nicklas |
236 |
|
3789 |
17 Mar 16 |
nicklas |
237 |
List<RawBioAssay> rawBioAssays = new ArrayList<RawBioAssay>(); |
3789 |
17 Mar 16 |
nicklas |
238 |
for (int id : ids) |
3789 |
17 Mar 16 |
nicklas |
239 |
{ |
3823 |
04 Apr 16 |
nicklas |
240 |
RawBioAssay raw = RawBioAssay.getById(dc, id); |
3823 |
04 Apr 16 |
nicklas |
241 |
Site site = Site.findByCaseName(raw.getName()); |
3823 |
04 Apr 16 |
nicklas |
// If all selected reports are from the same site we |
3823 |
04 Apr 16 |
nicklas |
// want to include the site name to the generated ZIP filename |
3823 |
04 Apr 16 |
nicklas |
244 |
if (commonSite == null) |
3823 |
04 Apr 16 |
nicklas |
245 |
{ |
3823 |
04 Apr 16 |
nicklas |
246 |
commonSite = site; |
3823 |
04 Apr 16 |
nicklas |
247 |
} |
3823 |
04 Apr 16 |
nicklas |
248 |
else if (commonSite != site) |
3823 |
04 Apr 16 |
nicklas |
249 |
{ |
3823 |
04 Apr 16 |
nicklas |
250 |
commonSite = Site.UNKNOWN; |
3823 |
04 Apr 16 |
nicklas |
251 |
} |
3823 |
04 Apr 16 |
nicklas |
252 |
rawBioAssays.add(raw); |
3789 |
17 Mar 16 |
nicklas |
253 |
} |
3789 |
17 Mar 16 |
nicklas |
254 |
|
3789 |
17 Mar 16 |
nicklas |
255 |
ExportOutputStream out = new ServletExportOutputStream(resp); |
3791 |
17 Mar 16 |
nicklas |
256 |
PdfCombiner pdf2Zip = new PdfToZipCombiner(out, password); |
3789 |
17 Mar 16 |
nicklas |
257 |
|
3789 |
17 Mar 16 |
nicklas |
258 |
out.setMimeType(pdf2Zip.getMimeType()); |
3823 |
04 Apr 16 |
nicklas |
259 |
String filename = PdfReportTemplate.PILOT_REPORT.getDefaultFilename().replace(".pdf", ""); |
3823 |
04 Apr 16 |
nicklas |
260 |
if (commonSite != null && commonSite != Site.UNKNOWN) |
3823 |
04 Apr 16 |
nicklas |
261 |
{ |
3823 |
04 Apr 16 |
nicklas |
// All reports are from the same site |
3823 |
04 Apr 16 |
nicklas |
263 |
filename += "-"+commonSite.getName().toLowerCase(); |
3823 |
04 Apr 16 |
nicklas |
264 |
} |
3823 |
04 Apr 16 |
nicklas |
265 |
filename += "-"+Reggie.CONVERTER_DATE_TO_STRING.convert(new Date()); |
3823 |
04 Apr 16 |
nicklas |
266 |
filename += ".zip"; |
3823 |
04 Apr 16 |
nicklas |
267 |
out.setFilename(pdf2Zip.getOutFilename(filename)); |
3789 |
17 Mar 16 |
nicklas |
268 |
|
3789 |
17 Mar 16 |
nicklas |
269 |
GeneReportsCombinerPlugin.PdfReportCombiner combiner = |
3789 |
17 Mar 16 |
nicklas |
270 |
new GeneReportsCombinerPlugin.PdfReportCombiner(PdfReportTemplate.PILOT_REPORT, pdf2Zip); |
3789 |
17 Mar 16 |
nicklas |
271 |
combiner.setIncludePersonalInformation(true); |
3789 |
17 Mar 16 |
nicklas |
272 |
combiner.combineReports(dc, rawBioAssays, null, null); |
3789 |
17 Mar 16 |
nicklas |
273 |
|
3821 |
04 Apr 16 |
nicklas |
274 |
dc.commit(); |
3789 |
17 Mar 16 |
nicklas |
275 |
pdf2Zip.close(); |
3789 |
17 Mar 16 |
nicklas |
276 |
out.flush(); |
3789 |
17 Mar 16 |
nicklas |
277 |
out.close(); |
3789 |
17 Mar 16 |
nicklas |
278 |
} |
3779 |
10 Mar 16 |
nicklas |
279 |
|
3779 |
10 Mar 16 |
nicklas |
280 |
} |
3779 |
10 Mar 16 |
nicklas |
281 |
catch (Throwable t) |
3779 |
10 Mar 16 |
nicklas |
282 |
{ |
3779 |
10 Mar 16 |
nicklas |
283 |
t.printStackTrace(); |
3779 |
10 Mar 16 |
nicklas |
284 |
json.clear(); |
3779 |
10 Mar 16 |
nicklas |
285 |
json.put("status", "error"); |
3779 |
10 Mar 16 |
nicklas |
286 |
json.put("message", t.getMessage()); |
3779 |
10 Mar 16 |
nicklas |
287 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
3779 |
10 Mar 16 |
nicklas |
288 |
} |
3779 |
10 Mar 16 |
nicklas |
289 |
finally |
3779 |
10 Mar 16 |
nicklas |
290 |
{ |
3779 |
10 Mar 16 |
nicklas |
291 |
if (dc != null) dc.close(); |
3779 |
10 Mar 16 |
nicklas |
292 |
json.writeJSONString(resp.getWriter()); |
3779 |
10 Mar 16 |
nicklas |
293 |
} |
3779 |
10 Mar 16 |
nicklas |
294 |
|
3779 |
10 Mar 16 |
nicklas |
295 |
} |
3779 |
10 Mar 16 |
nicklas |
296 |
|
3779 |
10 Mar 16 |
nicklas |
297 |
@Override |
3779 |
10 Mar 16 |
nicklas |
298 |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) |
3779 |
10 Mar 16 |
nicklas |
299 |
throws ServletException, IOException |
3779 |
10 Mar 16 |
nicklas |
300 |
{ |
3779 |
10 Mar 16 |
nicklas |
301 |
String cmd = req.getParameter("cmd"); |
3779 |
10 Mar 16 |
nicklas |
302 |
JsonUtil.setJsonResponseHeaders(resp); |
3779 |
10 Mar 16 |
nicklas |
303 |
|
3779 |
10 Mar 16 |
nicklas |
304 |
JSONObject json = new JSONObject(); |
3779 |
10 Mar 16 |
nicklas |
305 |
json.put("status", "ok"); |
3779 |
10 Mar 16 |
nicklas |
306 |
|
3779 |
10 Mar 16 |
nicklas |
307 |
JSONArray jsonMessages = new JSONArray(); |
3779 |
10 Mar 16 |
nicklas |
308 |
|
3975 |
26 May 16 |
nicklas |
309 |
final SessionControl sc = Reggie.getSessionControl(req); |
3779 |
10 Mar 16 |
nicklas |
310 |
DbControl dc = null; |
3779 |
10 Mar 16 |
nicklas |
311 |
try |
3779 |
10 Mar 16 |
nicklas |
312 |
{ |
3787 |
17 Mar 16 |
nicklas |
313 |
if ("MarkAsCompleted".equals(cmd)) |
3779 |
10 Mar 16 |
nicklas |
314 |
{ |
6336 |
16 Jun 21 |
nicklas |
315 |
dc = sc.newDbControl(":YellowLabel reporting"); |
3787 |
17 Mar 16 |
nicklas |
316 |
ReggieRole.checkPermission(dc, "'" + cmd + "' wizard", ReggieRole.PATIENT_CURATOR, ReggieRole.ADMINISTRATOR); |
3779 |
10 Mar 16 |
nicklas |
317 |
|
3779 |
10 Mar 16 |
nicklas |
318 |
JSONObject jsonReq = JsonUtil.parseRequest(req); |
3787 |
17 Mar 16 |
nicklas |
319 |
JSONArray jsonSpecimen = (JSONArray)jsonReq.get("specimen"); |
3824 |
04 Apr 16 |
nicklas |
320 |
JSONObject jsonOptions = (JSONObject)jsonReq.get("options"); |
3779 |
10 Mar 16 |
nicklas |
321 |
|
3824 |
04 Apr 16 |
nicklas |
322 |
Date completedDate = Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonOptions.get("completedDate")); |
4141 |
30 Sep 16 |
nicklas |
323 |
Set<SharedItem> itemsToPublish = new HashSet<>(); |
3824 |
04 Apr 16 |
nicklas |
324 |
|
3787 |
17 Mar 16 |
nicklas |
325 |
for (int spNo = 0; spNo < jsonSpecimen.size(); spNo++) |
3779 |
10 Mar 16 |
nicklas |
326 |
{ |
3787 |
17 Mar 16 |
nicklas |
327 |
JSONObject jsonSp = (JSONObject)jsonSpecimen.get(spNo); |
3787 |
17 Mar 16 |
nicklas |
328 |
Number spId = (Number)jsonSp.get("id"); |
3779 |
10 Mar 16 |
nicklas |
329 |
|
3787 |
17 Mar 16 |
nicklas |
330 |
Sample specimen = Sample.getById(dc, spId.intValue()); |
3824 |
04 Apr 16 |
nicklas |
331 |
Annotationtype.COMPLETED_DATE.setAnnotationValue(dc, specimen, completedDate); |
4141 |
30 Sep 16 |
nicklas |
332 |
itemsToPublish.add(specimen); |
3779 |
10 Mar 16 |
nicklas |
333 |
} |
3779 |
10 Mar 16 |
nicklas |
334 |
|
3824 |
04 Apr 16 |
nicklas |
335 |
jsonMessages.add(jsonSpecimen.size() + " specimen marked as completed on " + Reggie.CONVERTER_DATE_TO_STRING_WITH_SEPARATOR.convert(completedDate)); |
3779 |
10 Mar 16 |
nicklas |
336 |
dc.commit(); |
4141 |
30 Sep 16 |
nicklas |
337 |
|
4141 |
30 Sep 16 |
nicklas |
// Publish items to site |
4141 |
30 Sep 16 |
nicklas |
339 |
if (itemsToPublish.size() > 0) |
4141 |
30 Sep 16 |
nicklas |
340 |
{ |
6336 |
16 Jun 21 |
nicklas |
341 |
dc = sc.newDbControl(dc.getName()); |
4141 |
30 Sep 16 |
nicklas |
342 |
PluginExecutionRequest permissionChangeRequest = SetPermissionsForDeliveryPlugin.createExecutionRequest(dc, "YellowLabelServlet.MarkAsCompleted"); |
4141 |
30 Sep 16 |
nicklas |
343 |
permissionChangeRequest.setParameterValue("items", itemsToPublish); |
4141 |
30 Sep 16 |
nicklas |
344 |
PluginResponse response = permissionChangeRequest.invoke(); |
4141 |
30 Sep 16 |
nicklas |
345 |
if (response.getStatus() != Response.Status.DONE) |
4141 |
30 Sep 16 |
nicklas |
346 |
{ |
4141 |
30 Sep 16 |
nicklas |
347 |
jsonMessages.add("[Warning]Could not set permissions for specimen/case/patient to site (see below)"); |
4141 |
30 Sep 16 |
nicklas |
348 |
jsonMessages.add("[Warning]"+response.getMessage()); |
4141 |
30 Sep 16 |
nicklas |
349 |
} |
4141 |
30 Sep 16 |
nicklas |
350 |
dc.close(); |
4141 |
30 Sep 16 |
nicklas |
351 |
} |
4141 |
30 Sep 16 |
nicklas |
352 |
|
3779 |
10 Mar 16 |
nicklas |
353 |
} |
4028 |
26 Jul 16 |
nicklas |
354 |
else if ("PublishForDelivery".equals(cmd)) |
4028 |
26 Jul 16 |
nicklas |
355 |
{ |
6336 |
16 Jun 21 |
nicklas |
356 |
dc = sc.newDbControl(":YellowLabel reporting"); |
3779 |
10 Mar 16 |
nicklas |
357 |
|
4028 |
26 Jul 16 |
nicklas |
358 |
ReggieRole.checkPermission(dc, "'" + cmd + "' wizard", ReggieRole.PATIENT_CURATOR, ReggieRole.ADMINISTRATOR); |
4028 |
26 Jul 16 |
nicklas |
359 |
|
4028 |
26 Jul 16 |
nicklas |
360 |
JSONObject jsonReq = JsonUtil.parseRequest(req); |
4028 |
26 Jul 16 |
nicklas |
361 |
JSONArray jsonSpecimen = (JSONArray)jsonReq.get("specimen"); |
4028 |
26 Jul 16 |
nicklas |
362 |
JSONArray jsonRaw = (JSONArray)jsonReq.get("rawBioAssays"); |
4028 |
26 Jul 16 |
nicklas |
363 |
JSONObject jsonOptions = (JSONObject)jsonReq.get("options"); |
4028 |
26 Jul 16 |
nicklas |
364 |
|
4028 |
26 Jul 16 |
nicklas |
365 |
Date completedDate = Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonOptions.get("completedDate")); |
4141 |
30 Sep 16 |
nicklas |
366 |
Set<SharedItem> itemsToPublish = new HashSet<>(); |
4028 |
26 Jul 16 |
nicklas |
367 |
for (int spNo = 0; spNo < jsonSpecimen.size(); spNo++) |
4028 |
26 Jul 16 |
nicklas |
368 |
{ |
4028 |
26 Jul 16 |
nicklas |
369 |
JSONObject jsonSp = (JSONObject)jsonSpecimen.get(spNo); |
4028 |
26 Jul 16 |
nicklas |
370 |
Number spId = (Number)jsonSp.get("id"); |
4028 |
26 Jul 16 |
nicklas |
371 |
|
4028 |
26 Jul 16 |
nicklas |
372 |
Sample specimen = Sample.getById(dc, spId.intValue()); |
4043 |
01 Aug 16 |
nicklas |
373 |
Annotationtype.COMPLETED_DATE.setAnnotationValue(dc, specimen, completedDate); |
4141 |
30 Sep 16 |
nicklas |
374 |
itemsToPublish.add(specimen); |
4028 |
26 Jul 16 |
nicklas |
375 |
} |
4028 |
26 Jul 16 |
nicklas |
376 |
|
4028 |
26 Jul 16 |
nicklas |
377 |
List<RawBioAssay> rawBioAssays = new ArrayList<RawBioAssay>(); |
4028 |
26 Jul 16 |
nicklas |
378 |
for (int rawNo = 0; rawNo < jsonRaw.size(); rawNo++) |
4028 |
26 Jul 16 |
nicklas |
379 |
{ |
4028 |
26 Jul 16 |
nicklas |
380 |
JSONObject jsonR = (JSONObject)jsonRaw.get(rawNo); |
4028 |
26 Jul 16 |
nicklas |
381 |
Number rawId = (Number)jsonR.get("id"); |
4028 |
26 Jul 16 |
nicklas |
382 |
|
4028 |
26 Jul 16 |
nicklas |
383 |
RawBioAssay raw = RawBioAssay.getById(dc, rawId.intValue()); |
4028 |
26 Jul 16 |
nicklas |
384 |
rawBioAssays.add(raw); |
4028 |
26 Jul 16 |
nicklas |
385 |
} |
4028 |
26 Jul 16 |
nicklas |
386 |
|
4141 |
30 Sep 16 |
nicklas |
387 |
Directory deliveryRootDir = Directory.getNew(dc, new Path(Reggie.DELIVERY_DIR, Path.Type.DIRECTORY)); |
4141 |
30 Sep 16 |
nicklas |
388 |
DeliveryServlet.CombineForDelivery pdf2File = new DeliveryServlet.CombineForDelivery(dc, deliveryRootDir, PdfReportTemplate.PILOT_REPORT); |
4028 |
26 Jul 16 |
nicklas |
389 |
|
4028 |
26 Jul 16 |
nicklas |
390 |
GeneReportsCombinerPlugin.PdfReportCombiner combiner = |
4028 |
26 Jul 16 |
nicklas |
391 |
new GeneReportsCombinerPlugin.PdfReportCombiner(PdfReportTemplate.PILOT_REPORT, pdf2File); |
4028 |
26 Jul 16 |
nicklas |
392 |
combiner.setIncludePersonalInformation(true); |
4028 |
26 Jul 16 |
nicklas |
393 |
combiner.combineReports(dc, rawBioAssays, null, null); |
4034 |
29 Jul 16 |
nicklas |
394 |
pdf2File.close(); |
4034 |
29 Jul 16 |
nicklas |
395 |
dc.commit(); |
4028 |
26 Jul 16 |
nicklas |
396 |
|
4034 |
29 Jul 16 |
nicklas |
397 |
jsonMessages.add(jsonSpecimen.size() + " specimen marked as completed on " + Reggie.CONVERTER_DATE_TO_STRING_WITH_SEPARATOR.convert(completedDate)); |
4034 |
29 Jul 16 |
nicklas |
398 |
|
4034 |
29 Jul 16 |
nicklas |
// Publish items to site |
4141 |
30 Sep 16 |
nicklas |
400 |
if (itemsToPublish.size() > 0 || pdf2File.numberOfItemsToPublish() > 0) |
4034 |
29 Jul 16 |
nicklas |
401 |
{ |
4141 |
30 Sep 16 |
nicklas |
402 |
itemsToPublish.addAll(pdf2File.getItemsToPublish()); |
6336 |
16 Jun 21 |
nicklas |
403 |
dc = sc.newDbControl(dc.getName()); |
4141 |
30 Sep 16 |
nicklas |
404 |
PluginExecutionRequest permissionChangeRequest = SetPermissionsForDeliveryPlugin.createExecutionRequest(dc, "YellowLabelServlet.PublishForDelivery"); |
4141 |
30 Sep 16 |
nicklas |
405 |
permissionChangeRequest.setParameterValue("items", itemsToPublish); |
4034 |
29 Jul 16 |
nicklas |
406 |
PluginResponse response = permissionChangeRequest.invoke(); |
4034 |
29 Jul 16 |
nicklas |
407 |
if (response.getStatus() != Response.Status.DONE) |
4034 |
29 Jul 16 |
nicklas |
408 |
{ |
4034 |
29 Jul 16 |
nicklas |
409 |
jsonMessages.add("[Warning]The reports may not have been published correctly (see below)!"); |
4034 |
29 Jul 16 |
nicklas |
410 |
jsonMessages.add("[Warning]"+response.getMessage()); |
4034 |
29 Jul 16 |
nicklas |
411 |
} |
4034 |
29 Jul 16 |
nicklas |
412 |
else |
4034 |
29 Jul 16 |
nicklas |
413 |
{ |
4034 |
29 Jul 16 |
nicklas |
414 |
jsonMessages.add(rawBioAssays.size() + " reports has been published"); |
4034 |
29 Jul 16 |
nicklas |
415 |
} |
4034 |
29 Jul 16 |
nicklas |
416 |
dc.close(); |
4034 |
29 Jul 16 |
nicklas |
417 |
} |
4034 |
29 Jul 16 |
nicklas |
418 |
|
4028 |
26 Jul 16 |
nicklas |
419 |
} |
4028 |
26 Jul 16 |
nicklas |
420 |
|
3779 |
10 Mar 16 |
nicklas |
421 |
json.put("messages", jsonMessages); |
3779 |
10 Mar 16 |
nicklas |
422 |
CounterService.getInstance().setForceCount(); |
3779 |
10 Mar 16 |
nicklas |
423 |
} |
3779 |
10 Mar 16 |
nicklas |
424 |
catch (Throwable t) |
3779 |
10 Mar 16 |
nicklas |
425 |
{ |
3779 |
10 Mar 16 |
nicklas |
426 |
t.printStackTrace(); |
3779 |
10 Mar 16 |
nicklas |
427 |
json.clear(); |
3779 |
10 Mar 16 |
nicklas |
428 |
json.put("status", "error"); |
3779 |
10 Mar 16 |
nicklas |
429 |
json.put("message", t.getMessage()); |
3779 |
10 Mar 16 |
nicklas |
430 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
3779 |
10 Mar 16 |
nicklas |
431 |
} |
3779 |
10 Mar 16 |
nicklas |
432 |
finally |
3779 |
10 Mar 16 |
nicklas |
433 |
{ |
3779 |
10 Mar 16 |
nicklas |
434 |
if (dc != null) dc.close(); |
3779 |
10 Mar 16 |
nicklas |
435 |
json.writeJSONString(resp.getWriter()); |
3779 |
10 Mar 16 |
nicklas |
436 |
} |
3779 |
10 Mar 16 |
nicklas |
437 |
} |
3814 |
23 Mar 16 |
nicklas |
438 |
|
3814 |
23 Mar 16 |
nicklas |
439 |
/** |
3814 |
23 Mar 16 |
nicklas |
Generate a filter restriction for the given completed date. |
3814 |
23 Mar 16 |
nicklas |
* If not date is given, the restriction return items without a |
3814 |
23 Mar 16 |
nicklas |
completed date or with a completed date within the last 2 days |
3814 |
23 Mar 16 |
nicklas |
* Only the operators > and < are supported |
3814 |
23 Mar 16 |
nicklas |
* The filter may be for a year only or for a year+month only |
3814 |
23 Mar 16 |
nicklas |
445 |
*/ |
3814 |
23 Mar 16 |
nicklas |
446 |
private Restriction getCompletedDateRestriction(String completedDateFilter) |
3814 |
23 Mar 16 |
nicklas |
447 |
{ |
3814 |
23 Mar 16 |
nicklas |
448 |
Restriction r = null; |
3814 |
23 Mar 16 |
nicklas |
449 |
if (completedDateFilter != null) |
3814 |
23 Mar 16 |
nicklas |
450 |
{ |
3814 |
23 Mar 16 |
nicklas |
451 |
try |
3814 |
23 Mar 16 |
nicklas |
452 |
{ |
3814 |
23 Mar 16 |
nicklas |
453 |
Operator op = Operator.EQ; |
3814 |
23 Mar 16 |
nicklas |
454 |
String lastDateFilter = completedDateFilter; |
3814 |
23 Mar 16 |
nicklas |
455 |
if (completedDateFilter.startsWith(">")) |
3814 |
23 Mar 16 |
nicklas |
456 |
{ |
3814 |
23 Mar 16 |
nicklas |
// Later than given date |
3814 |
23 Mar 16 |
nicklas |
458 |
completedDateFilter = completedDateFilter.substring(1); |
3814 |
23 Mar 16 |
nicklas |
459 |
op = Operator.GTEQ; |
3814 |
23 Mar 16 |
nicklas |
// Fill in month and day if needed |
3814 |
23 Mar 16 |
nicklas |
461 |
if (completedDateFilter.length() == 4) completedDateFilter += "0101"; |
3814 |
23 Mar 16 |
nicklas |
462 |
if (completedDateFilter.length() == 6) completedDateFilter += "01"; |
3814 |
23 Mar 16 |
nicklas |
463 |
} |
3814 |
23 Mar 16 |
nicklas |
464 |
else if (completedDateFilter.startsWith("<")) |
3814 |
23 Mar 16 |
nicklas |
465 |
{ |
3814 |
23 Mar 16 |
nicklas |
// Before given date |
3814 |
23 Mar 16 |
nicklas |
467 |
completedDateFilter = completedDateFilter.substring(1); |
3814 |
23 Mar 16 |
nicklas |
468 |
op = Operator.LTEQ; |
3814 |
23 Mar 16 |
nicklas |
// Fill in month and day if needed |
3814 |
23 Mar 16 |
nicklas |
470 |
if (completedDateFilter.length() == 4) completedDateFilter += "0101"; |
3814 |
23 Mar 16 |
nicklas |
471 |
if (completedDateFilter.length() == 6) completedDateFilter += "01"; |
3814 |
23 Mar 16 |
nicklas |
472 |
} |
3814 |
23 Mar 16 |
nicklas |
473 |
else |
3814 |
23 Mar 16 |
nicklas |
474 |
{ |
3814 |
23 Mar 16 |
nicklas |
475 |
if (completedDateFilter.length() == 4) |
3814 |
23 Mar 16 |
nicklas |
476 |
{ |
3814 |
23 Mar 16 |
nicklas |
// Only year is given, we check dates between 01/01 and 12/31 |
3814 |
23 Mar 16 |
nicklas |
478 |
op = Operator.BETWEEN; |
3814 |
23 Mar 16 |
nicklas |
479 |
completedDateFilter += "0101"; |
3814 |
23 Mar 16 |
nicklas |
480 |
lastDateFilter += "1231"; |
3814 |
23 Mar 16 |
nicklas |
481 |
} |
3814 |
23 Mar 16 |
nicklas |
482 |
else if (completedDateFilter.length() == 6) |
3814 |
23 Mar 16 |
nicklas |
483 |
{ |
3814 |
23 Mar 16 |
nicklas |
// Only year+month is given, we check dates between 01 and 31 |
3814 |
23 Mar 16 |
nicklas |
485 |
op = Operator.BETWEEN; |
3814 |
23 Mar 16 |
nicklas |
486 |
completedDateFilter += "01"; |
3814 |
23 Mar 16 |
nicklas |
487 |
lastDateFilter += "31"; |
3814 |
23 Mar 16 |
nicklas |
488 |
} |
3814 |
23 Mar 16 |
nicklas |
489 |
} |
3814 |
23 Mar 16 |
nicklas |
490 |
Date completedDate = Reggie.CONVERTER_STRING_TO_DATE.convert(completedDateFilter); |
3814 |
23 Mar 16 |
nicklas |
491 |
if (op == Operator.BETWEEN) |
3814 |
23 Mar 16 |
nicklas |
492 |
{ |
3814 |
23 Mar 16 |
nicklas |
493 |
Date lastDate = Reggie.CONVERTER_STRING_TO_DATE.convert(lastDateFilter); |
3814 |
23 Mar 16 |
nicklas |
494 |
r = op.getRestriction(Hql.alias("cd"), new Expression[] { Expressions.parameter("completed", completedDate, Type.DATE), Expressions.parameter("lastCompleted", lastDate, Type.DATE)}); |
3814 |
23 Mar 16 |
nicklas |
495 |
} |
3814 |
23 Mar 16 |
nicklas |
496 |
else |
3814 |
23 Mar 16 |
nicklas |
497 |
{ |
3814 |
23 Mar 16 |
nicklas |
498 |
r = op.getRestriction(Hql.alias("cd"), Expressions.parameter("completed", completedDate, Type.DATE)); |
3814 |
23 Mar 16 |
nicklas |
499 |
} |
3814 |
23 Mar 16 |
nicklas |
500 |
} |
3814 |
23 Mar 16 |
nicklas |
501 |
catch (RuntimeException ex) |
3814 |
23 Mar 16 |
nicklas |
502 |
{} // Ignore the filter |
3814 |
23 Mar 16 |
nicklas |
503 |
} |
3814 |
23 Mar 16 |
nicklas |
504 |
if (r == null) |
3814 |
23 Mar 16 |
nicklas |
505 |
{ |
3814 |
23 Mar 16 |
nicklas |
// Default filter: not completed or completed with last two days |
3814 |
23 Mar 16 |
nicklas |
507 |
long twoDaysAgo = System.currentTimeMillis()-48*3600*1000; |
3814 |
23 Mar 16 |
nicklas |
508 |
r = Restrictions.or( |
3814 |
23 Mar 16 |
nicklas |
509 |
Restrictions.eq(Hql.alias("cd"), null), |
3814 |
23 Mar 16 |
nicklas |
510 |
Restrictions.gteq(Hql.alias("cd"), Expressions.parameter("twoDaysAgo", new Date(twoDaysAgo), Type.DATE)) |
3814 |
23 Mar 16 |
nicklas |
511 |
); |
3814 |
23 Mar 16 |
nicklas |
512 |
} |
3814 |
23 Mar 16 |
nicklas |
513 |
return r; |
3814 |
23 Mar 16 |
nicklas |
514 |
} |
3779 |
10 Mar 16 |
nicklas |
515 |
|
3780 |
10 Mar 16 |
nicklas |
516 |
public static Rna findLatestRnaForSpecimen(DbControl dc, String name) |
3780 |
10 Mar 16 |
nicklas |
517 |
{ |
3780 |
10 Mar 16 |
nicklas |
518 |
ItemQuery<Extract> rnaQuery = Extract.getQuery(); |
3780 |
10 Mar 16 |
nicklas |
519 |
Subtype.RNA.addFilter(dc, rnaQuery); |
3780 |
10 Mar 16 |
nicklas |
520 |
rnaQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
3780 |
10 Mar 16 |
nicklas |
521 |
rnaQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name+".%", Type.STRING))); |
3780 |
10 Mar 16 |
nicklas |
522 |
rnaQuery.order(Orders.desc(Hql.property("creationEvent.eventDate"))); |
3780 |
10 Mar 16 |
nicklas |
523 |
Iterator<Extract> it = rnaQuery.iterate(dc); |
3780 |
10 Mar 16 |
nicklas |
524 |
return it.hasNext() ? Rna.get(it.next()) : null; |
3780 |
10 Mar 16 |
nicklas |
525 |
} |
3779 |
10 Mar 16 |
nicklas |
526 |
|
3780 |
10 Mar 16 |
nicklas |
527 |
public static Library findLatestLibraryForSpecimen(DbControl dc, String name) |
3780 |
10 Mar 16 |
nicklas |
528 |
{ |
3869 |
22 Apr 16 |
nicklas |
529 |
ItemQuery<Extract> libQuery = Extract.getQuery(); |
3869 |
22 Apr 16 |
nicklas |
530 |
Subtype.LIBRARY.addFilter(dc, libQuery); |
3869 |
22 Apr 16 |
nicklas |
531 |
libQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
3869 |
22 Apr 16 |
nicklas |
532 |
libQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name+".%", Type.STRING))); |
3869 |
22 Apr 16 |
nicklas |
533 |
libQuery.restrict(Restrictions.neq(Hql.property("bioWell"), null)); |
3869 |
22 Apr 16 |
nicklas |
534 |
libQuery.order(Orders.desc(Hql.property("creationEvent.eventDate"))); |
3869 |
22 Apr 16 |
nicklas |
535 |
Iterator<Extract> it = libQuery.iterate(dc); |
3780 |
10 Mar 16 |
nicklas |
536 |
return it.hasNext() ? Library.get(it.next()) : null; |
3780 |
10 Mar 16 |
nicklas |
537 |
} |
3780 |
10 Mar 16 |
nicklas |
538 |
|
4667 |
01 Feb 18 |
nicklas |
539 |
public static Rawbioassay findLatestRawBioAssayForLibrary(DbControl dc, Library lib, Rawdatatype rawDataType) |
3782 |
11 Mar 16 |
nicklas |
540 |
{ |
3782 |
11 Mar 16 |
nicklas |
541 |
ItemQuery<RawBioAssay> rawQuery = RawBioAssay.getQuery(); |
3782 |
11 Mar 16 |
nicklas |
542 |
rawQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
4665 |
31 Jan 18 |
nicklas |
543 |
if (rawDataType != null) |
4665 |
31 Jan 18 |
nicklas |
544 |
{ |
4667 |
01 Feb 18 |
nicklas |
545 |
rawDataType.addFilter(dc, rawQuery); |
4665 |
31 Jan 18 |
nicklas |
546 |
} |
3782 |
11 Mar 16 |
nicklas |
547 |
rawQuery.restrict(Restrictions.eq(Hql.property("parentExtract"), Hql.entity(lib.getExtract()))); |
3782 |
11 Mar 16 |
nicklas |
548 |
rawQuery.order(Orders.desc(Hql.property("entryDate"))); |
3782 |
11 Mar 16 |
nicklas |
549 |
Iterator<RawBioAssay> it = rawQuery.iterate(dc); |
3782 |
11 Mar 16 |
nicklas |
550 |
return it.hasNext() ? Rawbioassay.get(it.next()) : null; |
3782 |
11 Mar 16 |
nicklas |
551 |
} |
3782 |
11 Mar 16 |
nicklas |
552 |
|
3779 |
10 Mar 16 |
nicklas |
553 |
} |