def _render_range_alert(self, analysis, result): """Appends an entry for the passed in analysis in self.alerts if the passed in tentative result is out of range or in shoulder range, in accordance with the assigned results range for the passed in analysis :param analysis: analysis object to be evaluated :param result: the tentative result to test if out of range/in shoulder """ if not analysis or not api.is_floatable(result): return out_of_range, out_of_shoulder = is_out_of_range(analysis, result) if not out_of_range: return result_range = analysis.getResultsRange() rngstr = get_formatted_interval(result_range, default="") message = "Result out of range" icon = "exclamation.png" if not out_of_shoulder: message = "Result in shoulder range" icon = "warning.png" uid = api.get_uid(analysis) alert = self.alerts.get(uid, []) alert.append({'icon': "++resource++bika.lims.images/{}".format(icon), 'msg': "{0} {1}".format(t(_(message)), rngstr), 'field': "Result"}) self.alerts[uid] = alert
def _folder_item_specifications(self, analysis_brain, item): """Set the results range to the item passed in""" # Everyone can see valid-ranges item['Specification'] = '' analysis = api.get_object(analysis_brain) results_range = analysis.getResultsRange() if not results_range: return # Display the specification interval item["Specification"] = get_formatted_interval(results_range, "") # Show an icon if out of range out_range, out_shoulders = is_out_of_range(analysis_brain) if not out_range: return # At least is out of range img = get_image("exclamation.png", title=_("Result out of range")) if not out_shoulders: img = get_image("warning.png", title=_("Result in shoulder range")) self._append_html_element(item, "Result", img) # Grades grade = api.get_grade_number(analysis_brain) if grade: span = " <span class='small grade_{}'>G{}</span>".format( grade, grade) self._append_html_element(item, "Result", span)
def _folder_item_specifications(self, analysis_brain, item): """Set the results range to the item passed in""" # Everyone can see valid-ranges item['Specification'] = '' results_range = analysis_brain.getResultsRange if not results_range: return # Display the specification interval item["Specification"] = get_formatted_interval(results_range, "") # Show an icon if out of range out_range, out_shoulders = is_out_of_range(analysis_brain) if not out_range: return # At least is out of range img = get_image("exclamation.png", title=_("Result out of range")) if not out_shoulders: img = get_image("warning.png", title=_("Result in shoulder range")) self._append_html_element(item, "Result", img)
def get_historicresults(patient): if not patient: return [], {} rows = {} dates = [] # Retrieve the AR IDs for the current patient query = { "portal_type": "AnalysisRequest", "getPatientUID": api.get_uid(patient), "review_state": ["verified", "published"], "sort_on": "getDateSampled", "sort_order": "descending" } brains = api.search(query, CATALOG_ANALYSIS_REQUEST_LISTING) samples = map(api.get_object, brains) # Retrieve all analyses analyses = map(lambda samp: samp.objectValues("Analysis"), samples) analyses = list(itertools.chain.from_iterable(analyses)) # Build the dictionary of rows for analysis in analyses: sample = analysis.aq_parent sample_type = sample.getSampleType() row = { "object": sample_type, "analyses": {}, } sample_type_uid = api.get_uid(sample_type) if sample_type_uid in rows: row = rows.get(sample_type_uid) anrow = row.get("analyses") service_uid = analysis.getServiceUID() asdict = { "object": analysis, "title": api.get_title(analysis), "keyword": to_utf8(analysis.getKeyword()), } if service_uid in anrow: asdict = anrow.get(service_uid) if not anrow.get("units", None): asdict.update( {"units": format_supsub(to_utf8(analysis.getUnit()))}) date = analysis.getResultCaptureDate() or analysis.created() date_time = DT2dt(to_date(date)).replace(tzinfo=None) date_time = datetime.strftime(date_time, "%Y-%m-%d %H:%M") # If more than one analysis of the same type has been # performed in the same datetime, get only the last one if date_time not in asdict.keys(): asdict[date_time] = { "object": analysis, "result": analysis.getResult(), "formattedresult": analysis.getFormattedResult() } # Get the specs # Only the specs applied to the last analysis for that # sample type will be taken into consideration. # We assume specs from previous analyses are obsolete. if "specs" not in asdict.keys(): specs = analysis.getResultsRange() asdict["specs"] = get_formatted_interval(specs, "") if date_time not in dates: dates.append(date_time) anrow[service_uid] = asdict row['analyses'] = anrow rows[sample_type_uid] = row dates.sort(reverse=False) return dates, rows