Эх сурвалжийг харах

Lab/Imaging: new data structure (wip)

Vijayakrishnan 3 жил өмнө
parent
commit
c4a94597fc

+ 219 - 21
resources/views/app/patient/prescriptions-popup/list-popup.blade.php

@@ -26,7 +26,7 @@
             <a href="#" v-on:click.prevent="newERx('OTHER')">+ Other</a>
         @endif
     </div>
-    <div class="d-flex align-items-start">
+    <div class="d-flex align-items-start bg-white">
         <table class="table table-striped table-sm table-bordered mb-0 flex-grow-1">
             <thead>
             <tr>
@@ -143,15 +143,27 @@
                 <div class="d-inline-flex align-items-baseline flex-grow-1">
                     <a v-if="!currentPrescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editClinicalDetails(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
                     <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
-                    <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
+                    <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline flex-grow-1">
                         <div class="" v-if="currentPrescription.erx_category === 'DRUG'">
                             <div class="d-flex align-items-baseline mb-1" v-for="drug in currentPrescription.clinical_detail_json.items">
                                 <b class="mr-2">@{{drug.medication ?? '-'}}</b>
                             </div>
                         </div>
-                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'">
-                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.test ?? '-'}}</b>
-                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.icds ?? '-'}}</span>
+                        <div v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'" class="flex-grow-1">
+                            <div class="border bg-light mb-1 px-2 py-1 flex-grow-1" v-for="item in currentPrescription.clinical_detail_json.items">
+                                <div class="d-flex align-items-baseline mb-1">
+                                    <span class="text-secondary mr-2">Tests:</span>
+                                    <span class="flex-grow-1">
+                                        <b v-for="test in item.tests" class="mr-2">@{{ test.desc }}</b>
+                                    </span>
+                                </div>
+                                <div class="d-flex align-items-baseline">
+                                    <span class="text-secondary mr-2">ICDs:</span>
+                                    <span class="flex-grow-1">
+                                        <b v-for="icd in item.icds" class="mr-2">@{{ icd.code }}</b>
+                                    </span>
+                                </div>
+                            </div>
                         </div>
                         <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'REFERRAL'">
                             <b class="mr-2">@{{currentPrescription.clinical_detail_json.to ?? '-'}}</b>
@@ -463,9 +475,21 @@ GROUP BY erx_category");
                         hcpProUid: '{{$pro->uid}}',
                         erxCategory: 'LAB',
                         clinicalDetailJson: {
-                            test: '',
-                            icds: '',
-                            memo: '',
+                            items: [
+                                {
+                                    tests: [
+                                        {
+                                            desc: '',
+                                        }
+                                    ],
+                                    icds: [
+                                        {
+                                            code: '',
+                                            desc: '',
+                                        }
+                                    ]
+                                }
+                            ]
                         }
                     },
                     currentPrescription_IMAGING: {
@@ -475,9 +499,21 @@ GROUP BY erx_category");
                         hcpProUid: '{{$pro->uid}}',
                         erxCategory: 'IMAGING',
                         clinicalDetailJson: {
-                            test: '',
-                            icds: '',
-                            memo: '',
+                            items: [
+                                {
+                                    tests: [
+                                        {
+                                            desc: '',
+                                        }
+                                    ],
+                                    icds: [
+                                        {
+                                            code: '',
+                                            desc: '',
+                                        }
+                                    ]
+                                }
+                            ]
                         }
                     },
                     currentPrescription_REFERRAL: {
@@ -596,6 +632,100 @@ GROUP BY erx_category");
                         }, 'json');
                         return false;
                     },
+                    addTestSet: function() {
+                        this['currentPrescription_' + this.currentPrescriptionType].clinicalDetailJson.items.push({
+                            tests: [
+                                {
+                                    desc: '',
+                                }
+                            ],
+                            icds: [
+                                {
+                                    code: '',
+                                    desc: '',
+                                }
+                            ]
+                        });
+                    },
+                    addTest: function(_item) {
+                        _item.tests.push({
+                            desc: ''
+                        });
+                        Vue.nextTick(() => {
+                            this.initICDAutoSuggest();
+                        });
+                    },
+                    addICD: function(_item) {
+                        _item.icds.push({
+                            desc: ''
+                        });
+                        Vue.nextTick(() => {
+                            this.initICDAutoSuggest();
+                        });
+                    },
+                    deleteTest: function(_item, _index) {
+                        _item.tests.splice(_index, 1);
+                    },
+                    deleteICD: function(_item, _index) {
+                        _item.icds.splice(_index, 1);
+                    },
+                    getBlankPrescriptionClinicalData: function(_type) {
+                        let data = null;
+                        switch (_type) {
+                            case 'DRUG':
+                                data = {
+                                    items: [
+                                        {
+                                            medication: '',
+                                            dispense: '',
+                                            refills: '',
+                                            purpose: ''
+                                        }
+                                    ]
+                                };
+                                break;
+                            case 'LAB':
+                            case 'IMAGING':
+                                data = {
+                                    items: [
+                                        {
+                                            tests: [
+                                                {
+                                                    desc: '',
+                                                }
+                                            ],
+                                            icds: [
+                                                {
+                                                    code: '',
+                                                    desc: '',
+                                                }
+                                            ]
+                                        }
+                                    ]
+                                };
+                                break;
+                            case 'REFERRAL':
+                                data = {
+                                    to: '',
+                                    memo: '',
+                                };
+                                break;
+                            case 'SUPPLY':
+                                data = {
+                                    item: '',
+                                    quantity: '',
+                                    memo: '',
+                                };
+                                break;
+                            case 'OTHER':
+                                data = {
+                                    title: '',
+                                    memo: '',
+                                };
+                                break;
+                        }
+                        return data;
+                    },
 
                     // new/edit/save-clinical
                     newPrescription: function(_type) {
@@ -622,7 +752,6 @@ GROUP BY erx_category");
                                 };
                                 break;
                             case 'LAB':
-                            case 'IMAGING':
                                 this.currentPrescription_LAB = {
                                     noteUid: '{{ @$note ? $note->uid : '' }}',
                                     clientUid: '{{ $patient->uid }}',
@@ -630,14 +759,52 @@ GROUP BY erx_category");
                                     hcpProUid: '{{$pro->uid}}',
                                     erxCategory: _type,
                                     clinicalDetailJson: {
-                                        test: '',
-                                        icds: '',
-                                        memo: '',
+                                        items: [
+                                            {
+                                                tests: [
+                                                    {
+                                                        desc: '',
+                                                    }
+                                                ],
+                                                icds: [
+                                                    {
+                                                        code: '',
+                                                        desc: '',
+                                                    }
+                                                ]
+                                            }
+                                        ]
+                                    }
+                                };
+                                break;
+                            case 'IMAGING':
+                                this.currentPrescription_IMAGING = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        items: [
+                                            {
+                                                tests: [
+                                                    {
+                                                        desc: '',
+                                                    }
+                                                ],
+                                                icds: [
+                                                    {
+                                                        code: '',
+                                                        desc: '',
+                                                    }
+                                                ]
+                                            }
+                                        ]
                                     }
                                 };
                                 break;
                             case 'REFERRAL':
-                                this.currentPrescription_LAB = {
+                                this.currentPrescription_REFERRAL = {
                                     noteUid: '{{ @$note ? $note->uid : '' }}',
                                     clientUid: '{{ $patient->uid }}',
                                     replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
@@ -650,7 +817,7 @@ GROUP BY erx_category");
                                 };
                                 break;
                             case 'SUPPLY':
-                                this.currentPrescription_LAB = {
+                                this.currentPrescription_SUPPLY = {
                                     noteUid: '{{ @$note ? $note->uid : '' }}',
                                     clientUid: '{{ $patient->uid }}',
                                     replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
@@ -664,7 +831,7 @@ GROUP BY erx_category");
                                 };
                                 break;
                             case 'OTHER':
-                                this.currentPrescription_LAB = {
+                                this.currentPrescription_OTHER = {
                                     noteUid: '{{ @$note ? $note->uid : '' }}',
                                     clientUid: '{{ $patient->uid }}',
                                     replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
@@ -691,7 +858,9 @@ GROUP BY erx_category");
                         this.currentPrescriptionType = _prescription.erx_category;
                         this['currentPrescription_' + this.currentPrescriptionType] = {
                             uid: _prescription.uid,
-                            clinicalDetailJson: JSON.parse(JSON.stringify(_prescription.clinical_detail_json))
+                            clinicalDetailJson: _prescription.clinical_detail_json ?
+                                JSON.parse(JSON.stringify(_prescription.clinical_detail_json)) :
+                                this.getBlankPrescriptionClinicalData(this.currentPrescriptionType)
                         };
                         Vue.nextTick(() => {
                             showStagPopup('pp-prescription-popup-' + this.currentPrescriptionType, true);
@@ -717,6 +886,9 @@ GROUP BY erx_category");
                                     .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.strength))
                                     .val(1);*/
                             }
+                            else if(this.currentPrescriptionType === 'LAB' || this.currentPrescriptionType === 'IMAGING') {
+                                this.initICDAutoSuggest();
+                            }
                         });
                     },
                     savePrescription: function() {
@@ -1020,7 +1192,6 @@ GROUP BY erx_category");
                         if(!this.currentPrescription.clinical_detail_json.items) {
                             this.currentPrescription.clinical_detail_json.items = [];
                         }
-
                         this.currentPrescription.clinical_detail_json.items.push({
                             medication: existing.data.name,
                             dispense: existing.data.dispense,
@@ -1139,6 +1310,7 @@ GROUP BY erx_category");
                                                 // refreshDynamicStagPopup();
                                                 // $('.visit-segment[data-segment-template-name="intake_medications"]').find('.refresh-segment').trigger('click');
 
+
                                                 if(!self.currentPrescription.clinical_detail_json) {
                                                     self.currentPrescription.clinical_detail_json = {};
                                                 }
@@ -1171,7 +1343,33 @@ GROUP BY erx_category");
 
                             });
                         }
-                    }
+                    },
+                    initICDAutoSuggest: function() {
+                        let self = this;
+                        let parentSegment = $('#prescriptions-popup-{{$patient->id}}');
+                        parentSegment.find('input[type="text"][data-field="icd"]:not([ac-initialized])').each(function() {
+                            var elem = this,
+                                dynID = 'icd-' + Math.ceil(Math.random() * 1000000),
+                                itemIndex = $(this).attr('data-item-index'),
+                                icdIndex = $(this).attr('data-icd-index'),
+                                category = $(this).attr('data-category');
+                            $(elem).attr('id', dynID);
+                            new window.Def.Autocompleter.Search(dynID,
+                                'https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search?sf=code,name&ef=name', {
+                                    tableFormat: true,
+                                    valueCols: [0],
+                                    colHeaders: ['Code', 'Name'],
+                                }
+                            );
+                            window.Def.Autocompleter.Event.observeListSelections(dynID, function() {
+                                let autocomp = elem.autocomp, acData = autocomp.getSelectedItemData();
+                                self['currentPrescription_' + category].clinicalDetailJson.items[itemIndex].icds[icdIndex].code = acData[0].code;
+                                self['currentPrescription_' + category].clinicalDetailJson.items[itemIndex].icds[icdIndex].desc = acData[0].data['name'];
+                                return false;
+                            });
+                            $(elem).attr('ac-initialized', 1);
+                        });
+                    },
                 },
                 mounted: function() {
                     let self = this;