Răsfoiți Sursa

FDB Playground - drug allergies (wip)

Vijayakrishnan 3 ani în urmă
părinte
comite
089384aa4b

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

@@ -154,4 +154,106 @@ ORDER BY r1.dam_concept_id_desc
         );
         return view('app.fdb-pg.fdb-allergy-suggest', compact('matches'));
     }
+
+    public function drugAllergies(Request $request) {
+
+        // override
+        if($request->input('test')) {
+            $x = new \stdClass();
+            $x->allergen = 'Pollen';
+            $x->dam_concept_id_typ = 6;
+            $allergies = [$x];
+            $y = new \stdClass();
+            $y->rx = 'Brufen';
+            $rx = [$y];
+        }
+        else {
+            $input = json_decode($request->input('data'));
+            $allergies = $input->allergies;
+            $rx = $input->rx;
+        }
+
+        $output = [];
+
+        /*
+        for each allergy
+            if dam_concept_id_typ = 1 // allergen-group-id
+                // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+a+DAM_ALRGN_GRP+Allergen+-+Illustration+of+Scenario+C
+                ...
+            elseif dam_concept_id_typ = 2 // medication-name-id
+                // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+a+MED_NAME_ID+Allergen+-+Illustration+of+Scenario+B
+                ...
+            elseif dam_concept_id_typ = 6 // base-ingredient-id
+                // https://docs.fdbhealth.com/display/MKDOCUS/Screening+an+NDC+for+an+Ingredient+Allergen+-+Illustration+of+Scenario+A
+                ...
+            endif
+        endfor
+        */
+
+        foreach ($allergies as $allergy) {
+            if($allergy->dam_concept_id_typ == 6) {
+                foreach ($rx as $rxItem) {
+                    if($this->drugAllergyIngredientAllergenVsSingleRx($allergy, $rxItem)) {
+                        $output[] = "<b>{$rxItem->rx}</b> can cause allergic reactions since the patient is allergic to <b>{$allergy->allergen}</b>.";
+                    }
+                }
+            }
+        }
+
+        return implode("\n", $output);
+
+    }
+
+    private function getAllergenIngredients($_allergen) {
+
+    }
+
+    private function getRxIngredients($_rx) {
+
+    }
+
+    private function drugAllergyIngredientAllergenVsSingleRx($_allergen, $_rx) {
+
+        $matches = DB::connection('pgsql_fdb')->select("
+(
+    -- ingredients from medication
+    SELECT R1.related_hic_seqn as hic_seqn, R2.hic_desc
+    FROM RHICHCR0_HIC_HIC_LINK R1
+             JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
+    WHERE R1.hic_seqn IN (
+        SELECT S2.dam_alrgn_hic_seqn
+        FROM RMEDMHL0_MED_HICLSEQNO_LINK S1
+                 JOIN RDAMHHA0_HIC_HICL_ALG_LINK S2 ON S1.hicl_seqno = S2.hicl_seqno
+        WHERE S1.med_concept_id = :medid
+          AND S1.med_concept_id_typ = 3
+    )
+)
+INTERSECT
+(
+    -- all ingredients directly and related from allergens
+    (
+        SELECT R1.related_hic_seqn as hic_seqn, R2.hic_desc
+        FROM RHICHCR0_HIC_HIC_LINK R1
+                 JOIN RHICD5_HIC_DESC R2 ON R1.related_hic_seqn = R2.hic_seqn
+        WHERE R1.hic_seqn = :allergenHicSeqNo
+    )
+    UNION
+    -- all ingredients via related dam allergen groups
+    (
+        SELECT r3.hic_seqn, r4.hic_desc
+        FROM RDAMGHC0_HIC_ALRGN_GRP_LINK R1
+                 JOIN rdamagd1_alrgn_grp_desc R2 on R1.dam_alrgn_grp = R2.dam_alrgn_grp
+                 JOIN RDAMGHC0_HIC_ALRGN_GRP_LINK R3 on R1.dam_alrgn_grp = R3.dam_alrgn_grp
+                 JOIN RHICD5_HIC_DESC R4 on r3.hic_seqn = r4.hic_seqn
+        WHERE R1.hic_seqn = :allergenHicSeqNo
+          AND R2.dam_alrgn_grp_status_cd = 0
+        ORDER BY r3.hic_seqn
+    )
+)
+",
+            ['medid' => $_rx->medid, 'allergenHicSeqNo' => $_allergen->dam_concept_id]
+        );
+
+        return !!count($matches);
+    }
 }

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

@@ -5,7 +5,7 @@
 @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}}
+        {{$match->dam_concept_id_desc}} <span class="text-sm">({{$match->dam_concept_id_typ == 6 ? 'ingredient' : ($match->dam_concept_id_typ == 1 ? 'allergen group' : 'medication')}})</span>
     </a>
     <?php $activeSet = true; ?>
 @endforeach

+ 56 - 9
resources/views/app/fdb-pg/fdb-rx.blade.php

@@ -30,7 +30,7 @@
                         <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">
+                                       fdb-allergy-suggest-search :fdb-suggest-group="index" :data-index="index">
                             </td>
                             <td class="text-center">
                                 <a href="#" v-on:click.prevent="allergies.splice(index, 1)"><i class="fa fa-trash-alt text-danger"></i></a>
@@ -57,7 +57,7 @@
                         <tr v-for="(item, index) in dx">
                             <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">
+                                       fdb-dx-suggest-search :fdb-suggest-group="index" :data-index="index">
                             </td>
                             <td class="text-center">
                                 <a href="#" v-on:click.prevent="dx.splice(index, 1)"><i class="fa fa-trash-alt text-danger"></i></a>
@@ -68,7 +68,7 @@
                     </div>
                 </div>
             </div>
-            <div class="bg-white p-3 border">
+            <div class="bg-white p-3 mb-3 border">
                 <div class="d-flex align-items-baseline mb-2">
                     <span class="font-size-14 font-weight-bold">Medications</span>
                     <a href="#" v-on:click.prevent="addRx()" class="ml-3">+ Add</a>
@@ -91,23 +91,23 @@
                 <tr v-for="(item, index) in rx">
                     <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">
+                               fdb-med-suggest-search :fdb-suggest-group="index" :data-index="index">
                     </td>
                     <td class="p-0 position-relative">
                         <select class="rounded-0 border-0 form-control form-control-sm min-width-unset"
-                                fdb-med-suggest-route :fdb-suggest-group="index"
+                                fdb-med-suggest-route :fdb-suggest-group="index" v-model="item.routed_med_id"
                                 disabled>
                         </select>
                     </td>
                     <td class="p-0 position-relative">
                         <select class="rounded-0 border-0 form-control form-control-sm min-width-unset"
-                                fdb-med-suggest-dosage :fdb-suggest-group="index"
+                                fdb-med-suggest-dosage :fdb-suggest-group="index" v-model="item.routed_dosage_form_med_id"
                                 disabled>
                         </select>
                     </td>
                     <td class="p-0 position-relative">
                         <select class="rounded-0 border-0 form-control form-control-sm min-width-unset"
-                                fdb-med-suggest-strength :fdb-suggest-group="index"
+                                fdb-med-suggest-strength :fdb-suggest-group="index" v-model="item.gcn_seqno"
                                 disabled>
                         </select>
                     </td>
@@ -131,6 +131,23 @@
                 </tbody>
             </table>
             </div>
+            <div class="row">
+                <div class="col-6">
+                    <div class="bg-white p-3 border">
+                        <div class="d-flex align-items-baseline mb-2">
+                            <span class="font-size-14 font-weight-bold">Drug Allergy Notes</span>
+                        </div>
+                        <div class="drug-allergies"></div>
+                    </div>
+                </div>
+                <div class="col-6 pl-0">
+                    <div class="bg-white p-3 border">
+                        <div class="d-flex align-items-baseline mb-2">
+                            <span class="font-size-14 font-weight-bold">Drug Drug Interaction Notes</span>
+                        </div>
+                    </div>
+                </div>
+            </div>
         </div>
     </div>
 
@@ -267,7 +284,7 @@
 
             addMCInitializer('fdb-pg', function() {
 
-                new Vue({
+                window.fdbPGApp = new Vue({
                     el: '#fdb-pg',
                     delimiters: ['@{{', '}}'],
                     data: {
@@ -375,6 +392,8 @@
                     },
                     mounted: function() {
 
+                        let vueApp = this;
+
                         // 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 () {
@@ -392,6 +411,10 @@
                             input.trigger('input');
                             input.trigger('change');
 
+                            // vue value
+                            vueApp.rx[input.attr('data-index')].rx = label;
+                            vueApp.rx[input.attr('data-index')].med_name_id = medNameID;
+
                             $(document).trigger('fdb-med-changed', [group]);
 
                             return false;
@@ -414,6 +437,10 @@
                             input.trigger('input');
                             input.trigger('change');
 
+                            // vue value
+                            vueApp.dx[input.attr('data-index')].problem = label;
+                            vueApp.dx[input.attr('data-index')].dxid = dxID;
+
                             $(document).trigger('fdb-dx-changed', [group]);
 
                             return false;
@@ -438,6 +465,11 @@
                             input.trigger('input');
                             input.trigger('change');
 
+                            // vue value
+                            vueApp.allergies[input.attr('data-index')].allergen = label;
+                            vueApp.allergies[input.attr('data-index')].dam_concept_id = damConceptID;
+                            vueApp.allergies[input.attr('data-index')].dam_concept_id_typ = damConceptIDTyp;
+
                             $(document).trigger('fdb-allergy-changed', [group]);
 
                             return false;
@@ -497,7 +529,7 @@
                                     .empty()
                                     .append('<option value="">-- select --</option>');
                                 for (let i = 0; i < _data.length; i++) {
-                                    strengthSelect.append('<option value="' + _data[i].gcn_seqno + '">' + _data[i].med_medid_desc + '</option>')
+                                    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) {
@@ -509,12 +541,27 @@
                         // on strength (medid) selection
                         $(document).off('change', '[fdb-med-suggest-strength]');
                         $(document).on('change', '[fdb-med-suggest-strength]', function () {
+
+                            let group = $(this).attr('fdb-suggest-group');
+                            vueApp.rx[group].medid = $(this).find('option:selected').attr('data-medid');
+
                             fillSideEffects($(this).attr('fdb-suggest-group'), $(this).val());
                             fillGeriatricPrecautions($(this).attr('fdb-suggest-group'), $(this).val());
                             fillIndications($(this).attr('fdb-suggest-group'), $(this).val());
 
                             let routedMedID = $('[fdb-med-suggest-route][fdb-suggest-group='+$(this).attr('fdb-suggest-group')+']').val();
                             fillContraindications($(this).attr('fdb-suggest-group'), routedMedID);
+
+                            if(vueApp.allergies && vueApp.allergies.length) {
+                                $.get('/fdb-drug-allergies', {
+                                    data: JSON.stringify({
+                                        allergies: vueApp.allergies,
+                                        rx: vueApp.rx
+                                    })
+                                }, _data => {
+                                    $('.drug-allergies').html(_data);
+                                });
+                            }
                         });
 
                         Vue.nextTick(() => {

+ 1 - 0
routes/web.php

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