Prechádzať zdrojové kódy

Merge branch 'dev-vj-notes' of rav.triplestart.com:jmudaka/stagfe2 into dev-josh-notes

= 3 rokov pred
rodič
commit
e67b603d37

+ 24 - 1
app/Models/Point.php

@@ -20,7 +20,7 @@ class Point extends Model
 
     public function lastChildPlan()
     {
-        return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
+        return $this->hasOne(Point::class, 'id', 'last_child_plan_point_id');
     }
 
     public function lastChildPlanNote()
@@ -62,4 +62,27 @@ class Point extends Model
         }
         return $points;
     }
+
+    public static function getPlanPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('addition_reason_category', 'DURING_VISIT')
+            ->where(function ($query1) use ($_note) {
+                $query1
+                    ->where('is_removed', false)
+                    ->orWhere(function ($query2) use ($_note) {
+                        $query2->where('is_removed', true)
+                            ->where('removed_in_note_id', $_note->id);
+                    });
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
 }

+ 22 - 9
resources/views/app/patient/segment-templates/_child_review/edit-review.php

@@ -1,6 +1,25 @@
-<div visit-moe>
+<?php
+if (!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+$epPart = ($intakeOrVisit === 'INTAKE') ? 'Review' : 'Plan';
+$currentValue = '';
+if($intakeOrVisit === 'INTAKE') {
+    if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
+        $parsedReview = json_decode($point->lastChildReview->data);
+        $currentValue = $parsedReview->value;
+    }
+}
+else {
+    if ($point->lastChildPlan && $point->last_child_plan_point_scoped_note_id === $note->id) {
+        $parsedReview = json_decode($point->lastChildPlan->data);
+        $currentValue = $parsedReview->value;
+    }
+}
+?>
+<div visit-moe relative>
     <a start show href="#">Edit</a>
-    <form url="/api/visitPoint/upsertChildReview" class="mcp-theme-1">
+    <form url="/api/visitPoint/upsertChild<?= $epPart ?>" class="mcp-theme-1" right>
         <input type="hidden" name="uid" value="<?= $point->uid ?>">
         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
         <input type="hidden" name="data">
@@ -8,13 +27,7 @@
         <p class="mb-2"><b>Review</b></p>
 
         <div class="mb-2">
-            <textarea data-name="value" class="form-control form-control-sm" rows="3"
-            ><?php
-                if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
-                    $parsedReview = json_decode($point->lastChildReview->data);
-                    echo $parsedReview->value;
-                }
-                ?></textarea>
+            <textarea data-name="value" class="form-control form-control-sm" rows="3"><?= $currentValue ?></textarea>
         </div>
         <div>
             <button submit class="btn btn-sm btn-primary mr-2">Save</button>

+ 35 - 11
resources/views/app/patient/segment-templates/_child_review/last-review.php

@@ -1,14 +1,38 @@
-<?php if($point->lastChildReview): ?>
-    <?php $parsedReview = json_decode($point->lastChildReview->data); ?>
-    <div><?= $parsedReview->value ?></div>
-    <div class="text-secondary text-sm"></div>
-    <?php if($point->last_child_review_point_scoped_note_id === $note->id): ?>
-        <span class="text-secondary text-sm">(reviewed on this note)</span>
+<?php
+if (!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+?>
+<?php if ($intakeOrVisit === 'INTAKE'): ?>
+    <?php if ($point->lastChildReview): ?>
+        <?php $parsedReview = json_decode($point->lastChildReview->data); ?>
+        <div><?= $parsedReview->value ?></div>
+        <div class="text-secondary text-sm"></div>
+        <?php if ($point->last_child_review_point_scoped_note_id === $note->id): ?>
+            <span class="text-secondary text-sm">(reviewed on this note)</span>
+        <?php else: ?>
+            <a native target="_blank"
+               href="<?= route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $point->lastChildReviewNote]) ?>">
+                <?= friendlier_date_time($point->last_child_review_effective_date) ?>
+            </a>
+        <?php endif; ?>
     <?php else: ?>
-        <a native target="_blank" href="<?= route('patients.view.notes.view.dashboard', ['patient'=>$patient, 'note'=>$point->lastChildReviewNote])?>">
-            <?= friendlier_date_time($point->last_child_review_effective_date) ?>
-        </a>
+        <span class="text-secondary text-sm">None</span>
     <?php endif; ?>
 <?php else: ?>
-    <span class="text-secondary text-sm">None</span>
-<?php endif; ?>
+    <?php if ($point->lastChildPlan): ?>
+        <?php $parsedReview = json_decode($point->lastChildPlan->data); ?>
+        <div><?= $parsedReview->value ?></div>
+        <div class="text-secondary text-sm"></div>
+        <?php if ($point->last_child_plan_point_scoped_note_id === $note->id): ?>
+            <span class="text-secondary text-sm">(reviewed on this note)</span>
+        <?php else: ?>
+            <a native target="_blank"
+               href="<?= route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $point->lastChildPlanNote]) ?>">
+                <?= friendlier_date_time($point->last_child_plan_effective_date) ?>
+            </a>
+        <?php endif; ?>
+    <?php else: ?>
+        <span class="text-secondary text-sm">None</span>
+    <?php endif; ?>
+<?php endif; ?>

+ 14 - 7
resources/views/app/patient/segment-templates/_common_actions/remove-undo.php

@@ -1,8 +1,15 @@
+<?php
+if(!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+$whenLabel = ($intakeOrVisit === 'INTAKE') ? 'on intake' : 'during visit';
+$epPart = ($intakeOrVisit === 'INTAKE') ? 'OnIntake' : 'DuringVisit';
+?>
 <?php if ($point->is_removed): ?>
     <?php if ($point->is_removed_due_to_entry_error): ?>
         <span class="font-weight-bold text-secondary mr-2 text-nowrap">Entry error</span>
     <?php else: ?>
-        <span class="font-weight-bold text-secondary mr-2 text-nowrap">Removed on intake</span>
+        <span class="font-weight-bold text-secondary mr-2 text-nowrap">Removed <?= $whenLabel ?></span>
     <?php endif; ?>
     <div visit-moe>
         <form show url="/api/visitPoint/undoMarkRemoved" class="mcp-theme-1">
@@ -13,15 +20,15 @@
     </div>
 <?php else: ?>
     <?php if($point->added_in_note_id === $note->id): ?>
-        <span class="font-weight-bold text-success mx-2 text-nowrap">* Added on intake</span>
+        <span class="font-weight-bold text-success mx-2 text-nowrap">* Added <?= $whenLabel ?></span>
     <?php endif; ?>
     <div visit-moe>
         <a start show href="#">Remove</a>
-        <form url="/api/visitPoint/markRemovedOnIntake" class="mcp-theme-1">
+        <form url="/api/visitPoint/markRemoved<?= $epPart ?>" class="mcp-theme-1">
             <input type="hidden" name="uid" value="<?= $point->uid ?>">
             <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
 
-            <p class="mb-2"><b>Remove <?= $label ?> (on intake)</b></p>
+            <p class="mb-2"><b>Remove <?= $label ?> <?= $whenLabel ?></b></p>
 
             <div class="mb-2">
                 <label class="text-sm text-secondary mb-1">Removal Reason</label>
@@ -130,11 +137,11 @@
             </div>
             <div class="border-bottom">
                 <div visit-moe>
-                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Mark as added during visit</a>
-                    <form url="/api/visitPoint/markAddedDuringVisit" class="mcp-theme-1">
+                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Mark as added <?= $whenLabel ?></a>
+                    <form url="/api/visitPoint/markAdded<?= $epPart ?>" class="mcp-theme-1">
                         <input type="hidden" name="uid" value="<?= $point->uid ?>">
                         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                        <p class="mb-2"><b>Mark as added during visit</b></p>
+                        <p class="mb-2"><b>Mark as added <?= $whenLabel ?></b></p>
                         <div class="mb-2">
                             <label class="text-sm text-secondary mb-1">Addition Reason</label>
                             <textarea name="additionReasonMemo" class="form-control form-control-sm" rows="2"></textarea>

+ 1 - 21
resources/views/app/patient/segment-templates/intake_medications/summary.blade.php

@@ -4,27 +4,7 @@ use App\Models\Point;
 
 /** @var \App\Models\Client $patient */
 
-$medications = Point
-    ::where('client_id', $patient->id)
-    ->where('category', 'MEDICATION')
-    ->where('addition_reason_category', 'ON_INTAKE')
-    ->where(function ($query1) use ($note) {
-        $query1
-            ->where('is_removed', false)
-            ->orWhere(function ($query2) use ($note) {
-                $query2->where('is_removed', true)
-                    ->where('is_removed_due_to_entry_error', false)
-                    ->where('removed_in_note_id', $note->id);
-            });
-    })
-    ->orderBy('created_at')
-    ->get();
-
-foreach ($medications as $medication) {
-    if ($medication->data) {
-        $medication->data = json_decode($medication->data);
-    }
-}
+$medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
 
 ?>
 

+ 217 - 1
resources/views/app/patient/segment-templates/plan_medications/edit.blade.php

@@ -1 +1,217 @@
-<h1>Edit for plan_medications</h1>
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$medications = Point::getPlanPointsOfCategory($patient, 'MEDICATION', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Medication</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($medications as $medication): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                                <?= !!@($medication->data->strength) ? '/&nbsp;' . @($medication->data->strength) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $medication;
+                                $label = 'Medication';
+                                $intakeOrVisit = 'PLAN';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $medication;
+                        $intakeOrVisit = 'PLAN';
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $medication;
+                        $intakeOrVisit = 'PLAN';
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe large class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new medication, prescribed during this visit</a>
+        <form url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="MEDICATION">
+            <input type="hidden" name="data">
+
+            <input type="hidden" data-name="medNameId">
+            <input type="hidden" data-name="route">
+            <input type="hidden" data-name="dose">
+            <input type="hidden" data-name="strength">
+            <input type="hidden" data-name="medId">
+
+            <p class="mb-2"><b>Add Medication (during visit)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text"
+                       data-name="name"
+                       class="form-control form-control-sm"
+                       stag-suggest
+                       stag-suggest-ep="/fdb-med-suggest/json">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Route</label>
+                <select data-name="routedMedId"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Dosage</label>
+                <select data-name="routedDosageFormMedId"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Strength</label>
+                <select data-name="gcnSeqno"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </div>
+
+            <div>
+                <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
+                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+            </div>
+        </form>
+    </div>
+</div>
+
+
+<script>
+    window.segmentInitializers.<?= $segment->segmentTemplate->internal_name ?> = function() {
+        // any JS can come here
+        // will be run on page-load as well as whenever this segment is refreshed
+
+        $('input[stag-suggest][data-name="name"]')
+            .off('stag-suggest-selected')
+            .on('stag-suggest-selected', (_e, _input, _data) => {
+
+                // _input is the textbox
+                // _data is {med_name_id: "50567", text: "Children's Tylenol"}
+
+                let medNameID = _data.med_name_id;
+                $('input[data-name="medNameId"]').val(medNameID);
+
+                let routeSelect = $('[data-name="routedMedId"]').empty().prop('disabled', true);
+                let dosageSelect = $('[data-name="routedDosageFormMedId"]').empty().prop('disabled', true);
+                let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+
+                $.get('/fdb-routed-meds?med-name-id=' + medNameID, _data => {
+                    routeSelect
+                        .empty()
+                        .append('<option value="">-- select --</option>');
+                    for (let i = 0; i < _data.length; i++) {
+                        routeSelect.append('<option value="' + _data[i].routed_med_id + '">' + _data[i].med_routed_med_id_desc + '</option>')
+                    }
+                    routeSelect.prop('disabled', false);
+                    if(_data.length === 1) {
+                        routeSelect.val(_data[0].routed_med_id).trigger('change');
+                    }
+                }, 'json');
+            });
+
+        // on route selection
+        $(document).off('change', '[data-name="routedMedId"]');
+        $(document).on('change', '[data-name="routedMedId"]', function () {
+
+            // clear
+            let dosageSelect = $('[data-name="routedDosageFormMedId"]').empty().prop('disabled', true);
+            let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+            let routedMedID = $(this).val();
+            $('input[data-name="route"]').val($(this).find('option:selected').text());
+
+            $.get('/fdb-routed-dosages?routed-med-id=' + routedMedID, _data => {
+                dosageSelect
+                    .empty()
+                    .append('<option value="">-- select --</option>');
+                for (let i = 0; i < _data.length; i++) {
+                    dosageSelect.append('<option value="' + _data[i].routed_dosage_form_med_id + '">' + _data[i].med_routed_df_med_id_desc + '</option>')
+                }
+                dosageSelect.prop('disabled', false);
+                if(_data.length === 1) {
+                    dosageSelect.val(_data[0].routed_dosage_form_med_id).trigger('change');
+                }
+            }, 'json');
+        });
+
+        // on dosage selection
+        $(document).off('change', '[data-name="routedDosageFormMedId"]');
+        $(document).on('change', '[data-name="routedDosageFormMedId"]', function () {
+
+            // clear
+            let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+            let dosageFormMedID = $(this).val();
+            $('input[data-name="dose"]').val($(this).find('option:selected').text());
+
+            $.get('/fdb-meds?dosage-form-med-id=' + dosageFormMedID, _data => {
+                strengthSelect
+                    .empty()
+                    .append('<option value="">-- select --</option>');
+                for (let i = 0; i < _data.length; i++) {
+                    strengthSelect.append('<option data-medid="' + _data[i].medid + '" value="' + _data[i].gcn_seqno + '">' + _data[i].med_medid_desc + '</option>')
+                }
+                strengthSelect.prop('disabled', false);
+                if(_data.length === 1) {
+                    strengthSelect.val(_data[0].gcn_seqno).trigger('change');
+                    $('input[data-name="description"]').focus();
+                }
+            }, 'json');
+        });
+
+        // on strength (medid) selection
+        $(document).off('change', '[data-name="gcnSeqno"]');
+        $(document).on('change', '[data-name="gcnSeqno"]', function () {
+
+            $('input[data-name="medId"]').val($(this).find('option:selected').attr('data-medid'));
+            $('input[data-name="strength"]').val($(this).find('option:selected').text());
+
+        });
+
+    };
+</script>
+

+ 30 - 1
resources/views/app/patient/segment-templates/plan_medications/summary.blade.php

@@ -1 +1,30 @@
-<h1>Summary for plan_medications</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$medications = Point::getPlanPointsOfCategory($patient, 'MEDICATION', $note);
+
+?>
+
+<?php if (!count($medications)): ?>
+    <div class="text-secondary">No medications</div>
+<?php else: ?>
+    <?php foreach ($medications as $medication): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                <?= !!@($medication->data->frequency) ? '/&nbsp;' . @($medication->data->frequency) : '' ?>
+            </div>
+            <?php if ($medication->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($medication->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+