Ejemplo n.º 1
0
    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'/>&nbsp;" % (antype, self.context.absolute_url())
                if obj.getReferenceType() == 'b':
                    imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/>&nbsp;" % (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'/>&nbsp;" % (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
Ejemplo n.º 2
0
    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'/>&nbsp;" % (antype, self.context.absolute_url())
                if obj.getReferenceType() == 'b':
                    imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/>&nbsp;" % (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'/>&nbsp;" % (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
Ejemplo n.º 3
0
    def folderitem(self, obj, item, index):
        item = super(QCAnalysesView, self).folderitem(obj, item, index)

        obj = self.get_object(obj)

        # Fill Worksheet cell
        worksheet = obj.getWorksheet()
        if not worksheet:
            return item

        # Fill the Worksheet cell
        ws_id = api.get_id(worksheet)
        ws_url = api.get_url(worksheet)
        item["replace"]["Worksheet"] = get_link(ws_url, value=ws_id)

        if IDuplicateAnalysis.providedBy(obj):
            an_type = "d"
            img_name = "duplicate.png"
            parent = obj.getRequest()
        else:
            an_type = obj.getReferenceType()
            img_name = an_type == "c" and "control.png" or "blank.png"
            parent = obj.aq_parent

        # Render the image
        an_type = QCANALYSIS_TYPES.getValue(an_type)
        item['before']['Service'] = get_image(img_name, title=an_type)

        # Fill the Parent cell
        parent_url = api.get_url(parent)
        parent_id = api.get_id(parent)
        item["replace"]["Parent"] = get_link(parent_url, value=parent_id)

        return item
Ejemplo n.º 4
0
    def folderitem(self, obj, item, index):
        """Prepare a data item for the listing.

        :param obj: The catalog brain or content object
        :param item: Listing item (dictionary)
        :param index: Index of the listing item
        :returns: Augmented listing data item
        """

        obj = obj.getObject()
        # Group items by RefSample - Worksheet - Position
        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:
            item['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" \
                          "'/>&nbsp;" % (
                              antype, self.context.absolute_url())
            if obj.getReferenceType() == 'b':
                imgtype = "<img title='%s' " \
                          "src='%s/++resource++bika.lims.images/blank.png" \
                          "'/>&nbsp;" % (
                              antype, self.context.absolute_url())
            item['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" \
                      "'/>&nbsp;" % (
                          antype, self.context.absolute_url())
            item['sortcode'] = '%s_%s' % (obj.getSample().id, obj.getKeyword())

        item['before']['Service'] = imgtype
        item['sortcode'] = '%s_%s' % (obj.getReferenceAnalysesGroupID(),
                                      obj.getKeyword())
        return item
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
    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'/>&nbsp;" % (
                        antype, self.context.absolute_url())
                if obj.getReferenceType() == 'b':
                    imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/>&nbsp;" % (
                        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'/>&nbsp;" % (
                    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
Ejemplo n.º 8
0
    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'/>&nbsp;" % (antype, self.context.absolute_url())
                if obj.getReferenceType() == 'b':
                    imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/>&nbsp;" % (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'/>&nbsp;" % (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