Bladeren bron

FDB Playground - duplicate-therapy (wip)

Vijayakrishnan 3 jaren geleden
bovenliggende
commit
b5fad60b4f
3 gewijzigde bestanden met toevoegingen van 107 en 6 verwijderingen
  1. 81 2
      app/Http/Controllers/FDBPGController.php
  2. 25 4
      resources/views/app/fdb-pg/fdb-rx.blade.php
  3. 1 0
      routes/web.php

+ 81 - 2
app/Http/Controllers/FDBPGController.php

@@ -374,12 +374,14 @@ INTERSECT
         $output = [];
 
         for ($i=$leftIndex; $i<count($rx) - 1; $i++) {
-            for ($j=$leftIndex + 1; $j<count($rx); $j++) {
+            for ($j=$i + 1; $j<count($rx); $j++) {
                 $output[] = $this->drugDrugInteractionSinglePair($rx[$i], $rx[$j]);
             }
         }
 
-        return implode("<br>", $output);
+        return "<ol class='pl-0 ml-3'>" . implode("", array_map(function($_x) {
+                return "<li class='mb-2'>" . $_x . "</li>";
+            }, $output)) . "</ol>";
     }
 
     private function drugDrugInteractionSinglePair($_rx1, $_rx2) {
@@ -536,4 +538,81 @@ WHERE r1.side_a_gcn_seqno in ($gcnSeqnos) AND r1.side_b_gcn_seqno in ($gcnSeqnos
         );
         return view('app.fdb-pg.fdb-coadministration', compact('coadministration'));
     }
+
+    public function duplicateTherapy(Request $request) {
+
+        if($request->input('test')) {
+            // override
+            $rx = json_decode(json_encode([
+                [
+                    "gcn_seqno" => "4376",
+                    "med_name_id" => "1076",
+                    "medid" => "172480",
+                    "routed_dosage_form_med_id" => "5870",
+                    "routed_med_id" => "1082",
+                    "rx" => "aspirin 325",
+                ],
+                [
+                    "gcn_seqno" => "4377",
+                    "med_name_id" => "1076",
+                    "medid" => "216092",
+                    "routed_dosage_form_med_id" => "5870",
+                    "routed_med_id" => "1082",
+                    "rx" => "aspirin 500",
+                ],
+            ]));
+        }
+        else {
+            $input = json_decode($request->input('data'));
+            $rx = $input->rx;
+        }
+
+        $dptClasses = [];
+        foreach ($rx as $rxItem) {
+            $rxItem->dpt = $this->getDptClassFromGcnSeqNo($rxItem->gcn_seqno);
+        }
+
+        // dd($rx);
+
+        $leftIndex = 0;
+        $matches = [];
+        for ($i=$leftIndex; $i<count($rx) - 1; $i++) {
+            for ($j=$i + 1; $j<count($rx); $j++) {
+                $compareResult = $this->compareDPTs($rx[$i]->dpt, $rx[$j]->dpt);
+                foreach ($compareResult as $c) {
+                    $matches[] = "<b>{$rx[$i]->rx}</b> and <b>{$rx[$j]->rx}</b> both participate in the duplicate therapy class <b>{$c->dpt_class_desc}</b> (duplicates allowed: {$c->dpt_allowance})";
+                }
+            }
+        }
+
+        return "<ol class='pl-0 ml-3'>" . implode("", array_map(function($_x) {
+                return "<li class='mb-2'>" . $_x . "</li>";
+            }, $matches)) . "</ol>";
+    }
+
+    private function getDptClassFromGcnSeqNo($_gcnSeqNo) {
+        return DB::connection('pgsql_fdb')->select("
+SELECT distinct r1.dpt_class_id, r2.dpt_allowance, r2.dpt_class_desc
+FROM RDPTGC0_GCNSEQNO_LINK r1 
+JOIN RDPTCL0_CLASS_ID r2 on r1.dpt_class_id = r2.dpt_class_id
+WHERE r1.gcn_seqno = :gcnSeqNo
+            ",
+            ['gcnSeqNo' => $_gcnSeqNo]
+        );
+    }
+
+    private function compareDPTs($_dptArray1, $_dptArray2) {
+        $output = [];
+        for ($i=0; $i<count($_dptArray1); $i++) {
+            for ($j=0; $j<count($_dptArray2); $j++) {
+                if($_dptArray1[$i]->dpt_class_id == $_dptArray2[$j]->dpt_class_id) {
+                    $output[] = json_decode(json_encode([
+                        "dpt_allowance" => $_dptArray1[$i]->dpt_allowance,
+                        "dpt_class_desc" => $_dptArray1[$i]->dpt_class_desc
+                    ]));
+                }
+            }
+        }
+        return $output;
+    }
 }

+ 25 - 4
resources/views/app/fdb-pg/fdb-rx.blade.php

@@ -125,14 +125,14 @@
 
                     </td>
                     <td class="text-center">
-                        <a href="#" v-on:click.prevent="rx.splice(index, 1); showDrugAllergyNotes();"><i class="fa fa-trash-alt text-danger"></i></a>
+                        <a href="#" v-on:click.prevent="rx.splice(index, 1); showDrugAllergyNotes(); showDrugCoadministrationNotes(); showDuplicateTherapyNotes()"><i class="fa fa-trash-alt text-danger"></i></a>
                     </td>
                 </tr>
                 </tbody>
             </table>
             </div>
             <div class="row">
-                <div class="col-4">
+                <div class="col-3">
                     <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>
@@ -140,7 +140,7 @@
                         <div class="drug-allergies"></div>
                     </div>
                 </div>
-                <div class="col-4 pl-0">
+                <div class="col-3 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>
@@ -148,7 +148,15 @@
                         <div class="drug-drug-interaction"></div>
                     </div>
                 </div>
-                <div class="col-4 pl-0">
+                <div class="col-3 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">Duplicate Therapy Notes</span>
+                        </div>
+                        <div class="duplicate-therapy"></div>
+                    </div>
+                </div>
+                <div class="col-3 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">Coadministration Notes</span>
@@ -369,6 +377,18 @@
                                 });
                             }
                         },
+                        showDuplicateTherapyNotes: function() {
+                            $('.duplicate-therapy').html('');
+                            if(this.rx && this.rx.length > 1) {
+                                $.get('/fdb-duplicate-therapy', {
+                                    data: JSON.stringify({
+                                        rx: this.rx
+                                    })
+                                }, _data => {
+                                    $('.duplicate-therapy').html(_data);
+                                });
+                            }
+                        },
                         initFDBRxSuggest: function() {
                             $('[fdb-med-suggest-search]:not([fdb-suggest-initialized])').each(function() {
                                 let elem = $(this);
@@ -626,6 +646,7 @@
 
                             vueApp.showDrugAllergyNotes();
                             vueApp.showDrugDrugInteractionNotes();
+                            vueApp.showDuplicateTherapyNotes();
                             vueApp.showDrugCoadministrationNotes();
                         });
 

+ 1 - 0
routes/web.php

@@ -337,6 +337,7 @@ Route::middleware('pro.auth')->group(function () {
     Route::any('/fdb-drug-allergies', 'FDBPGController@drugAllergies');
     Route::any('/fdb-drug-drug-interaction', 'FDBPGController@drugDrugInteraction');
     Route::any('/fdb-drug-coadministration', 'FDBPGController@drugCoadministration');
+    Route::any('/fdb-duplicate-therapy', 'FDBPGController@duplicateTherapy');
 });
 
 Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');