Forráskód Böngészése

Point::getUnifiedPointsOfCategory()

Vijayakrishnan 3 éve
szülő
commit
a022837c60
1 módosított fájl, 45 hozzáadás és 0 törlés
  1. 45 0
      app/Models/Point.php

+ 45 - 0
app/Models/Point.php

@@ -178,6 +178,51 @@ class Point extends Model
         return $points;
     }
 
+    public static function getUnifiedPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('is_removed_due_to_entry_error', false)
+            ->where(function ($query1) use ($_note) {
+                $query1
+
+                    ->where(function ($query2) use ($_note) { // added on_intake on this note
+                        $query2->where('is_removed', false)
+                            ->where('addition_reason_category', 'ON_INTAKE')
+                            ->where('added_in_note_id', $_note->id);
+                    })
+                    ->orWhere(function ($query2) use ($_note) { // removed on_intake on this note
+                        $query2->where('is_removed', true)
+                            ->where('removal_reason_category', 'ON_INTAKE')
+                            ->where('removed_in_note_id', $_note->id);
+                    })
+                    ->orWhere('last_child_review_point_scoped_note_id', $_note->id) // review added during this note
+
+                    ->where(function ($query2) use ($_note) { // added during_visit on this note
+                        $query2->where('is_removed', false)
+                            ->where('addition_reason_category', 'DURING_VISIT')
+                            ->where('added_in_note_id', $_note->id);
+                    })
+                    ->orWhere(function ($query2) use ($_note) { // removed during_visit on this note
+                        $query2->where('is_removed', true)
+                            ->where('removal_reason_category', 'DURING_VISIT')
+                            ->where('removed_in_note_id', $_note->id);
+                    })
+                    ->orWhere('last_child_plan_point_scoped_note_id', $_note->id) // plan added during this note
+
+                    // marked relevant to this note
+                    ->orWhereRaw("(SELECT count(id) from note_point WHERE is_active IS TRUE AND note_id = {$_note->id} AND point_id = point.id) > 0");
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
+
     public static function getPointsOfCategory(Client $_patient, String $_category, $_assoc = false) {
         $points = Point
             ::where('client_id', $_patient->id)