Explorar o código

Default pharmacy

Samson Mutunga hai 1 ano
pai
achega
7c0a4b2347

+ 17 - 0
app/Http/Controllers/Controller.php

@@ -13,6 +13,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Support\Facades\Cookie;
+use Illuminate\Support\Facades\Http;
 
 class Controller extends BaseController
 {
@@ -137,4 +138,20 @@ class Controller extends BaseController
             $query->where($columnName, $request->input($valueName));
         }
     }
+
+    // TODO move to utility
+    public function callJavaApi($endPoint, $data)
+    {
+        $sessionKey = Cookie::get('sessionKey');
+        $url =  config('stag.backendUrl') . $endPoint;
+        
+        $response = Http::asForm()
+            ->withHeaders([
+                'sessionKey' => $sessionKey
+            ])
+            ->post($url, $data)
+            ->json();
+        return $response;
+    }
+
 }

+ 36 - 2
app/Http/Controllers/PatientController.php

@@ -543,13 +543,47 @@ class PatientController extends Controller
         }
         return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
     }
-
+    protected function getDefaultFacility(){
+        $defaultFacility = Facility::where('name', 'Ultra Care Pharmacy')->where('address_city', 'Baltimore')->first();
+        return $defaultFacility;
+    }
     public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
+        $this->updateDefaultPatientPharmacy($patient);
         if(!!$currentErx) {
             $currentErx = Erx::where('uid', $currentErx)->first();
         }
         $note = $patient->coreNote;
-        return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note'));
+        $defaultFacility = $this->getDefaultFacility();
+        $patient->refresh();
+        return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note', 'defaultFacility'));
+    }
+
+    protected function updateDefaultPatientPharmacy(Client $patient){
+        $prescriptions = $patient->prescriptions;
+        if(!count($prescriptions)) return;
+        $defaultFacility = $this->getDefaultFacility();
+        if(!$defaultFacility) return;
+
+        foreach($prescriptions as $prescription){
+            if($prescription->logistics_detail_json) continue;
+            $this->setPrescriptionDefaultPharmacy($prescription, $defaultFacility);
+        }
+    }
+
+    private function setPrescriptionDefaultPharmacy(Erx $prescription, Facility $facility){
+        $data = [
+            'uid' => $prescription->uid,
+            'logisticsDetailJson' => json_encode([
+                'facilityName' => $facility->name,
+                'facilityCity' => $facility->address_city,
+                'facilityState' => $facility->address_state,
+                'facilityAddressMemo' => '',
+                'facilityPhone' => $facility->phone,
+                'facilityFax' => $facility->fax,
+                'facilityZip' => $facility->address_zip,
+            ])
+        ];
+        $response = $this->callJavaApi('/erx/updateLogisticsDetail', $data);
     }
 
     public function prescriptionsPopup(Request $request, Client $patient, String $type = '', String $currentErx = '') {

+ 14 - 37
resources/views/app/patient/prescriptions/list.blade.php

@@ -510,13 +510,21 @@ GROUP BY erx_category");
 
         ?>
 
+        var DEFAULTLOGISTICSDETAILS = {
+                facilityName: '{{ @$defaultFacility->name ?? '' }}',
+                facilityCity: '{{ @$defaultFacility->address_city ?? '' }}',
+                facilityState: '{{ @$defaultFacility->address_state ?? '' }}',
+                facilityAddressMemo: '',
+                facilityPhone: '{{ @$defaultFacility->phone ?? '' }}',
+                facilityFax: '{{ @$defaultFacility->fax ?? '' }}',
+                facilityZip: '{{ @$defaultFacility->address_zip ?? '' }}',
+            };
         function init() {
 
             window.eRxApp = new Vue({
                 el: '#prescriptions-{{$patient->id}}',
                 delimiters: ['@{{', '}}'],
                 data: {
-
                     includeCancelled: '',
 
                     prescriptions: <?= json_encode($prescriptions) ?>,
@@ -695,28 +703,12 @@ GROUP BY erx_category");
                     // for editing logistics - common
                     currentPrescriptionLogistics: {
                         uid: '',
-                        logisticsDetailJson: {
-                            facilityName: '',
-                            facilityCity: '',
-                            facilityState: '',
-                            facilityAddressMemo: '',
-                            facilityPhone: '',
-                            facilityFax: '',
-                            facilityZip: '',
-                        }
+                        logisticsDetailJson: DEFAULTLOGISTICSDETAILS
                     },
 
                     newPrescriptionLogistics: {
                         uid: '',
-                        logisticsDetailJson: {
-                            facilityName: '',
-                            facilityCity: '',
-                            facilityState: '',
-                            facilityAddressMemo: '',
-                            facilityPhone: '',
-                            facilityFax: '',
-                            facilityZip: '',
-                        }
+                        logisticsDetailJson: DEFAULTLOGISTICSDETAILS
                     },
 
                     // for editing hcp, sign, pro status & client status - common
@@ -847,18 +839,11 @@ GROUP BY erx_category");
                             }
                             this.newPrescriptionLogistics = {
                                 uid: '',
-                                logisticsDetailJson: {
-                                    facilityName: '',
-                                    facilityCity: '',
-                                    facilityState: '',
-                                    facilityAddressMemo: '',
-                                    facilityPhone: '',
-                                    facilityFax: '',
-                                    facilityZip: '',
-                                }
+                                logisticsDetailJson: DEFAULTLOGISTICSDETAILS
                             };
                             this.currentPrescriptionType = _type;
                             Vue.nextTick(() => {
+                                console.log({n: this.newPrescriptionLogistics, DEFAULTLOGISTICSDETAILS});
                                 showStagPopup('new-prescription-popup-' + _type, true);
                                 $('[stag-popup-key="new-prescription-popup-' + _type + '"] [stag-suggest-initialized]').removeAttr('stag-suggest-initialized');
                                 initStagSuggest();
@@ -1163,15 +1148,7 @@ GROUP BY erx_category");
                         this.currentPrescriptionAction = 'EDIT_LOGISTICS';
                         this.currentPrescriptionLogistics = {
                             uid: _prescription.uid,
-                            logisticsDetailJson: _prescription.logistics_detail_json ? JSON.parse(JSON.stringify(_prescription.logistics_detail_json)) : {
-                                facilityName: '',
-                                facilityCity: '',
-                                facilityState: '',
-                                facilityAddressMemo: '',
-                                facilityPhone: '',
-                                facilityFax: '',
-                                facilityZip: '',
-                            }
+                            logisticsDetailJson: _prescription.logistics_detail_json ? JSON.parse(JSON.stringify(_prescription.logistics_detail_json)) : DEFAULTLOGISTICSDETAILS
                         }
                         Vue.nextTick(() => {
                             showStagPopup('logistics-popup', true);