Bladeren bron

Upload card front/back images

Samson Mutunga 2 weken geleden
bovenliggende
commit
9ceb43ea72

+ 12 - 0
app/Http/Controllers/PatientController.php

@@ -771,6 +771,18 @@ class PatientController extends Controller
         return view('app.patient.insurance-card', compact('patient', 'card'));
     }
 
+    public function insuranceCardPutInfo(Request $request, Client $patient, InsuranceCard $card){
+        //Use java, but currently java is not updating card info columns
+        $data = $request->except(['uid']);
+        foreach($data as $key=>$value){
+            if($key === 'frontImageUrl') $card->front_image_url = $value;
+            if($key === 'backImageUrl') $card->back_image_url = $value;
+        }
+
+        $card->save();
+        return $this->pass($card->uid);
+    }
+
     public function insuranceCoverageHistory(Request $request, Client $patient){
         $insuranceCoverageHistory = ClientPrimaryCoverage::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get();
         return view('app.patient.insurance-coverage-history', compact('patient', 'insuranceCoverageHistory'));

+ 2 - 0
app/Models/InsuranceCard.php

@@ -9,6 +9,8 @@ class InsuranceCard extends Model
 {    
     protected $table = 'insurance_card';
 
+    public $timestamps = false;
+    
     public function client(){
         return $this->hasOne(Client::class, 'id', 'client_id');
     }

+ 2 - 0
resources/views/app/patient/insurance-card.blade.php

@@ -16,6 +16,8 @@
                 @include('app.patient.partials.insurance-cards.forms.put-card-info')
                 <span class="text-muted mx-1">|</span>
                 @include('app.patient.partials.insurance-cards.forms.put-benefit-meter')
+                <span class="text-muted mx-1">|</span>
+                @include('app.patient.partials.insurance-cards.forms.upload-card-images')
             </div>
         </div>
         <div class="row">

+ 92 - 0
resources/views/app/patient/partials/insurance-cards/forms/upload-card-images.blade.php

@@ -0,0 +1,92 @@
+<div moe>
+    <a class="text-nowrap" href="" show start>Upload Card Images</a>
+    <form url="/api/eligibilityCheck/create" style="min-width: 300px;" right>
+        <input type="hidden" name="insuranceCardUid" value="{{ $card->uid }}">
+        <div class="bg-light">
+            <div class="col-md-12">
+                <div class="row border rounded pt-3 mb-3 bg-white">
+
+                    <div class="col-md-6">
+                        <div class="form-group">
+                            <label>Front Image</label>
+                            <input type="file" file-picker name="frontImageUrl" class="form-control" />
+                            <div class="d-nonex">
+                                <img src="{{ $card->front_image_url }}" />
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-md-6">
+                        <div class="form-group">
+                            <label>Back Image</label>
+                            <input type="file" file-picker name="backImageUrl" class="form-control" />
+                            <div class="d-nonex">
+                                <img src="{{ $card->back_image_url }}" />
+                            </div>
+                        </div>
+                    </div>
+                </div>
+
+            </div>
+        </div>
+        <div class="mb-0">
+            <button class="btn btn-default border btn-sm" cancel>Close</button>
+        </div>
+    </form>
+</div>
+
+<script>
+    (function($) {
+        const PUT_INFO_URL = "{{ route('patients.view.insurance-card-put-info', ['patient' => $patient, 'card' => $card]) }}";
+        const uploadCardImages = {
+            uploadBase64File: function(name, base64File) {
+                var self = this;
+                const params = {
+                    webDisplayProfilePhotoBase64: base64File,
+                    purpose: 'INSURANCE_CARD_IMAGE'
+                };
+                $.post('/api/systemFile/uploadBase64', params, function(response) {
+                    if(response.success){
+                        const fileUrl = '/api/systemFile/' + response.data;
+                        const data = {
+                            system_file_uid: response.data,
+                            url: base64File
+                        };
+                        self.updateCardRecord({[name]: JSON.stringify(data)});
+                    }else{
+                        toastr.error(response.message);
+                    }
+                }, 'json');
+            },
+            updateCardRecord: function(params){
+                var self = this;
+                params.uid = "{{ $card->uid }}";
+                $.post(PUT_INFO_URL, params, function(response){
+                    if(response.success){
+                        toastr.success('Updated');
+                    }else{
+                        toastr.error(response.message);
+                    }
+                }, 'json');
+            },
+            initOnFileChange: function() {
+                var self = this;
+                $('[file-picker]').on('change', function(e) {
+                    const name = e.currentTarget.name;
+                    const file = e.target.files[0];
+                    const reader = new FileReader();
+                    reader.onload = function() {
+                        const base64Image = reader.result;
+                        self.uploadBase64File(name, base64Image);
+                    };
+                    if (file) {
+                        reader.readAsDataURL(file);
+                    }
+                });
+            },
+            init: function() {
+                this.initOnFileChange();
+            }
+        };
+        uploadCardImages.init();
+    })(jQuery);
+</script>

+ 1 - 0
routes/web.php

@@ -635,6 +635,7 @@ Route::middleware('pro.auth')->group(function () {
             Route::get('education', 'PatientController@education')->name('education');
             Route::get('insurance-cards', 'PatientController@insuranceCards')->name('insurance-cards');
             Route::get('insurance-cards/view/{card}', 'PatientController@insuranceCard')->name('insurance-card');
+            Route::post('insurance-cards/view/{card}/put-info', 'PatientController@insuranceCardPutInfo')->name('insurance-card-put-info');
             Route::get('insurance-coverage-history', 'PatientController@insuranceCoverageHistory')->name('insurance-coverage-history');
             Route::get('messaging', 'PatientController@messaging')->name('messaging');
             Route::get('duplicate', 'PatientController@duplicate')->name('duplicate');