Point.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 && @$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. public static function getPointsOfCategory(Client $_patient, String $_category, $_assoc = false) {
  79. $points = Point
  80. ::where('client_id', $_patient->id)
  81. ->where('category', $_category)
  82. ->where('is_removed', false)
  83. ->orderBy('created_at')
  84. ->get();
  85. foreach ($points as $point) {
  86. if ($point->data) {
  87. $point->data = json_decode($point->data, $_assoc);
  88. }
  89. }
  90. return $points;
  91. }
  92. }