def folderitems(self): items = AnalysesView.folderitems(self) # Group items by RefSample - Worksheet - Position for i in range(len(items)): obj = items[i]['obj'] wss = obj.getBackReferences('WorksheetAnalysis') wsid = wss[0].id if wss and len(wss) > 0 else '' wshref = wss[0].absolute_url() if wss and len(wss) > 0 else None if wshref: items[i]['replace']['Worksheet'] = "<a href='%s'>%s</a>" % (wshref, wsid) imgtype = "" if obj.portal_type == 'ReferenceAnalysis': antype = QCANALYSIS_TYPES.getValue(obj.getReferenceType()) if obj.getReferenceType() == 'c': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/control.png'/> " % (antype, self.context.absolute_url()) if obj.getReferenceType() == 'b': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/> " % (antype, self.context.absolute_url()) items[i]['replace']['Partition'] = "<a href='%s'>%s</a>" % (obj.aq_parent.absolute_url(), obj.aq_parent.id) elif obj.portal_type == 'DuplicateAnalysis': antype = QCANALYSIS_TYPES.getValue('d') imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/> " % (antype, self.context.absolute_url()) items[i]['sortcode'] = '%s_%s' % (obj.getSample().id, obj.getService().getKeyword()) items[i]['before']['Service'] = imgtype items[i]['sortcode'] = '%s_%s' % (obj.getReferenceAnalysesGroupID(), obj.getService().getKeyword()) # Sort items items = sorted(items, key = itemgetter('sortcode')) return items
def folderitems(self): items = AnalysesView.folderitems(self) # Group items by RefSample - Worksheet - Position for i in range(len(items)): obj = items[i]['obj'] wss = obj.getBackReferences('WorksheetAnalysis') wsid = wss[0].id if wss and len(wss) > 0 else '' wshref = wss[0].absolute_url() if wss and len(wss) > 0 else None if wshref: items[i]['replace']['Worksheet'] = "<a href='%s'>%s</a>" % ( wshref, wsid) imgtype = "" if obj.portal_type == 'ReferenceAnalysis': antype = QCANALYSIS_TYPES.getValue(obj.getReferenceType()) if obj.getReferenceType() == 'c': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/control.png'/> " % ( antype, self.context.absolute_url()) if obj.getReferenceType() == 'b': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/> " % ( antype, self.context.absolute_url()) items[i]['replace']['Partition'] = "<a href='%s'>%s</a>" % ( obj.aq_parent.absolute_url(), obj.aq_parent.id) elif obj.portal_type == 'DuplicateAnalysis': antype = QCANALYSIS_TYPES.getValue('d') imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/> " % ( antype, self.context.absolute_url()) items[i]['sortcode'] = '%s_%s' % ( obj.getSample().id, obj.getService().getKeyword()) items[i]['before']['Service'] = imgtype items[i]['sortcode'] = '%s_%s' % (obj.getReferenceAnalysesGroupID( ), obj.getService().getKeyword()) # Sort items items = sorted(items, key=itemgetter('sortcode')) return items
def getLatestReferenceAnalyses(self): """ Returns a list with the latest Reference analyses performed for this instrument and Analysis Service. References the latest ReferenceAnalysis done for this instrument. Duplicate Analyses and Regular Analyses are not included. Only contains the last ReferenceAnalysis done for this instrument, Analysis Service and Reference type (blank or control). The list is created 'on-fly' if the method hasn't been already called or a new ReferenceAnalysis has been added by using addReferences() since its last call. Otherwise, uses the private accessor _LatestReferenceAnalyses as a cache (prevents overload). As an example: [0]: RefAnalysis for Ethanol, QC-001 (Blank) [1]: RefAnalysis for Ethanol, QC-002 (Control) [2]: RefAnalysis for Methanol, QC-001 (Blank) """ field = self.getField('_LatestReferenceAnalyses') refs = field and field.get(self) or [] if len(refs) == 0: latest = {} # Since the results file importer uses Date from the results # file as Analysis 'Capture Date', we cannot assume the last # item from the list is the latest analysis done, so we must # pick up the latest analyses using the Results Capture Date for ref in self.getReferenceAnalyses(): antype = QCANALYSIS_TYPES.getValue(ref.getReferenceType()) key = '%s.%s' % (ref.getServiceUID(), antype) last = latest.get(key, ref) if ref.getResultCaptureDate() > last.getResultCaptureDate(): latest[key] = ref else: latest[key] = last refs = [r for r in latest.itervalues()] # Add to the cache self.getField('_LatestReferenceAnalyses').set(self, refs) return refs
def folderitems(self): items = AnalysesView.folderitems(self) items.sort(key=itemgetter('CaptureDate'), reverse=True) for i in range(len(items)): obj = items[i]['obj'] imgtype = "" if obj.portal_type == 'ReferenceAnalysis': antype = QCANALYSIS_TYPES.getValue(obj.getReferenceType()) if obj.getReferenceType() == 'c': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/control.png'/> " % ( antype, self.context.absolute_url()) if obj.getReferenceType() == 'b': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/> " % ( antype, self.context.absolute_url()) items[i]['replace']['Partition'] = "<a href='%s'>%s</a>" % ( obj.aq_parent.absolute_url(), obj.aq_parent.id) elif obj.portal_type == 'DuplicateAnalysis': antype = QCANALYSIS_TYPES.getValue('d') imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/> " % ( antype, self.context.absolute_url()) items[i]['sortcode'] = '%s_%s' % ( obj.getSample().id, obj.getService().getKeyword()) else: items[i]['sortcode'] = '%s_%s' % ( obj.getSample().id, obj.getService().getKeyword()) items[i]['before']['Service'] = imgtype # Get retractions field pdf = obj.getRetractedAnalysesPdfReport() title = '' anchor = '' try: if pdf: filesize = 0 title = _('Retractions') anchor = "<a class='pdf' target='_blank' href='%s/at_download/RetractedAnalysesPdfReport'>%s</a>" % \ (obj.absolute_url(), _("Retractions")) filesize = pdf.get_size() filesize = filesize / 1024 if filesize > 0 else 0 except: # POSKeyError: 'No blob file' # Show the record, but not the link title = _('Retraction report unavailable') anchor = title items[i]['Retractions'] = title items[i]['replace']['Retractions'] = anchor # Create json qcid = obj.aq_parent.id serviceref = "%s (%s)" % (items[i]['Service'], items[i]['Keyword']) trows = self.anjson.get(serviceref, {}) anrows = trows.get(qcid, []) anid = '%s.%s' % (items[i]['getReferenceAnalysesGroupID'], items[i]['id']) rr = obj.aq_parent.getResultsRangeDict() uid = obj.getServiceUID() if uid in rr: specs = rr[uid] try: smin = float(specs.get('min', 0)) smax = float(specs.get('max', 0)) error = float(specs.get('error', 0)) target = float(specs.get('result', 0)) result = float(items[i]['Result']) error_amount = ((target / 100) * error) if target > 0 else 0 upper = smax + error_amount lower = smin - error_amount anrow = { 'date': items[i]['CaptureDate'], 'min': smin, 'max': smax, 'target': target, 'error': error, 'erroramount': error_amount, 'upper': upper, 'lower': lower, 'result': result, 'unit': items[i]['Unit'], 'id': items[i]['uid'] } anrows.append(anrow) trows[qcid] = anrows self.anjson[serviceref] = trows except: pass return items