Explorar o código

Medications center (wip)

Vijayakrishnan %!s(int64=3) %!d(string=hai) anos
pai
achega
5b6f85c82f
Modificáronse 1 ficheiros con 182 adicións e 7 borrados
  1. 182 7
      resources/views/app/patient/medications-center.blade.php

+ 182 - 7
resources/views/app/patient/medications-center.blade.php

@@ -13,6 +13,7 @@ $points = Point
     ->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) {
@@ -34,6 +35,7 @@ $medications = $points;
                 <th class="border-bottom-0 text-secondary">Frequency</th>
                 <th class="border-bottom-0 text-secondary">Active?</th>
                 <th class="border-bottom-0 text-secondary">Edit</th>
+                <th class="border-bottom-0 text-secondary">Delete</th>
                 <th class="border-bottom-0 text-secondary">Started</th>
                 <th class="border-bottom-0 text-secondary">Ended</th>
                 <th class="border-bottom-0 text-secondary">Last Review</th>
@@ -42,29 +44,146 @@ $medications = $points;
             </thead>
             <?php foreach($medications as $medication): ?>
             <?php $point = $medication; ?>
-            <tr>
+            <tr class="{{$medication->is_removed ? 'on-hover-opaque' : ''}}">
                 <td>
-                    <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                    <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
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @endif
+                        <div>
+                            <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                            @if(!$medication->is_removed && $medication->added_in_note_id === $note->id)
+                                <div class="mt-1 text-sm text-secondary">Added during this visit</div>
+                            @endif
+                            @if($medication->is_removed && ($medication->added_in_note_id !== $note->id && $medication->removed_in_note_id === $note->id))
+                                <div class="mt-1 text-sm text-secondary">Discontinued during this visit</div>
+                            @endif
+                        </div>
+                    </div>
                 </td>
                 <td>
                     <?= !!@($medication->data->frequency) ? @($medication->data->frequency) : '-' ?>
                 </td>
                 <td>
-                    <?= $medication->is_removed ? 'NO' : '<b>YES</b>' ?>
+                    @if($medication->is_removed)
+                        NO
+                    @else
+                        <b>YES</b>
+                    @endif
                 </td>
                 <td>
-                    EDIT
+                    @if($medication->added_in_note_id === $note->id)
+                        <div moe wide>
+                            <a start show href="#" title="Edit">Edit</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1 frm-edit-medication">
+                                <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <p class="mb-2"><b>Update Medication</b></p>
+
+                                <input type="hidden" name="data">
+
+                                <input type="hidden" data-name="medId">
+                                <input type="hidden" data-name="routedMedId">
+                                <input type="hidden" data-name="routedDosageFormMedId">
+                                <input type="hidden" data-name="gcnSeqno">
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Drug</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset prescription-medication"
+                                           data-name="name"
+                                           value="{{@$medication->data->name}}"
+                                           stag-suggest
+                                           stag-suggest-ep="/fdb-med-suggest-v2/json">
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Frequency</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset"
+                                           data-option-list="frequency-options" data-field="frequency"
+                                           value="{{@$medication->data->frequency}}"
+                                           data-name="frequency">
+                                    <div id="frequency-options" class="data-option-list">
+                                        <div>Once a day</div>
+                                        <div>Twice a day</div>
+                                    </div>
+                                </div>
+
+                                <div>
+                                    <button type="submit" class="btn-save-medication btn btn-sm btn-primary mr-2">Save</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </td>
+                <td>
+                    @if(!$medication->is_removed)
+                        @if($medication->added_in_note_id === $note->id)
+                            <div moe>
+                                <a start show href="#" title="Delete">Delete</a>
+                                <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                    <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                    <input type="hidden" name="isRemoved" value="1">
+                                    <input type="hidden" name="isRemovedDueToEntryError" value="1">
+                                    <input type="hidden" name="removalReasonMemo" value="Entry Error">
+                                    <input type="hidden" name="removalEffectiveDate" value="<?= date('Y-m-d') ?>">
+                                    <p class="mb-2"><b>Delete this medication?</b></p>
+                                    <div>
+                                        <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @else
+                            <div moe>
+                                <a start show href="#" title="Discontinue">Discontinue</a>
+                                <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                    <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                    <input type="hidden" name="isRemoved" value="1">
+                                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+                                    <p class="mb-2"><b>Discontinue this medication?</b></p>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Already stopped / Stop now</label>
+                                        <select class="form-control form-control-sm" name="removalReasonCategory" required>
+                                            <option value="">-- select --</option>
+                                            <option value="ON_INTAKE">Already stopped (before this visit)</option>
+                                            <option value="DURING_VISIT">Stop now</option>
+                                        </select>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Reason</label>
+                                        <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
+                                        <input type="date" name="removalEffectiveDate"
+                                               value="<?= date('Y-m-d') ?>"
+                                               max="<?= date('Y-m-d') ?>"
+                                               class="form-control form-control-sm">
+                                    </div>
+                                    <div>
+                                        <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    @endif
                 </td>
                 <td>
                     <?= !!@($medication->data->start_date) ? @($medication->data->start_date) : '-' ?>
                     @if(!!@($medication->data->prescriber))
-                        <div class="mt-1">By: <?= !!@($medication->data->prescriber) ? @($medication->data->prescriber) : '-' ?></div>
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($medication->data->prescriber) ? @($medication->data->prescriber) : '-' ?></div>
                     @endif
                 </td>
                 <td>
                     <?= !!@($medication->removal_effective_date) ? @($medication->removal_effective_date) : '-' ?>
                     @if(!!@($medication->removal_reason_memo))
-                        <div class="mt-1">By: <?= !!@($medication->removal_reason_memo) ? @($medication->removal_reason_memo) : '-' ?></div>
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($medication->removal_reason_memo) ? @($medication->removal_reason_memo) : '-' ?></div>
                     @endif
                 </td>
                 <td>
@@ -159,7 +278,7 @@ $medications = $points;
 
                     <div class="d-flex align-items-center">
                         <button type="submit" class="btn btn-sm btn-primary mr-2">Submit</button>
-                        <button type="button" class="btn btn-sm btn-default border mr-2" onclick="closeStagPopup()">Close</button>
+                        <button type="button" class="btn btn-sm btn-default bg-white border mr-2" onclick="closeStagPopup()">Close</button>
                     </div>
                 </form>
             </div>
@@ -235,6 +354,62 @@ $medications = $points;
                     return false;
                 });
 
+            parentSegment.find('.frm-edit-medication')
+                .off('submit')
+                .on('submit', function () {
+
+                    debugger
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            // TODO: update intake and plan meds
+                            refreshDynamicStagPopup();
+                        }
+                    }, 'json');
+                    return false;
+                });
+
             initStagSuggest();
         }
         addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}')