Point.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note) {
  24. $points = Point
  25. ::where('client_id', $_patient->id)
  26. ->where('category', $_category)
  27. ->where('addition_reason_category', 'ON_INTAKE')
  28. ->where(function ($query1) use ($_note) {
  29. $query1
  30. ->where('is_removed', false)
  31. ->orWhere(function ($query2) use ($_note) {
  32. $query2->where('is_removed', true)
  33. ->where('removed_in_note_id', $_note->id);
  34. });
  35. })
  36. ->orderBy('created_at')
  37. ->get();
  38. foreach ($points as $point) {
  39. if ($point->data) {
  40. $point->data = json_decode($point->data);
  41. }
  42. }
  43. return $points;
  44. }
  45. }