Browse Source

Allow paste and save cgm in bulk from lv extract

Vijayakrishnan Krishnan 5 ngày trước cách đây
mục cha
commit
dc6d6e2619

BIN
public/img/loading.gif


+ 5 - 0
resources/views/app/patient/measurements.blade.php

@@ -70,6 +70,11 @@
                 <span class="mx-2 text-secondary">|</span>
                 @include('app.patient.partials.add-cgm-measurement')
 
+                @if($pro->pro_type == 'ADMIN')
+                    <span class="mx-2 text-secondary">|</span>
+                    @include('app.patient.partials.add-cgm-bulk-daily-averages')
+                @endif
+
             </div>
             <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                 <thead class="bg-light">

+ 121 - 0
resources/views/app/patient/partials/add-cgm-bulk-daily-averages.blade.php

@@ -0,0 +1,121 @@
+<div id="add-cgm-bulk-daily-averages-container">
+    <div moe>
+        <a start show class="py-0 font-weight-normal">Bulk Add Glucose Measurements</a>
+        <form url="/api/measurement/createForCGM" id="add-cgm-bulk-daily-averages-form">
+
+            <div id="add-cgm-bulk-daily-averages">
+
+                <p class="font-weight-bold text-secondary mb-2">Bulk Add Glucose Measurements</p>
+
+                <div class="mb-2">
+                    <label class="text-secondary text-sm mb-1">JSON From LV-Extract:</label>
+                    <input type="text"
+                        class="form-control form-control-sm"
+                        name="bulkJson"
+                        v-model="pasted"
+                        @paste="processPaste"
+                        required>
+                </div>
+
+                <div class="mb-2">
+                    <label class="text-secondary text-sm mb-1">Entries Detected:</label>
+                    <table class="table table-sm table-striped mb-0">
+                        <tr v-for="entry in detectedRows">
+                            <td>@{{entry.month}}-@{{entry.day}}-@{{entry.year}}</td>
+                            <td>@{{entry.value ? entry.value + ' mg/dL' : ''}}</td>
+                            <td class="text-right align-middle">
+                                <img v-if="(entry.saving && !entry.saved)" src="/img/loading.gif" style="width: 10px">
+                                <i v-if="entry.saved" class="fa fa-check text-sm text-success"></i>
+                            </td>
+                        </tr>
+                    </table>
+                </div>
+
+                {{--<input type="hidden" name="clientUid" value="{{ $patient->uid }}">--}}
+
+                <label class="text-secondary text-sm mb-2">Note: Saving can take some time depending on the number of entries.</label>
+                <div class="d-flex align-items-center">
+                    <button class="btn btn-sm btn-primary mr-2" v-on:click.prevent="doSubmit()">Save</button>
+                    <button class="btn btn-sm btn-default mr-2 border" v-on:click.prevent="doClose()">Cancel</button>
+                </div>
+
+            </div>
+        </form>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            new Vue({
+                el: '#add-cgm-bulk-daily-averages',
+                delimiters: ['@{{', '}}'],
+                data: {
+                    pasted: '',
+                    detectedRows: [{
+                        value: '',
+                        day: '',
+                        month: '',
+                        year: '',
+                        saving: false,
+                        saved: false
+                    }]
+                },
+                methods: {
+                    processPaste: function() {
+                        setTimeout(() => { // hacky but works well
+                            // console.log(this.pasted);
+                            let parsed = [];
+                            try {
+                                parsed = JSON.parse(this.pasted);
+                                for (let i = 0; i < parsed.length; i++) {
+                                    parsed[i].saved = false;
+                                    parsed[i].saving = false;
+                                }
+                                this.detectedRows = parsed;
+                                this.pasted = '';
+                            }
+                            catch (e) {
+                                alert('Invalid data! Cannot detect entries.')
+                                this.detectedRows = [];
+                                this.pasted = '';
+                            }
+                        }, 0);
+                    },
+                    doSubmit: async function() {
+                        // submit to API
+                        for (let i = 0; i < this.detectedRows.length; i++) {
+                            if(this.detectedRows[i].saved) continue;
+                            this.detectedRows[i].saving = true;
+                            await this.submitMeasurement(this.detectedRows[i]);
+                            this.detectedRows[i].saved = true;
+                        }
+                    },
+                    submitMeasurement: async function(_o) {
+
+                        const date = [
+                            _o.year,
+                            (_o.month.length === 1 ? '0' : '') + _o.month,
+                            (_o.day.length === 1 ? '0' : '') + _o.day
+                        ].join('-');
+
+                        await $.post('/api/measurement/createForCGM', {
+                            clientUid: '{{$patient->uid}}',
+                            cgmIsDailyAverage: 1,
+                            cgmDailyAverage: +(_o.value),
+                            effectiveDate: date,
+                            reasonMemo: 'CGM average for ' + date
+                        })
+                    },
+                    doClose: function() {
+                        fastReload();
+                        return false;
+                    }
+                },
+                mounted: function() {
+                },
+            });
+        }
+        addMCInitializer('add-cgm-bulk-daily-averages', init, '#add-cgm-bulk-daily-averages-container')
+    }).call(window);
+</script>