def to_service_uid(uid_brain_obj_str): """Resolves the passed in element to a valid uid. Returns None if the value cannot be resolved to a valid uid """ if api.is_uid(uid_brain_obj_str) and uid_brain_obj_str != "0": return uid_brain_obj_str if api.is_object(uid_brain_obj_str): obj = api.get_object(uid_brain_obj_str) if IAnalysisService.providedBy(obj): return api.get_uid(obj) elif IRoutineAnalysis.providedBy(obj): return obj.getServiceUID() else: logger.error("Type not supported: {}".format(obj.portal_type)) return None if isinstance(uid_brain_obj_str, six.string_types): # Maybe is a keyword? query = dict(portal_type="AnalysisService", getKeyword=uid_brain_obj_str) brains = api.search(query, SETUP_CATALOG) if len(brains) == 1: return api.get_uid(brains[0]) # Or maybe a title query = dict(portal_type="AnalysisService", title=uid_brain_obj_str) brains = api.search(query, SETUP_CATALOG) if len(brains) == 1: return api.get_uid(brains[0]) return None
def is_analysis(self, obj): """Check if the object is an analysis """ if IRoutineAnalysis.providedBy(obj): return True if IReferenceAnalysis.providedBy(obj): return True return False
def get_assigned_services(self): """Get the current assigned services of this Worksheet """ analyses = self.context.getAnalyses() routine_analyses = filter( lambda an: IRoutineAnalysis.providedBy(an), analyses) services = map(lambda an: an.getAnalysisService(), routine_analyses) return services
def resolve_to_uid(item): if api.is_uid(item): return item elif IAnalysisService.providedBy(item): return item.UID() elif IRoutineAnalysis.providedBy(item): return item.getServiceUID() bsc = api.get_tool("bika_setup_catalog") brains = bsc(portal_type='AnalysisService', getKeyword=item) if brains: return brains[0].UID brains = bsc(portal_type='AnalysisService', title=item) if brains: return brains[0].UID raise RuntimeError( str(item) + " should be the UID, title, keyword " " or title of an AnalysisService.")
def _folder_item_report_visibility(self, analysis_brain, item): """Set if the hidden field can be edited (enabled/disabled) :analysis_brain: Brain that represents an analysis :item: analysis' dictionary counterpart to be represented as a row""" # Users that can Add Analyses to an Analysis Request must be able to # set the visibility of the analysis in results report, also if the # current state of the Analysis Request (e.g. verified) does not allow # the edition of other fields. Note that an analyst has no privileges # by default to edit this value, cause this "visibility" field is # related with results reporting and/or visibility from the client side. # This behavior only applies to routine analyses, the visibility of QC # analyses is managed in publish and are not visible to clients. if 'Hidden' not in self.columns: return full_obj = self.get_object(analysis_brain) item['Hidden'] = full_obj.getHidden() if IRoutineAnalysis.providedBy(full_obj): item['allow_edit'].append('Hidden')
def get_slot_header_data(self, obj): """Prepare the data for the slot header template """ item_obj = None item_title = "" item_url = "" item_img = "" item_img_url = "" item_img_text = "" additional_item_icons = [] parent_obj = None parent_title = "" parent_url = "" parent_img = "" parent_img_text = "" additional_parent_icons = [] sample_type_obj = None sample_type_title = "" sample_type_url = "" sample_type_img = "" sample_type_img_text = "" if IDuplicateAnalysis.providedBy(obj): # item request = obj.getRequest() item_obj = request item_title = api.get_id(request) item_url = api.get_url(request) item_img = "duplicate.png" item_img_url = api.get_url(request) item_img_text = t(_("Duplicate")) # additional item icons additional_item_icons.append(self.render_remarks_tag(request)) # parent client = request.getClient() parent_obj = client parent_title = api.get_title(client) parent_url = api.get_url(client) parent_img = "client.png" parent_img_text = t(_("Client")) # sample type sample_type = request.getSampleType() sample_type_title = request.getSampleTypeTitle() sample_type_url = api.get_url(sample_type) sample_type_img = "sampletype.png" sample_type_img_text = t(_("Sample Type")) elif IReferenceAnalysis.providedBy(obj): # item sample = obj.getSample() item_obj = sample item_title = api.get_id(sample) item_url = api.get_url(sample) item_img_url = api.get_url(sample) item_img = "control.png" item_img_text = t(_("Control")) if obj.getReferenceType() == "b": item_img = "blank.png" item_img_text = t(_("Blank")) # parent supplier = obj.getSupplier() parent_obj = supplier parent_title = api.get_title(supplier) parent_url = api.get_url(supplier) parent_img = "supplier.png" parent_img_text = t(_("Supplier")) elif IRoutineAnalysis.providedBy(obj): # item request = obj.getRequest() item_obj = request item_title = api.get_id(request) item_url = api.get_url(request) item_img = "sample.png" item_img_url = api.get_url(request) item_img_text = t(_("Sample")) # additional item icons additional_item_icons.append(self.render_remarks_tag(request)) # parent client = obj.getClient() parent_obj = client parent_title = api.get_title(client) parent_url = api.get_url(client) parent_img = "client.png" parent_img_text = t(_("Client")) # sample type client_ref = request.getClientReference() client_sid = request.getClientSampleID() tokens = filter(None, [client_ref, client_sid]) sample_type_title = ' / '.join(tokens) sample_type = obj.getSampleType() sample_type_img = "sampletype.png" sample_type_img_text = t(_("Tank / Blend ID")) return { # item "item_obj": item_obj, "item_title": item_title, "item_url": item_url, "item_img": get_image(item_img, title=item_img_text), "item_img_url": item_img_url, "additional_item_icons": additional_item_icons, # parent "parent_obj": parent_obj, "parent_title": parent_title, "parent_url": parent_url, "parent_img": get_image(parent_img, title=parent_img_text), "additional_parent_icons": additional_parent_icons, # sample type "sample_type_obj": sample_type_obj, "sample_type_title": sample_type_title, "sample_type_url": sample_type_url, "sample_type_img": get_image(sample_type_img, title=sample_type_img_text), }
def create_retest(ar): """Creates a retest (Analysis Request) from an invalidated Analysis Request :param ar: The invalidated Analysis Request :type ar: IAnalysisRequest :rtype: IAnalysisRequest """ if not ar: raise ValueError("Source Analysis Request cannot be None") if not IAnalysisRequest.providedBy(ar): raise ValueError("Type not supported: {}".format(repr(type(ar)))) if ar.getRetest(): # Do not allow the creation of another retest! raise ValueError("Retest already set") if not ar.isInvalid(): # Analysis Request must be in 'invalid' state raise ValueError( "Cannot do a retest from an invalid Analysis Request".format( repr(ar))) # Open the actions pool actions_pool = ActionHandlerPool.get_instance() actions_pool.queue_pool() # Create the Retest (Analysis Request) ignore = ['Analyses', 'DatePublished', 'Invalidated', 'Sample'] retest = _createObjectByType("AnalysisRequest", ar.aq_parent, tmpID()) copy_field_values(ar, retest, ignore_fieldnames=ignore) # Mark the retest with the `IAnalysisRequestRetest` interface alsoProvides(retest, IAnalysisRequestRetest) # Assign the source to retest retest.setInvalidated(ar) # Rename the retest according to the ID server setup renameAfterCreation(retest) # Copy the analyses from the source intermediate_states = ['retracted', 'reflexed'] for an in ar.getAnalyses(full_objects=True): if (api.get_workflow_status_of(an) in intermediate_states): # Exclude intermediate analyses continue nan = _createObjectByType("Analysis", retest, an.getKeyword()) # Make a copy ignore_fieldnames = ['DataAnalysisPublished'] copy_field_values(an, nan, ignore_fieldnames=ignore_fieldnames) nan.unmarkCreationFlag() push_reindex_to_actions_pool(nan) # Transition the retest to "sample_received"! changeWorkflowState(retest, 'bika_ar_workflow', 'sample_received') alsoProvides(retest, IReceived) # Initialize analyses for analysis in retest.getAnalyses(full_objects=True): if not IRoutineAnalysis.providedBy(analysis): continue changeWorkflowState(analysis, "bika_analysis_workflow", "unassigned") # Reindex and other stuff push_reindex_to_actions_pool(retest) push_reindex_to_actions_pool(retest.aq_parent) # Resume the actions pool actions_pool.resume() return retest
def _reindex_request(obj): if IRoutineAnalysis.providedBy(obj): request = obj.getRequest() if request: request.reindexObject()
def _resolve_items_to_service_uids(items): """ Returns a list of service uids without duplicates based on the items :param items: A list (or one object) of service-related info items. The list can be heterogeneous and each item can be: - Analysis Service instance - Analysis instance - Analysis Service title - Analysis Service UID - Analysis Service Keyword If an item that doesn't match any of the criterias above is found, the function will raise a RuntimeError """ portal = None bsc = None service_uids = [] # Maybe only a single item was passed if type(items) not in (list, tuple): items = [items, ] for item in items: # service objects if IAnalysisService.providedBy(item): uid = item.UID() service_uids.append(uid) continue # Analysis objects (shortcut for eg copying analyses from other AR) if IRoutineAnalysis.providedBy(item): service_uids.append(item.getServiceUID()) continue # An object UID already there? if item in service_uids: continue # Maybe object UID. portal = portal if portal else api.portal.get() bsc = bsc if bsc else getToolByName(portal, 'bika_setup_catalog') brains = bsc(UID=item) if brains: uid = brains[0].UID service_uids.append(uid) continue # Maybe service Title brains = bsc(portal_type='AnalysisService', title=item) if brains: uid = brains[0].UID service_uids.append(uid) continue # Maybe service Keyword brains = bsc(portal_type='AnalysisService', getKeyword=item) if brains: uid = brains[0].UID service_uids.append(uid) continue raise RuntimeError( str(item) + " should be the UID, title, keyword " " or title of an AnalysisService.") return list(set(service_uids))
def is_analysis(self, obj): """Check if the object is an analysis """ return IRoutineAnalysis.providedBy(obj)