hasOne(Point::class, 'id', 'last_child_review_point_id'); } public function lastChildReviewNote() { return $this->hasOne(Note::class, 'id', 'last_child_review_point_scoped_note_id'); } public function lastChildPlan() { return $this->hasOne(Point::class, 'id', 'last_child_plan_point_id'); } public function lastChildPlanNote() { return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id'); } public static function getGlobalSingletonOfCategory(Client $_patient, String $_category, $_assoc = false) { $point = Point ::where('client_id', $_patient->id) ->where('category', $_category) ->orderBy('created_at', 'DESC') ->first(); if ($point->data) { $point->data = json_decode($point->data, $_assoc); } return $point; } public static function getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) { $points = Point ::where('client_id', $_patient->id) ->where('category', $_category) ->where('addition_reason_category', 'ON_INTAKE') ->where(function ($query1) use ($_note) { $query1 ->where('is_removed', false) ->orWhere(function ($query2) use ($_note) { $query2->where('is_removed', true) ->where('removed_in_note_id', $_note->id); }); }) ->orderBy('created_at') ->get(); foreach ($points as $point) { if ($point->data) { $point->data = json_decode($point->data, $_assoc); } } return $points; } public static function getPlanPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) { $points = Point ::where('client_id', $_patient->id) ->where('category', $_category) ->where('addition_reason_category', 'DURING_VISIT') ->where(function ($query1) use ($_note) { $query1 ->where('is_removed', false) ->orWhere(function ($query2) use ($_note) { $query2->where('is_removed', true) ->where('removed_in_note_id', $_note->id); }); }) ->orderBy('created_at') ->get(); foreach ($points as $point) { if ($point->data) { $point->data = json_decode($point->data, $_assoc); } } return $points; } }