Jelajahi Sumber

FDB Playground - allergy suggest (wip)

Vijayakrishnan 3 tahun lalu
induk
melakukan
a8bf6aaaea

+ 15 - 0
app/Http/Controllers/FDBPGController.php

@@ -139,4 +139,19 @@ ORDER BY r1.dxid_desc56
         );
         return view('app.fdb-pg.fdb-dx-suggest', compact('matches'));
     }
+
+    public function allergySuggest(Request $request)
+    {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+        $matches = DB::connection('pgsql_fdb')->select("
+SELECT r1.dam_concept_id, r1.dam_concept_id_typ, r1.dam_concept_id_desc
+FROM rdamca0_concept r1
+WHERE (r1.dam_concept_id_desc ILIKE :term)
+ORDER BY r1.dam_concept_id_desc
+",
+            ['term' => '%' . $term . '%']
+        );
+        return view('app.fdb-pg.fdb-allergy-suggest', compact('matches'));
+    }
 }

+ 12 - 0
resources/views/app/fdb-pg/fdb-allergy-suggest.blade.php

@@ -0,0 +1,12 @@
+@if(!count($matches))
+    <span class="d-block no-suggest-items">No matches!</span>
+@endif
+<?php $activeSet = false; ?>
+@foreach($matches as $match)
+    <a native class="d-block suggest-item fdb-suggest text-nowrap {{ $activeSet ? '' : 'active'  }}" href="#"
+       data-dam-concept-id="{{$match->dam_concept_id}}" data-dam-concept-id-typ="{{$match->dam_concept_id_typ}}">
+        {{$match->dam_concept_id_desc}}
+    </a>
+    <?php $activeSet = true; ?>
+@endforeach
+

+ 88 - 7
resources/views/app/fdb-pg/fdb-rx.blade.php

@@ -12,6 +12,26 @@
     <div class="p-0 mcp-theme-1" id="fdb-pg">
         <div class="px-3 py-2 bg-light border-bottom d-flex align-items-center font-weight-bold font-size-14">FDB Playground</div>
         <div class="p-3">
+            <div class="d-flex align-items-baseline mb-2">
+                <span class="font-size-14 font-weight-bold">Allergies</span>
+                <a href="#" v-on:click.prevent="addAllergy()" class="ml-3">+ Add</a>
+            </div>
+            <table class="table table-sm table-striped table-bordered m-0" style="table-layout: fixed">
+                <thead>
+                <tr>
+                    <th class="border-bottom-0 text-secondary">Allergy</th>
+                </tr>
+                </thead>
+                <tbody>
+                <tr v-for="(item, index) in allergies">
+                    <td class="p-0 position-relative">
+                        <input type="text" class="rounded-0 border-0 form-control form-control-sm min-width-unset"
+                               fdb-allergy-suggest-search :fdb-suggest-group="index">
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+            <hr class="m-neg-4 my-4">
             <div class="d-flex align-items-baseline mb-2">
                 <span class="font-size-14 font-weight-bold">Current Problems</span>
                 <a href="#" v-on:click.prevent="addDx()" class="ml-3">+ Add</a>
@@ -24,8 +44,8 @@
                 </thead>
                 <tbody>
                 <tr v-for="(item, index) in dx">
-                    <td class="p-0 position-relative" style="z-index: 2">
-                        <input type="text" class="rounded-0 border-0 form-control form-control-sm min-width-unset" style="z-index: 1"
+                    <td class="p-0 position-relative">
+                        <input type="text" class="rounded-0 border-0 form-control form-control-sm min-width-unset"
                                fdb-dx-suggest-search :fdb-suggest-group="index">
                     </td>
                 </tr>
@@ -51,8 +71,8 @@
                 </thead>
                 <tbody>
                 <tr v-for="(item, index) in rx">
-                    <td class="p-0 position-relative" style="z-index: 1">
-                        <input type="text" class="rounded-0 border-0 form-control form-control-sm min-width-unset" style="z-index: 1"
+                    <td class="p-0 position-relative">
+                        <input type="text" class="rounded-0 border-0 form-control form-control-sm min-width-unset"
                                fdb-med-suggest-search :fdb-suggest-group="index">
                     </td>
                     <td class="p-0 position-relative">
@@ -120,6 +140,9 @@
                     else if($(elem).is('[fdb-dx-suggest-search]')) {
                         ep = '/fdb-dx-suggest';
                     }
+                    else if($(elem).is('[fdb-allergy-suggest-search]')) {
+                        ep = '/fdb-allergy-suggest';
+                    }
                     $.get(ep + '?term=' + $.trim(term), function (_data) {
                         suggestionsOuter.html(_data).removeClass('d-none');
                     });
@@ -226,6 +249,9 @@
                     el: '#fdb-pg',
                     delimiters: ['@{{', '}}'],
                     data: {
+                        allergies: [{
+
+                        }],
                         dx: [{
 
                         }],
@@ -248,6 +274,13 @@
                                 $('[fdb-dx-suggest-search]').last().focus();
                             });
                         },
+                        addAllergy: function() {
+                            this.allergies.push({});
+                            Vue.nextTick(() => {
+                                this.initFDBAllergySuggest();
+                                $('[fdb-allergy-suggest-search]').last().focus();
+                            });
+                        },
                         initFDBRxSuggest: function() {
                             $('[fdb-med-suggest-search]:not([fdb-suggest-initialized])').each(function() {
                                 let elem = $(this);
@@ -291,13 +324,36 @@
                                         return handleKeypress($(this), e);
                                     });
 
+                                $(this).attr('fdb-suggest-initialized', 1);
+                            });
+                        },
+                        initFDBAllergySuggest: function() {
+                            $('[fdb-allergy-suggest-search]:not([fdb-suggest-initialized])').each(function() {
+                                let elem = $(this);
+                                elem.next('.fdb-suggestions-container').remove();
+                                $('<div class="fdb-suggestions-container position-relative" fdb-suggest-group="' + elem.attr('fdb-suggest-group') + '">' +
+                                    '<div class="suggestions-outer fdb-suggestions position-absolute d-none"></div>' +
+                                    '</div>').insertAfter(elem);
+
+                                elem
+                                    .off('keydown.fdb-suggest')
+                                    .on('keydown.fdb-suggest', function (e) {
+                                        suggestionsOuter = $(this).next('.fdb-suggestions-container').find('>.suggestions-outer');
+                                        return handleKeydown($(this), e);
+                                    })
+                                    .off('keypress.fdb-suggest')
+                                    .on('keypress.fdb-suggest', function (e) {
+                                        suggestionsOuter = $(this).next('.fdb-suggestions-container').find('>.suggestions-outer');
+                                        return handleKeypress($(this), e);
+                                    });
+
                                 $(this).attr('fdb-suggest-initialized', 1);
                             });
                         }
                     },
                     mounted: function() {
 
-                        // on auto-suggest selection
+                        // on auto-suggest med selection
                         $(document).off('click', '.suggest-item.fdb-suggest[data-med-name-id]');
                         $(document).on('click', '.suggest-item.fdb-suggest[data-med-name-id]', function () {
 
@@ -319,7 +375,7 @@
                             return false;
                         });
 
-                        // on auto-suggest selection
+                        // on auto-suggest dx selection
                         $(document).off('click', '.suggest-item.fdb-suggest[data-dx-id]');
                         $(document).on('click', '.suggest-item.fdb-suggest[data-dx-id]', function () {
 
@@ -341,6 +397,30 @@
                             return false;
                         });
 
+                        // on auto-suggest allergy selection
+                        $(document).off('click', '.suggest-item.fdb-suggest[data-dam-concept-id]');
+                        $(document).on('click', '.suggest-item.fdb-suggest[data-dam-concept-id]', function () {
+
+                            $('.suggestions-outer.fdb-suggestions').addClass('d-none');
+
+                            let damConceptID = $(this).attr('data-dam-concept-id'),
+                                damConceptIDTyp = $(this).attr('data-dam-concept-id-typ'),
+                                label = $.trim($(this).text()),
+                                group = $(this).closest('.fdb-suggestions-container').attr('fdb-suggest-group');
+
+                            // set value
+                            let input = $(this).closest('.position-relative').prev('[fdb-allergy-suggest-search]');
+                            input.val(label);
+                            input.attr('data-dam-concept-id', damConceptID);
+                            input.attr('data-dam-concept-id-type', damConceptIDTyp);
+                            input.trigger('input');
+                            input.trigger('change');
+
+                            $(document).trigger('fdb-allergy-changed', [group]);
+
+                            return false;
+                        });
+
                         // med changed, update routes
                         $(document).off('fdb-med-changed');
                         $(document).on('fdb-med-changed', function(e, group) {
@@ -416,9 +496,10 @@
                         });
 
                         Vue.nextTick(() => {
+                            this.initFDBAllergySuggest();
                             this.initFDBDxSuggest();
                             this.initFDBRxSuggest();
-                            $('[fdb-dx-suggest-search]').first().focus();
+                            $('[fdb-allergy-suggest-search]').first().focus();
                         });
 
                     }

+ 1 - 0
routes/web.php

@@ -333,6 +333,7 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/fdb-indications', 'FDBPGController@indications');
     Route::get('/fdb-contraindications', 'FDBPGController@contraindications');
     Route::get('/fdb-dx-suggest', 'FDBPGController@dxSuggest');
+    Route::get('/fdb-allergy-suggest', 'FDBPGController@allergySuggest');
 });
 
 Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');