Changeset 1413 for extensions
- Timestamp:
- Oct 19, 2011, 2:07:49 PM (12 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/resources/specimentube.jsp
r1411 r1413 75 75 var caseInfo = null; 76 76 var boxInfo = null; 77 var updateMode = null;78 77 79 78 function init() … … 136 135 getCaseInfo(); 137 136 138 var hasSpecimen = caseInfo.specimen && caseInfo.specimen.length > 0;139 var hasLeftSpecimen = false;140 var hasRightSpecimen = false;141 var hasUnknownSpecimen = false;142 var thisArrivalDate = null;143 var thisNumberOfTubes = null;144 var thisCaseSamplingDate = null;145 var thisCaseRNALaterDate = null;146 var thisCaseLaterality = null;147 var thisCasePad = null;148 var thisOtherPathNote = null;149 var thisSpecimenType = null;150 var thisBiopsyType = null;151 152 137 frm.caseName.disabled = true; 153 154 Main.show('gocancel'); 155 Main.show('caseSection'); 156 157 var hasLeftCase = false; 158 var hasRightCase = false; 159 var hasUnknownCase = false; 160 161 // Load annotations from the actual case 162 thisCaseLaterality = caseInfo.laterality; 163 thisOtherPathNote = caseInfo.otherPathNote; 164 thisCasePad = caseInfo.pad; 165 if (caseInfo.reasonIfNoSpecimen && caseInfo.reasonIfNoSpecimen.length>0) 166 { 167 setFatalError("There is a reason given why this case doesn't have specimen tubes. " + 168 "This wizard can't be used until that is corrected."); 169 } 170 171 //Adjust the step-title 172 if (caseInfo.id) 173 { 174 setInnerHTML('step2.title', 'Add Specimen tube Information'); 175 } 176 if (hasSpecimen) 177 { 178 setInnerHTML('step2.title', 'Update Case Information'); 179 updateMode = true; 180 frm.nofTubes.value = thisNumberOfTubes; 181 frm.nofTubes.disabled = true; 182 frm.arrivalDate.focus(); 183 184 // If the number of tubes not is set - use the current number of specimen tubes. 185 if (!thisNumberOfTubes) thisNumberOfTubes = caseInfo.specimen.length; 186 187 for (var i=0; i < caseInfo.specimen.length; i++) 188 { 189 var specimen = caseInfo.specimen[i]; 190 if (specimen.pad && !thisCasePad) 191 { 192 thisCasePad = specimen.pad; 193 } 194 if(specimen.arrivalDate && !thisArrivalDate) 195 { 196 thisArrivalDate = specimen.arrivalDate; 197 } 198 if (specimen.nofTubes && !thisNumberOfTubes) 199 { 200 thisNumberOfTubes = specimen.nofTubes; 201 } 202 if (specimen.samplingDate && !thisCaseSamplingDate) 203 { 204 thisCaseSamplingDate = specimen.samplingDate; 205 } 206 if (specimen.rnaLaterDate && !thisCaseRNALaterDate) 207 { 208 thisCaseRNALaterDate = specimen.rnaLaterDate; 209 } 210 if (specimen.otherPathNote && !thisOtherPathNote) 211 { 212 thisOtherPathNote = specimen.otherPathNote; 213 } 214 if (specimen.laterality && !thisCaseLaterality) 215 { 216 if (specimen.laterality == 'LEFT') hasLeftSpecimen = true; 217 if (specimen.laterality == 'RIGHT') hasRightSpecimen = true; 218 thisCaseLaterality = specimen.laterality; 219 } 220 else if(!thisCaseLaterality) 221 { 222 hasUnknownSpecimen = true; 223 } 224 if (specimen.specimenType && !thisSpecimenType) 225 { 226 thisSpecimenType = specimen.specimenType; 227 } 228 if (specimen.biopsyType && !thisBiopsyType) 229 { 230 thisBiopsyType = specimen.biopsyType; 231 } 232 } 233 234 // Check that all specimen tubes have the same laterality 235 var numLateralities = 0; 236 if (hasLeftSpecimen) numLateralities++; 237 if (hasRightSpecimen) numLateralities++; 238 if (hasUnknownSpecimen) numLateralities++; 239 if (numLateralities > 1) 240 { 241 setInputStatus('laterality', 'Specimen tubes with different laterality', 'warning'); 242 thisCaseLaterality = null; 243 Forms.checkRadio(frm.laterality, thisCaseLaterality); 244 } 245 } 246 if (thisCaseLaterality != null) 247 { 248 var lateralityInput = ''; 249 lateralityInput += '<input type="radio" name="laterality" value="LEFT" '; 250 if (thisCaseLaterality == 'LEFT') lateralityInput += 'checked'; 251 lateralityInput += ' onChange="lateralityOnChange()">LEFT'; 252 lateralityInput += '<br>'; 253 lateralityInput += '<input type="radio" name="laterality" value="RIGHT" '; 254 if (thisCaseLaterality == 'RIGHT') lateralityInput += 'checked'; 255 lateralityInput += ' onChange="lateralityOnChange()">RIGHT'; 256 setInnerHTML('laterality.input', lateralityInput); 257 } 258 lateralityOnChange(); 259 specimenTypeOnClick(); 260 biopsyTypeOnClick(); 261 if (thisCasePad != null) 262 { 263 frm.pad.value = thisCasePad; 264 padOnChange(); 265 } 266 if (thisArrivalDate != null) 267 { 268 frm.arrivalDate.value = thisArrivalDate; 269 } 270 if (thisNumberOfTubes != null) 271 { 272 frm.nofTubes.value = thisNumberOfTubes; 273 nofTubesOnChange(); 274 } 275 if (thisCaseSamplingDate != null) 276 { 277 frm.samplingDate.value = thisCaseSamplingDate.substring(0, 8); 278 frm.samplingTime.value = thisCaseSamplingDate.substring(9, 13); 279 samplingDateTimeOnChange(); 280 } 281 if (thisCaseRNALaterDate != null) 282 { 283 frm.rnaLaterDate.value = thisCaseRNALaterDate.substring(0, 8); 284 frm.rnaLaterTime.value = thisCaseRNALaterDate.substring(9, 13); 285 rnaLaterDateTimeOnChange(); 286 } 287 if (thisOtherPathNote != null) 288 { 289 frm.otherPathNote.value = thisOtherPathNote; 290 } 291 if (thisSpecimenType != null) 292 { 293 Forms.selectListOption(frm.specimenType, thisSpecimenType); 294 specimenTypeOnClick(); 295 } 296 if (thisBiopsyType != null) 297 { 298 Forms.selectListOption(frm.biopsyType, thisBiopsyType); 299 biopsyTypeOnClick(); 300 } 138 if (caseInfo != null) 139 { 140 Main.show('gocancel'); 141 Main.show('caseSection'); 142 } 143 301 144 frm.nofTubes.focus(); 302 145 frm.nofTubes.setSelectionRange(0,1); … … 326 169 frm.biopsyType.disabled = true; 327 170 328 if (updateMode)329 {330 //setInnerHTML('step3.title', 'Update Tube Information');331 }332 333 171 for (var i=0;i<nofTubes;i++) 334 172 { … … 343 181 boxInfo[i] = null; 344 182 var boxDisabled = ''; 345 if (caseInfo.specimen && caseInfo.specimen.length>0 && i<caseInfo.specimen.length) 346 { 347 boxDisabled = 'disabled'; 348 specimen = caseInfo.specimen[i]; 349 boxValue = specimen.box == null ? '' : specimen.box; 350 rowValue = specimen.row == null ? '' : specimen.row; 351 columnValue = specimen.column == null ? '' : specimen.column; 352 } 183 353 184 inputTubeHtml += '<tr>'; 354 185 inputTubeHtml += '<td class="prompt">Specimen Tube '+caseInfo.name+'.'+(i+1)+'</td>'; … … 395 226 Main.hide('gonext'); 396 227 397 if (updateMode) Main.show('goupdate'); 398 else Main.show('gocreate'); 228 Main.show('gocreate'); 399 229 400 230 var textLength = frm.box0.value.length; … … 833 663 laterality = null; 834 664 } 835 836 for (var i = 0; i < caseInfo.specimen.length; i++)837 {838 var specimen = caseInfo.specimen[i];839 if (specimen.laterality != laterality)840 {841 setInputStatus('laterality', 'Specimen tubes are updated to: ' + laterality, 'valid')842 return;843 }844 }845 665 } 846 666 … … 855 675 { 856 676 specimenType = selectedSpecimenType; 857 }858 859 for (var i=0; i<caseInfo.specimen.length; i++)860 {861 var specimen = caseInfo.specimen[i];862 if (specimen.specimenType != specimenType)863 {864 setInputStatus('specimenType', 'Specimen tubes are updated to: ' + specimenType, 'valid')865 return;866 }867 677 } 868 678 setInputStatus('specimenType', '', 'valid'); … … 879 689 biopsyType = selectedBiopsyType; 880 690 } 881 882 for (var i=0; i<caseInfo.specimen.length; i++) 883 { 884 var specimen = caseInfo.specimen[i]; 885 if (specimen.biopsyType != biopsyType) 886 { 887 setInputStatus('biopsyType', 'Specimen tubes are updated to: ' + biopsyType, 'valid') 888 return; 889 } 890 } 691 891 692 setInputStatus('biopsyType', '', 'valid'); 892 693 } … … 919 720 var frm = document.forms['reggie']; 920 721 921 922 722 caseInfo.laterality = Forms.getCheckedRadio(frm.laterality).value; 923 723 caseInfo.pad = frm.pad.value; … … 928 728 929 729 var nofTubes = frm.nofTubes.value; 730 caseInfo.specimen = new Array(nofTubes); 930 731 for (var i=0; i<nofTubes; i++) 931 732 { 932 var specimenTube = new Object(); 933 if (caseInfo.specimen[i]) specimenTube = caseInfo.specimen[i]; 733 var specimenTube = new Object(); 934 734 specimenTube.name = caseInfo.name+'.'+(1+i); 935 735 … … 956 756 var request = Ajax.getXmlHttpRequest(); 957 757 var url = 'SpecimenTubeRegistration.servlet?ID=<%=ID%>&cmd='; 958 url += updateMode ? 'UpdateSpecimenTubes' :'CreateSpecimenTubes';758 url += 'CreateSpecimenTubes'; 959 759 request.open("POST", url, false); 960 760 request.setRequestHeader("Content-Type", "application/json"); -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SpecimenTubeServlet.java
r1409 r1413 69 69 70 70 String caseName = req.getParameter("caseName"); 71 Case theCase = Case.findByName(dc, caseName); 72 List<SpecimenTube> specimenTubes = null; 71 Case theCase = Case.findByName(dc, caseName); 72 if (theCase != null) 73 { 74 throw new InvalidDataException("The case (" + caseName + ") already exists in BASE. " + 75 "This wizard cannot be used to update tubes that already been connected to a case."); 76 } 77 78 List<SpecimenTube> specimenTubes = SpecimenTube.findByCaseName(dc, caseName); 79 if (specimenTubes.size() > 0) 80 { 81 throw new InvalidDataException("There are already specimen tubes in this case."); 82 } 83 73 84 JSONObject jsonCase = null; 74 75 // Load specimen tubes for the case76 specimenTubes = SpecimenTube.findByCaseName(dc, caseName);77 85 if (theCase == null) 78 86 { 79 87 jsonCase = new JSONObject(); 80 88 jsonCase.put("name", caseName); 81 } 82 else 83 { 84 theCase.loadAnnotations(dc, "laterality", Reggie.ANNOTATION_LATERALITY, null); 85 theCase.loadAnnotations(dc, "pad", Reggie.ANNOTATION_PAD_CASE, null); 86 theCase.loadAnnotations(dc, "reasonIfNoSpecimen", Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, null); 87 theCase.loadAnnotations(dc, "pathNote", Reggie.ANNOTATION_OTHER_PATH_NOTE, null); 88 89 jsonCase = theCase.asJSONObject(); 90 91 } 92 93 JSONArray jsonTubes = new JSONArray(); 94 if (theCase != null && specimenTubes.size() == 0) 95 { 96 throw new InvalidDataException("The case (" + caseName + ") was found " + 97 "but has no tubes to update"); 98 } 99 100 AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true); 101 AnnotationType laterlityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true); 102 AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true); 103 AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true); 104 AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true); 105 AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true); 106 AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT, true); 107 AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OTHER_PATH_NOTE, true); 108 AnnotationType specimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SPECIMEN_TYPE, true); 109 AnnotationType biopsyType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BIOPSY_TYPE, true); 110 111 DateToStringConverter dateTimeConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm")); 112 DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd")); 113 for (SpecimenTube tube : specimenTubes) 114 { 115 tube.loadAnnotations("pad", padType, null); 116 tube.loadAnnotations("laterality", laterlityType, null); 117 tube.loadAnnotations("samplingDate", samplingDateType, dateTimeConverter); 118 tube.loadAnnotations("rnaLaterDate", rnaLaterDateType, dateTimeConverter); 119 tube.loadAnnotations("arrivalDate", arrivalDateType, dateConverter); 120 tube.loadAnnotations("nofTubes", nofDeliveredTubesType, null); 121 tube.loadAnnotations("operatorComment", operatorCommentType, null); 122 tube.loadAnnotations("otherPathNote", pathNoteType, null); 123 tube.loadAnnotations("specimenType", specimenType, null); 124 tube.loadAnnotations("biopsyType", biopsyType, null); 125 126 jsonTubes.add(tube.asJSONObject()); 127 } 128 jsonCase.put("specimen", jsonTubes); 89 } 129 90 json.put("caseInfo", jsonCase); 130 91 } … … 268 229 try 269 230 { 270 if ("UpdateSpecimenTubes".equals(cmd)) 271 { 272 dc = sc.newDbControl(); 273 274 JSONObject jsonReq = (JSONObject) new JSONParser().parse(req.getReader()); 275 JSONObject jsonCase = (JSONObject)jsonReq.get("caseInfo"); 276 Sample theCase = null; 277 278 Number caseId = (Number)jsonCase.get("id"); 279 String laterality = Values.getStringOrNull((String)jsonCase.get("laterality")); 280 String padCase = Values.getStringOrNull((String)jsonCase.get("pad")); 281 String otherPathNote = Values.getStringOrNull((String)jsonCase.get("otherPathNote")); 282 StringToDateConverter dateTimeConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm")); 283 StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd")); 284 Date samplingDate = dateTimeConverter.convert((String)jsonCase.get("samplingDate")); 285 Date rnaLaterDate = dateTimeConverter.convert((String)jsonCase.get("rnaLaterDate")); 286 Date arrivalDate = dateConverter.convert((String)jsonCase.get("arrivalDate")); 287 288 AnnotationType nofDeliveredTubesType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_NOF_DELIVERED_TUBES, true); 289 AnnotationType padType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD, true); 290 AnnotationType padCaseType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_PAD_CASE, true); 291 AnnotationType lateralityType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_LATERALITY, true); 292 AnnotationType pathNoteType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OTHER_PATH_NOTE, true); 293 AnnotationType samplingDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SAMPLING_DATETIME, true); 294 AnnotationType rnaLaterDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true); 295 AnnotationType arrivalDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_ARRIVAL_DATE, true); 296 AnnotationType operatorCommentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT, true); 297 AnnotationType specimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_SPECIMEN_TYPE, true); 298 AnnotationType biopsyType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BIOPSY_TYPE, true); 299 300 // Checking if it is an existing case or a new should be created. 301 if (caseId != null) 302 { 303 theCase = Sample.getById(dc, caseId.intValue()); 304 305 if (laterality != null) Reggie.setAnnotationValue(theCase, lateralityType, laterality); 306 if (arrivalDate != null) Reggie.setAnnotationValue(theCase, arrivalDateType, arrivalDate); 307 if (otherPathNote != null) Reggie.setAnnotationValue(theCase, pathNoteType, otherPathNote); 308 if (padCase != null) Reggie.appendAnnotationValueIfUnique(theCase, padCaseType, padCase); 309 } 310 311 JSONArray jsonSpecimen = (JSONArray)jsonCase.get("specimen"); 312 if (jsonSpecimen != null && jsonSpecimen.size() > 0) 313 { 314 int nofTubes = jsonSpecimen.size(); 315 for (int i=0; i < jsonSpecimen.size(); i++) 316 { 317 JSONObject jsonSpec = (JSONObject)jsonSpecimen.get(i); 318 Number specimenId = (Number)jsonSpec.get("id"); 319 Sample specimen = Sample.getById(dc, specimenId.intValue()); 320 321 String operatorComment = Values.getStringOrNull((String)jsonSpec.get("operatorComment")); 322 String specimenTypeString = Values.getStringOrNull((String)jsonCase.get("specimenType")); 323 String biopsyTypeString = Values.getStringOrNull((String)jsonCase.get("biopsyType")); 324 325 Reggie.setAnnotationValue(specimen, nofDeliveredTubesType, nofTubes); 326 if (arrivalDate != null) Reggie.setAnnotationValue(specimen, arrivalDateType, arrivalDate); 327 if (laterality != null) Reggie.setAnnotationValue(specimen, lateralityType, laterality); 328 if (samplingDate != null) Reggie.setAnnotationValue(specimen, samplingDateType, samplingDate); 329 if (rnaLaterDate != null) Reggie.setAnnotationValue(specimen, rnaLaterDateType, rnaLaterDate); 330 if (padCase != null) Reggie.setAnnotationValue(specimen, padType, padCase); 331 if (otherPathNote != null) Reggie.setAnnotationValue(specimen, pathNoteType, otherPathNote); 332 if (operatorComment != null) Reggie.setAnnotationValue(specimen, operatorCommentType, operatorComment); 333 if (specimenTypeString != null) Reggie.setAnnotationValue(specimen, specimenType, specimenTypeString); 334 if (biopsyTypeString != null) Reggie.setAnnotationValue(specimen, biopsyType, biopsyTypeString); 335 336 jsonMessages.add("Specimen tube '" + specimen.getName() + "' updated successfully."); 337 } 338 } 339 dc.commit(); 340 json.put("messages", jsonMessages); 341 } 342 else if ("CreateSpecimenTubes".equals(cmd)) 231 if ("CreateSpecimenTubes".equals(cmd)) 343 232 { 344 233 dc = sc.newDbControl();
Note: See TracChangeset
for help on using the changeset viewer.