Эх сурвалжийг харах

Allergies/rx/dx wizards - favorites impl

Vijayakrishnan 3 жил өмнө
parent
commit
4c430f41a4

+ 15 - 0
app/Models/Pro.php

@@ -334,6 +334,21 @@ class Pro extends Model
             ->get();
     }
 
+    public function favoritesByCategoryDecoded($_category) {
+        $favorites = ProFavorite::where('pro_id', $this->id)
+            ->where('is_removed', false)
+            ->where('category', $_category)
+            ->orderBy('category', 'asc')
+            ->orderBy('position_index', 'asc')
+            ->get();
+        foreach ($favorites as $favorite) {
+            if ($favorite->data) {
+                $favorite->data = json_decode($favorite->data);
+            }
+        }
+        return $favorites;
+    }
+
     function get_patients_count_as_mcp() {
         $query = Client::whereNull('shadow_pro_id');
         return $query->where('mcp_pro_id', $this->id)->count();

+ 62 - 2
resources/views/app/patient/allergies-center.blade.php

@@ -3,13 +3,21 @@
 use App\Models\Point;
 use App\Models\Client;
 use App\Models\Note;
-use App\Models\Segment;
+use App\Models\Pro;
 
 /** @var Client $patient */
 /** @var Note $note */
+/** @var Pro $pro */
 
 list($allergies, $counts) = Point::getPointsOfCategoryExtended($patient, 'ALLERGY', $note);
 $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
+$favorites = $pro->favoritesByCategoryDecoded('allergy');
+function isFavoriteAllergy($_allergy, $_favorites) {
+    foreach($_favorites as $favorite) {
+        if($favorite->data->name === $_allergy->data->name) return $favorite->uid;
+    }
+    return false;
+}
 ?>
 
 <div class="mt-3 p-3 border-top" id="allergies-center-{{$note->id}}">
@@ -49,6 +57,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
             <?php $prevRowState = -1; ?>
             <?php foreach($allergies as $allergy): ?>
             <?php $point = $allergy; ?>
+            <?php $favoriteUid = isFavoriteAllergy($allergy, $favorites); ?>
             @if($prevRowState !== $allergy->state)
                 @include('app.patient.wizard-partials.state-row', ['point' => $allergy])
             @endif
@@ -69,6 +78,27 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
                             <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
                             @include('app.patient.wizard-partials.state-badge', ['point' => $allergy, 'addedVerb' => 'Diagnosed'])
                         </div>
+                        <div class="ml-auto mr-1">
+                            <div moe>
+                                @if(!$favoriteUid)
+                                    <form show url="/api/proFavorite/create">
+                                        <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                                        <input type="hidden" name="category" value="allergy">
+                                        <textarea class="d-none" name="data">{!! json_encode(["name" => @($allergy->data->name), "damConceptId" => @($allergy->data->damConceptId), "damConceptIdType" => @($allergy->data->damConceptIdType),]) !!}</textarea>
+                                        <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-secondary-light" title="Add to common">
+                                            <i class="fa fa-bookmark"></i>
+                                        </button>
+                                    </form>
+                                @else
+                                    <form show url="/api/proFavorite/remove">
+                                        <input type="hidden" name="uid" value="{{$favoriteUid}}">
+                                        <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-info" title="Remove from common">
+                                            <i class="fa fa-bookmark"></i>
+                                        </button>
+                                    </form>
+                                @endif
+                            </div>
+                        </div>
                     </div>
                 </td>
                 <td>
@@ -203,7 +233,27 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
 
                     <div class="row">
                         <div class="col-8">
-                            <p class="mb-2"><b>Add Allergy</b></p>
+                            <div class="d-flex align-items-baseline mb-2">
+                                <b>Add Allergy</b>
+                                @if(count($favorites))
+                                    <div class="d-inline position-relative on-click-menu ml-4">
+                                        <span class="text-primary c-pointer">
+                                            <i class="fa fa-bookmark text-info mr-1"></i> Common Allergies <i class="ml-1 fa fa-caret-down"></i>
+                                        </span>
+                                        <div menu right class="bg-white border">
+                                            @foreach($favorites as $favorite)
+                                                <a native target="_blank" href="#"
+                                                   data-name="{{@($favorite->data->name)}}"
+                                                   data-damConceptId="{{@($favorite->data->damConceptId)}}"
+                                                   data-damConceptIdType="{{@($favorite->data->damConceptIdType)}}"
+                                                   class="px-2 py-1 d-block text-nowrap text-sm favorite-item">
+                                                    {{$favorite->data->name}}
+                                                </a>
+                                            @endforeach
+                                        </div>
+                                    </div>
+                                @endif
+                            </div>
                             <div class="mb-2">
                                 <label class="text-sm mb-0 font-weight-bold">Name</label>
                                 <input type="text" data-name="name" class="form-control form-control-sm"
@@ -265,6 +315,16 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
             @if($numActiveItems && $tracker && @($tracker->data->no_known_allergies_of_any_type))
                 parentSegment.find('[data-field-name="no_known_allergies_of_any_type"]').prop('checked', false).trigger('change');
             @endif
+
+            parentSegment.find('.favorite-item')
+                .off('click.add-from-favorite')
+                .on('click.add-from-favorite', function () {
+                    $('#frm-add-allergy').find('input[data-name="name"]').val($(this).attr('data-name'));
+                    $('#frm-add-allergy').find('input[data-name="damConceptId"]').val($(this).attr('data-damConceptId'));
+                    $('#frm-add-allergy').find('input[data-name="damConceptIdType"]').val($(this).attr('data-damConceptIdType'));
+                    $(this).closest('.on-click-menu').find('[menu]').hide();
+                    return false;
+                });
         }
         addMCInitializer('allergies-center-{{$note->id}}', init, '#allergies-center-{{$note->id}}');
     }).call(window);

+ 67 - 3
resources/views/app/patient/medications-center.blade.php

@@ -3,14 +3,21 @@
 use App\Models\Point;
 use App\Models\Client;
 use App\Models\Note;
-use App\Models\Segment;
+use App\Models\Pro;
 
 /** @var Client $patient */
 /** @var Note $note */
+/** @var Pro $pro */
 
 list($medications, $counts) = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note);
 $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
-
+$favorites = $pro->favoritesByCategoryDecoded('medication');
+function isFavoriteMedication($_medication, $_favorites) {
+    foreach($_favorites as $favorite) {
+        if($favorite->data->name === $_medication->data->name) return $favorite->uid;
+    }
+    return false;
+}
 ?>
 
 <div class="mt-3 p-3 border-top" id="medications-center-{{$note->id}}">
@@ -44,6 +51,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
             <?php $prevRowState = -1; ?>
             <?php foreach($medications as $medication): ?>
                 <?php $point = $medication; ?>
+                <?php $favoriteUid = isFavoriteMedication($medication, $favorites); ?>
                 @if($prevRowState !== $medication->state)
                     @include('app.patient.wizard-partials.state-row', ['point' => $medication])
                 @endif
@@ -64,6 +72,28 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
                                 <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
                                 @include('app.patient.wizard-partials.state-badge', ['point' => $medication, 'addedVerb' => 'Prescribed', 'removedVerb' => 'Discontinued'])
                             </div>
+                            <div class="ml-auto mr-1">
+                                <div moe>
+                                    @if(!$favoriteUid)
+                                        <form show url="/api/proFavorite/create">
+                                            <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                                            <input type="hidden" name="category" value="medication">
+                                            <textarea class="d-none"
+                                                      name="data">{!! json_encode(["name" => @($medication->data->name), "medId" => @($medication->data->medId), "routedMedId" => @($medication->data->routedMedId), "routedDosageFormMedId" => @($medication->data->routedDosageFormMedId), "gcnSeqno" => @($medication->data->gcnSeqno)]) !!}</textarea>
+                                            <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-secondary-light" title="Add to common">
+                                                <i class="fa fa-bookmark"></i>
+                                            </button>
+                                        </form>
+                                    @else
+                                        <form show url="/api/proFavorite/remove">
+                                            <input type="hidden" name="uid" value="{{$favoriteUid}}">
+                                            <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-info" title="Remove from common">
+                                                <i class="fa fa-bookmark"></i>
+                                            </button>
+                                        </form>
+                                    @endif
+                                </div>
+                            </div>
                         </div>
                     </td>
                     <td>
@@ -204,7 +234,29 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
 
                     <div class="row">
                         <div class="col-8">
-                            <p class="mb-2"><b>Add Medication</b></p>
+                            <div class="d-flex align-items-baseline mb-2">
+                                <b>Add Medication</b>
+                                @if(count($favorites))
+                                    <div class="d-inline position-relative on-click-menu ml-4">
+                                        <span class="text-primary c-pointer">
+                                            <i class="fa fa-bookmark text-info mr-1"></i> Common Medications <i class="ml-1 fa fa-caret-down"></i>
+                                        </span>
+                                        <div menu right class="bg-white border">
+                                            @foreach($favorites as $favorite)
+                                                <a native target="_blank" href="#"
+                                                   data-name="{{@($favorite->data->name)}}"
+                                                   data-medId="{{@($favorite->data->medId)}}"
+                                                   data-routedMedId="{{@($favorite->data->routedMedId)}}"
+                                                   data-routedDosageFormMedId="{{@($favorite->data->routedDosageFormMedId)}}"
+                                                   data-gcnSeqno="{{@($favorite->data->gcnSeqno)}}"
+                                                   class="px-2 py-1 d-block text-nowrap text-sm favorite-item">
+                                                    {{$favorite->data->name}}
+                                                </a>
+                                            @endforeach
+                                        </div>
+                                    </div>
+                                @endif
+                            </div>
                             <div class="mb-2">
                                 <label class="mb-0 font-weight-bold">Name</label>
                                 <input type="text"
@@ -321,6 +373,18 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
         @if($numActiveItems && $tracker && @($tracker->data->no_known_medications))
             parentSegment.find('[data-field-name="no_known_medications"]').prop('checked', false).trigger('change');
         @endif
+
+        parentSegment.find('.favorite-item')
+            .off('click.add-from-favorite')
+            .on('click.add-from-favorite', function () {
+                $('#frm-add-medication').find('input[data-name="name"]').val($(this).attr('data-name'));
+                $('#frm-add-medication').find('input[data-name="medId"]').val($(this).attr('data-medId'));
+                $('#frm-add-medication').find('input[data-name="routedMedId"]').val($(this).attr('data-routedMedId'));
+                $('#frm-add-medication').find('input[data-name="routedDosageFormMedId"]').val($(this).attr('data-routedDosageFormMedId'));
+                $('#frm-add-medication').find('input[data-name="gcnSeqno"]').val($(this).attr('data-gcnSeqno'));
+                $(this).closest('.on-click-menu').find('[menu]').hide();
+                return false;
+            });
     }
     addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}');
 }).call(window);

+ 68 - 2
resources/views/app/patient/problems-center.blade.php

@@ -3,14 +3,22 @@
 use App\Models\Point;
 use App\Models\Client;
 use App\Models\Note;
-use App\Models\Segment;
+use App\Models\Pro;
 
 /** @var Client $patient */
 /** @var Note $note */
+/** @var Pro $pro */
 
 list($problems, $counts) = Point::getPointsOfCategoryExtended($patient, 'PROBLEM', $note);
 $ccSegment = $note->getSegmentByInternalName('chief_complaint');
 $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
+$favorites = $pro->favoritesByCategoryDecoded('problem');
+function isFavoriteProblem($_problem, $_favorites) {
+    foreach($_favorites as $favorite) {
+        if($favorite->data->name === $_problem->data->name) return $favorite->uid;
+    }
+    return false;
+}
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="problems-center-{{$note->id}}">
@@ -44,6 +52,7 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
             <?php $prevRowState = -1; ?>
             <?php foreach($problems as $problem): ?>
             <?php $point = $problem; ?>
+            <?php $favoriteUid = isFavoriteProblem($problem, $favorites); ?>
             @if($prevRowState !== $problem->state)
                 @include('app.patient.wizard-partials.state-row', ['point' => $problem])
             @endif
@@ -72,6 +81,30 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
                                 </div>
                             @endif
                         </div>
+                        <div class="ml-auto mr-1">
+                            <div moe>
+                                @if(!$favoriteUid)
+                                    <form show url="/api/proFavorite/create">
+                                        <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                                        <input type="hidden" name="category" value="problem">
+                                        <input type="hidden" data-name="dxid" value="{{@$problem->data->dxid}}">
+                                        <input type="hidden" data-name="icd" value="{{@$problem->data->icd}}">
+                                        <input type="hidden" data-name="icd-type" value="{{@$problem->data->{'icd-type'} }}">
+                                        <textarea class="d-none" name="data">{!! json_encode(["name" => @($problem->data->name), "dxid" => @($problem->data->dxid), "icd" => @($problem->data->icd), "icd-type" => @($problem->data->{'icd-type'})]) !!}</textarea>
+                                        <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-secondary-light" title="Add to common">
+                                            <i class="fa fa-bookmark"></i>
+                                        </button>
+                                    </form>
+                                @else
+                                    <form show url="/api/proFavorite/remove">
+                                        <input type="hidden" name="uid" value="{{$favoriteUid}}">
+                                        <button submit class="outline-0 shadow-none border-0 bg-transparent p-0 text-info" title="Remove from common">
+                                            <i class="fa fa-bookmark"></i>
+                                        </button>
+                                    </form>
+                                @endif
+                            </div>
+                        </div>
                     </div>
                 </td>
                 <td>
@@ -218,7 +251,28 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
 
                     <div class="row">
                         <div class="col-8">
-                            <p class="mb-2"><b>Add Problem</b></p>
+                            <div class="d-flex align-items-baseline mb-2">
+                                <b>Add Problem</b>
+                                @if(count($favorites))
+                                    <div class="d-inline position-relative on-click-menu ml-4">
+                                        <span class="text-primary c-pointer">
+                                            <i class="fa fa-bookmark text-info mr-1"></i> Common Problems <i class="ml-1 fa fa-caret-down"></i>
+                                        </span>
+                                        <div menu right class="bg-white border">
+                                            @foreach($favorites as $favorite)
+                                                <a native target="_blank" href="#"
+                                                   data-name="{{@($favorite->data->name)}}"
+                                                   data-dxid="{{@($favorite->data->dxid)}}"
+                                                   data-icd="{{@($favorite->data->icd)}}"
+                                                   data-icd-type="{{@($favorite->data->{'icd-type'})}}"
+                                                   class="px-2 py-1 d-block text-nowrap text-sm favorite-item">
+                                                    {{$favorite->data->name}}
+                                                </a>
+                                            @endforeach
+                                        </div>
+                                    </div>
+                                @endif
+                            </div>
                             <div class="row mb-2">
                                 <div class="col-8 pr-0">
                                     <label class="text-sm mb-0 font-weight-bold">Name</label>
@@ -331,6 +385,18 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
             @if(trim(request()->input('dx')))
                 parentSegment.find('input[stag-suggest][data-name="name"]').focus().trigger('keydown')[0].scrollIntoView();
             @endif
+
+
+            parentSegment.find('.favorite-item')
+                .off('click.add-from-favorite')
+                .on('click.add-from-favorite', function () {
+                    $('#frm-add-problem').find('input[data-name="name"]').val($(this).attr('data-name'));
+                    $('#frm-add-problem').find('input[data-name="dxid"]').val($(this).attr('data-dxid'));
+                    $('#frm-add-problem').find('input[data-name="icd"]').val($(this).attr('data-icd')).removeAttr('readonly');
+                    $('#frm-add-problem').find('input[data-name="icd-type"]').val($(this).attr('data-icd-type'));
+                    $(this).closest('.on-click-menu').find('[menu]').hide();
+                    return false;
+                });
         }
         addMCInitializer('problems-center-{{$note->id}}', init, '#problems-center-{{$note->id}}');
     }).call(window);