|
10 | 10 |
|
11 | 11 | @indexer(IAnalysisRequest)
|
12 | 12 | def assigned_state(instance):
|
13 |
| - """Returns `assigned` or `unassigned` depending on the state of the |
14 |
| - analyses the analysisrequest contains. Return `unassigned` if the Analysis |
15 |
| - Request has at least one analysis in `unassigned` state. |
16 |
| - Otherwise, returns `assigned` |
| 13 | + """Returns `assigned`, `unassigned` or 'not_applicable' depending on the |
| 14 | + state of the analyses the analysisrequest contains. Return `unassigned` if |
| 15 | + the Analysis Request has at least one 'active' analysis in `unassigned` |
| 16 | + status. Returns 'assigned' if all 'active' analyses of the sample are |
| 17 | + assigned to a Worksheet. Returns 'not_applicable' if no 'active' analyses |
| 18 | + for the given sample exist |
17 | 19 | """
|
18 |
| - analyses = instance.getAnalyses() |
19 |
| - if not analyses: |
20 |
| - return "unassigned" |
21 |
| - for analysis in analyses: |
22 |
| - analysis_object = api.get_object(analysis) |
23 |
| - if not analysis_object.getWorksheet(): |
| 20 | + assigned = False |
| 21 | + skip_statuses = ["retracted", "rejected", "cancelled"] |
| 22 | + |
| 23 | + # Retrieve analyses directly from the instance container instead of relying |
| 24 | + # on ARAnalysesField getter, that performs a catalog query. Reason is, that |
| 25 | + # we never know if the sample is indexed before the analyses or any other |
| 26 | + # dependent catalog |
| 27 | + for analysis in instance.objectValues(spec="Analysis"): |
| 28 | + status = api.get_review_status(analysis) |
| 29 | + |
| 30 | + if status == "unassigned": |
| 31 | + # One unassigned found, no need to go further |
24 | 32 | return "unassigned"
|
25 |
| - return "assigned" |
| 33 | + |
| 34 | + if status in skip_statuses: |
| 35 | + # Skip "inactive" analyses |
| 36 | + continue |
| 37 | + |
| 38 | + if analysis.getWorksheetUID(): |
| 39 | + # At least one analysis with a worksheet assigned |
| 40 | + assigned = True |
| 41 | + |
| 42 | + # ARAnalysesField getter returns all the analyses from the sample, those |
| 43 | + # from partitions included. Since we do not rely on the getter, we need to |
| 44 | + # manually extract the analyses from the partitions |
| 45 | + # Pity is, that for the retrieval of partitions we need to rely on |
| 46 | + # getBackReferences, that is a query against reference_catalog |
| 47 | + for partition in instance.getDescendants(): |
| 48 | + # Note we call this same index, but for the partition |
| 49 | + partition_status = assigned_state(partition)() |
| 50 | + if partition_status == "unassigned": |
| 51 | + # One of the partitions with unassigned, no need to go further |
| 52 | + return "unassigned" |
| 53 | + |
| 54 | + elif partition_status == "assigned": |
| 55 | + assigned = True |
| 56 | + |
| 57 | + if assigned: |
| 58 | + # All "active" analyses assigned to a worksheet |
| 59 | + return "assigned" |
| 60 | + |
| 61 | + # Sample without "active" assigned/unassigned analyses |
| 62 | + return "not_applicable" |
26 | 63 |
|
27 | 64 |
|
28 | 65 | @indexer(IAnalysisRequest)
|
|
0 commit comments