def after_verify(analysis): """ Method triggered after a 'verify' transition for the analysis passed in is performed. Promotes the transition to the Analysis Request and to Worksheet (if the analysis is assigned to any) This function is called automatically by bika.lims.workfow.AfterTransitionEventHandler """ # Mark this analysis as IVerified alsoProvides(analysis, IVerified) # Promote to analyses this analysis depends on promote_to_dependencies(analysis, "verify") # TODO: REFLEX TO REMOVE # Do all the reflex rules process if IRequestAnalysis.providedBy(analysis): analysis._reflex_rule_process('verify') # Promote transition to worksheet ws = analysis.getWorksheet() if ws: doActionFor(ws, 'verify') push_reindex_to_actions_pool(ws) # Promote transition to Analysis Request if IRequestAnalysis.providedBy(analysis): doActionFor(analysis.getRequest(), 'verify') reindex_request(analysis)
def after_submit(analysis): """Method triggered after a 'submit' transition for the analysis passed in is performed. Promotes the submit transition to the Worksheet to which the analysis belongs to. Note that for the worksheet there is already a guard that assures the transition to the worksheet will only be performed if all analyses within the worksheet have already been transitioned. This function is called automatically by bika.lims.workfow.AfterTransitionEventHandler """ # Mark this analysis as ISubmitted alsoProvides(analysis, ISubmitted) # Promote to analyses this analysis depends on promote_to_dependencies(analysis, "submit") # TODO: REFLEX TO REMOVE # Do all the reflex rules process if IRequestAnalysis.providedBy(analysis): analysis._reflex_rule_process('submit') # Promote transition to worksheet ws = analysis.getWorksheet() if ws: doActionFor(ws, 'submit') push_reindex_to_actions_pool(ws) # Promote transition to Analysis Request if IRequestAnalysis.providedBy(analysis): doActionFor(analysis.getRequest(), 'submit') reindex_request(analysis)
def reindex_request(analysis, idxs=None): """Reindex the Analysis Request the analysis belongs to, as well as the ancestors recursively """ if not IRequestAnalysis.providedBy(analysis) or \ IDuplicateAnalysis.providedBy(analysis): # Analysis not directly bound to an Analysis Request. Do nothing return n_idxs = ['assigned_state', 'getDueDate'] n_idxs = idxs and list(set(idxs + n_idxs)) or n_idxs request = analysis.getRequest() ancestors = [request] + request.getAncestors(all_ancestors=True) for ancestor in ancestors: push_reindex_to_actions_pool(ancestor, n_idxs)
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))) # 0. Open the actions pool actions_pool = ActionHandlerPool.get_instance() actions_pool.queue_pool() # 1. Create the Retest (Analysis Request) ignore = ['Analyses', 'DatePublished', 'Invalidated', 'Sample'] retest = _createObjectByType("AnalysisRequest", ar.aq_parent, tmpID()) retest.setSample(ar.getSample()) copy_field_values(ar, retest, ignore_fieldnames=ignore) renameAfterCreation(retest) # 2. 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) # 3. Assign the source to retest retest.setInvalidated(ar) # 4. Transition the retest to "sample_received"! changeWorkflowState(retest, 'bika_ar_workflow', 'sample_received') # 5. Reindex and other stuff push_reindex_to_actions_pool(retest) push_reindex_to_actions_pool(retest.aq_parent) # 6. Resume the actions pool actions_pool.resume() return retest
def remove_analysis_from_worksheet(analysis): """Removes the analysis passed in from the worksheet, if assigned to any """ worksheet = analysis.getWorksheet() if not worksheet: return analyses = filter(lambda an: an != analysis, worksheet.getAnalyses()) worksheet.setAnalyses(analyses) worksheet.purgeLayout() if analyses: # Maybe this analysis was the only one that was not yet submitted or # verified, so try to submit or verify the Worksheet to be aligned # with the current states of the analyses it contains. doActionFor(worksheet, "submit") doActionFor(worksheet, "verify") else: # We've removed all analyses. Rollback to "open" doActionFor(worksheet, "rollback_to_open") # Reindex the Worksheet idxs = ["getAnalysesUIDs", "getDepartmentUIDs"] push_reindex_to_actions_pool(worksheet, idxs=idxs)