12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Models;
- # use Illuminate\Database\Eloquent\Model;
- class Point extends Model
- {
- protected $table = 'point';
- public function lastChildReview()
- {
- return $this->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;
- }
- }
|