Point.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_plan_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. public static function getPlanPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
  57. $points = Point
  58. ::where('client_id', $_patient->id)
  59. ->where('category', $_category)
  60. ->where('addition_reason_category', 'DURING_VISIT')
  61. ->where(function ($query1) use ($_note) {
  62. $query1
  63. ->where('is_removed', false)
  64. ->orWhere(function ($query2) use ($_note) {
  65. $query2->where('is_removed', true)
  66. ->where('removed_in_note_id', $_note->id);
  67. });
  68. })
  69. ->orderBy('created_at')
  70. ->get();
  71. foreach ($points as $point) {
  72. if ($point->data) {
  73. $point->data = json_decode($point->data, $_assoc);
  74. }
  75. }
  76. return $points;
  77. }
  78. }