Point.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. class Point extends Model
  5. {
  6. protected $table = 'point';
  7. public function lastChildReview()
  8. {
  9. return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
  10. }
  11. public function lastChildReviewNote()
  12. {
  13. return $this->hasOne(Note::class, 'id', 'last_child_review_point_scoped_note_id');
  14. }
  15. public function lastChildPlan()
  16. {
  17. return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
  18. }
  19. public function lastChildPlanNote()
  20. {
  21. return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id');
  22. }
  23. public static function getGlobalSingletonOfCategory(Client $_patient, String $_category, $_assoc = false) {
  24. $point = Point
  25. ::where('client_id', $_patient->id)
  26. ->where('category', $_category)
  27. ->orderBy('created_at', 'DESC')
  28. ->first();
  29. if ($point->data) {
  30. $point->data = json_decode($point->data, $_assoc);
  31. }
  32. return $point;
  33. }
  34. public static function getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
  35. $points = Point
  36. ::where('client_id', $_patient->id)
  37. ->where('category', $_category)
  38. ->where('addition_reason_category', 'ON_INTAKE')
  39. ->where(function ($query1) use ($_note) {
  40. $query1
  41. ->where('is_removed', false)
  42. ->orWhere(function ($query2) use ($_note) {
  43. $query2->where('is_removed', true)
  44. ->where('removed_in_note_id', $_note->id);
  45. });
  46. })
  47. ->orderBy('created_at')
  48. ->get();
  49. foreach ($points as $point) {
  50. if ($point->data) {
  51. $point->data = json_decode($point->data, $_assoc);
  52. }
  53. }
  54. return $points;
  55. }
  56. }