@@ -52,10 +52,22 @@ def new_seen_orders_table(context: dict, area: Area | None = None) -> dict:
5252 .exclude (is_urgent = True )
5353 .select_related ("genrequest" )
5454 .annotate (
55- sample_count = models .Count ("extractionorder__samples" ),
55+ sample_count = models .Case (
56+ models .When (
57+ extractionorder__isnull = False ,
58+ then = models .Count (
59+ "extractionorder__samples" , distinct = True ),
60+ ),
61+ models .When (
62+ analysisorder__isnull = False ,
63+ then = models .Count ("analysisorder__samples" , distinct = True ),
64+ ),
65+ default = 0 ,
66+ ),
5667 priority = models .Case (
5768 models .When (is_urgent = True , then = Order .OrderPriority .URGENT ),
58- models .When (is_prioritized = True , then = Order .OrderPriority .PRIORITIZED ),
69+ models .When (is_prioritized = True ,
70+ then = Order .OrderPriority .PRIORITIZED ),
5971 default = 1 ,
6072 ),
6173 )
@@ -84,7 +96,18 @@ def new_unseen_orders_table(context: dict, area: Area | None = None) -> dict:
8496 .exclude (is_urgent = True )
8597 .select_related ("genrequest" )
8698 .annotate (
87- sample_count = models .Count ("extractionorder__samples" ),
99+ sample_count = models .Case (
100+ models .When (
101+ extractionorder__isnull = False ,
102+ then = models .Count (
103+ "extractionorder__samples" , distinct = True ),
104+ ),
105+ models .When (
106+ analysisorder__isnull = False ,
107+ then = models .Count ("analysisorder__samples" , distinct = True ),
108+ ),
109+ default = 0 ,
110+ )
88111 )
89112 .prefetch_related (
90113 "analysisorder__markers" ,
@@ -96,6 +119,8 @@ def new_unseen_orders_table(context: dict, area: Area | None = None) -> dict:
96119
97120 new_orders = new_orders .order_by ("-created_at" )
98121
122+ print (new_orders .values ())
123+
99124 return {
100125 "title" : "New unseen orders" ,
101126 "table" : NewUnseenOrderTable (new_orders ),
@@ -116,12 +141,12 @@ def assigned_orders_table(context: dict) -> dict:
116141 )
117142 .select_related ("genrequest" )
118143 .annotate (
119- sample_count = models .Count ("extractionorder__samples" ),
120- )
121- .annotate (
144+ sample_count = models .Count (
145+ "extractionorder__samples" , distinct = True ),
122146 priority = models .Case (
123147 models .When (is_urgent = True , then = Order .OrderPriority .URGENT ),
124- models .When (is_prioritized = True , then = Order .OrderPriority .PRIORITIZED ),
148+ models .When (is_prioritized = True ,
149+ then = Order .OrderPriority .PRIORITIZED ),
125150 default = 1 ,
126151 )
127152 )
0 commit comments