Kaynağa Gözat

rx wiz add/edit: logic updates

Vijayakrishnan 3 yıl önce
ebeveyn
işleme
c2bbceda5f

+ 51 - 0
app/Models/Point.php

@@ -166,4 +166,55 @@ class Point extends Model
         }
         return $points;
     }
+
+    public static function getPointsOfCategoryExtended(Client $_patient, String $_category, Note $_note) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', 'MEDICATION')
+            ->where(function ($q) use($_note) {
+                $q
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->orWhere('removed_in_note_id', '<>', $_note->id);
+            })
+            ->orderBy('is_removed')
+            ->orderBy('added_in_note_id', 'DESC')
+            ->orderBy('removal_effective_date', 'DESC')
+            ->orderByRaw('removed_in_note_id DESC NULLS FIRST')
+            ->orderBy('created_at')
+            ->get();
+
+        $pointsByType = [
+            "new" => [],
+            "preExisting" => [],
+            "historic" => [],
+            "eeFromOtherNote" => []
+        ];
+
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data);
+            }
+
+            if(!$point->is_removed && $point->added_in_note_id === $_note->id) {
+                $point->state = 1;
+                $pointsByType["new"][] = $point;
+            }
+            elseif(!$point->is_removed && $point->added_in_note_id !== $_note->id) {
+                $point->state = 2;
+                $pointsByType["preExisting"][] = $point;
+            }
+            elseif($point->is_removed && !$point->is_removed_due_to_entry_error) {
+                $point->state = 3;
+                $pointsByType["historic"][] = $point;
+            }
+            elseif($point->is_removed_due_to_entry_error) {
+                $point->state = 4;
+                $pointsByType["eeFromOtherNote"][] = $point;
+            }
+        }
+
+        $points = array_merge($pointsByType["new"], $pointsByType["preExisting"], $pointsByType["historic"], $pointsByType["eeFromOtherNote"]);
+
+        return $points;
+    }
 }

+ 11 - 20
resources/views/app/patient/medications-center.blade.php

@@ -8,20 +8,7 @@ use App\Models\Segment;
 /** @var Client $patient */
 /** @var Note $note */
 
-$points = Point
-    ::where('client_id', $patient->id)
-    ->where('category', 'MEDICATION')
-    ->where('is_removed_due_to_entry_error', false)
-    ->orderBy('is_removed')
-    ->orderBy('removal_effective_date', 'DESC')
-    ->orderBy('created_at')
-    ->get();
-foreach ($points as $point) {
-    if ($point->data) {
-        $point->data = json_decode($point->data);
-    }
-}
-$medications = $points;
+$medications = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note);
 
 ?>
 
@@ -43,15 +30,15 @@ $medications = $points;
                 <th class="border-bottom-0 text-secondary w-25">Review</th>
             </tr>
             </thead>
-            <?php $prevRowRemoved = -1; ?>
+            <?php $prevRowState = -1; ?>
             <?php foreach($medications as $medication): ?>
             <?php $point = $medication; ?>
-            @if($prevRowRemoved !== -1 && $prevRowRemoved !== $medication->is_removed)
+            @if($prevRowState !== -1 && $prevRowState !== $medication->state)
                 <tr>
                     <td colspan="10" class="px-0 pt-1 pb-0 on-hover-opaque bg-secondary"></td>
                 </tr>
             @endif
-            <?php $prevRowRemoved = $medication->is_removed; ?>
+            <?php $prevRowState = $medication->state; ?>
             <?php $rel = $medication->relevanceToNote($note); ?>
             <tr class="{{$medication->is_removed ? '' : ''}}">
                 @if($patient->core_note_id !== $note->id)
@@ -71,10 +58,14 @@ $medications = $points;
                 @endif
                 <td>
                     <div class="d-flex align-items-baseline">
-                        @if($medication->is_removed)
-                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
-                        @else
+                        @if($medication->state === 1)
                             <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($medication->state === 2)
+                            <i class="text-info fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($medication->state === 3)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($medication->state === 4)
+                            <i class="text-secondary fa fa-circle text-sm on-hover-opaque mr-2"></i>
                         @endif
                         <div>
                             <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>

+ 2 - 2
resources/views/app/patient/wizard-partials/common-fields.blade.php

@@ -22,13 +22,13 @@
             <label class="my-0 d-inline-flex align-items-center">
                 <input type="radio" name="additionReasonCategory" value="ON_INTAKE"
                         {{$point && $point->addition_reason_category === 'ON_INTAKE' ? 'checked' : ''}}
-                        {{$point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
+                        {{0 && $point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
                 <span class="ml-1">Pre-existing</span>
             </label>
             <label class="ml-3 my-0 d-inline-flex align-items-center">
                 <input type="radio" name="additionReasonCategory" value="DURING_VISIT"
                         {{$point && $point->addition_reason_category === 'DURING_VISIT' ? 'checked' : ''}}
-                        {{$point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
+                        {{0 && $point && $point->added_in_note_id !== $note->id ? 'readonly disabled' : ''}}>
                 <span class="ml-1">Added during this visit (as part of my plan)</span>
             </label>
         </div>