def getResultsRange(self): """Returns the valid result range for this routine analysis based on the results ranges defined in the Analysis Request this routine analysis is assigned to. A routine analysis will be considered out of range if it result falls out of the range defined in "min" and "max". If there are values set for "warn_min" and "warn_max", these are used to compute the shoulders in both ends of the range. Thus, an analysis can be out of range, but be within shoulders still. :return: A dictionary with keys "min", "max", "warn_min" and "warn_max" :rtype: dict """ specs = ResultsRangeDict() analysis_request = self.getRequest() if not analysis_request: return specs keyword = self.getKeyword() ar_ranges = analysis_request.getResultsRange() # Get the result range that corresponds to this specific analysis an_range = [rr for rr in ar_ranges if rr.get('keyword', '') == keyword] rr = an_range and an_range[0].copy() or specs # Calculated Specification calc_uid = rr.get("calculation") calc = api.get_object_by_uid(calc_uid, None) if calc: spec = rr.copy() spec["analysis_uid"] = self.UID() calc_spec = calc.calculate_result(mapping={"spec": spec}, default=rr) if calc_spec: rr.update(calc_spec) return rr
def get_object_by_uid(self, uid): """Get the object by UID """ logger.debug("get_object_by_uid::UID={}".format(uid)) obj = api.get_object_by_uid(uid, None) if obj is None: logger.warn("!! No object found for UID #{} !!") return obj
def __call__(self): plone.protect.CheckAuthenticator(self.request) ar = api.get_object_by_uid(self.request.get('uid', None), None) or \ self.context if not ar or not IAnalysisRequest.providedBy(ar): return self.template() # Set the default recipients for the email self.recipients = self.get_recipients(ar) # Set the subject self.subject = self.context.translate( _("Some results from ${ar} exceeded panic range", mapping={"ar": ar.getId()}) ) # Set the body of the message self.body = self.get_body_message(ar) return self.template()
def get_specification_for(spec, default=_marker): """Returns a plain dictionary with specification values (min, max, etc.) It looks through an excel file provided as-is to find the record that better fits with the gender and age from the analysis request and for the analysis passed in :param: Analysis object or analysis uid or analysis brain """ analysis = api.get_object_by_uid(spec.get(('analysis_uid'))) if not analysis or not IRequestAnalysis.providedBy(analysis): if default is not _marker: return default api.fail("Type {} not supported: ".format(repr(analysis))) request = analysis.getRequest() gender = api.get_field_value(request, "Gender") if not gender or gender.lower() not in GENDERS.keys(): # If no gender is specified or not a valid value, assume any gender = 'a' dob = api.get_field_value(request, "DateOfBirth") sampled = request.getDateSampled() if not dob or not sampled: #logger.error("No DateSampled/ DateOfBirth set. Ignore if 1.3 upgrade") return {} specification = request.getSpecification() if not specification: # This should never happen, Since this function has been triggered, we # assume an specification has been set to the AR if default is not _marker: return default api.fail("Specification not set for request {}".format(request.id)) years, months, days = api.get_age(dob, sampled) return get_analysisspec(analysis_keyword=analysis.getKeyword(), gender=gender, years=years, months=months, days=days)