Przeglądaj źródła

Edit mode autocomplete support for rx strengths

Vijayakrishnan 4 lat temu
rodzic
commit
e30a4e1537

+ 1 - 1
resources/views/app/patient/partials/rx.blade.php

@@ -93,7 +93,7 @@
                                     <a class="on-hover-opaque" start show title="Edit">
                                         <i class="font-size-11 fa fa-edit"></i>
                                     </a>
-                                    <form url="/api/clientInfoLine/updateContent">
+                                    <form url="/api/clientInfoLine/updateContent" onshow="rxEditMoeOpened">
                                         <input type="hidden" name="uid" value="{{ $line->uid }}">
                                         <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                                         <input type="hidden" name="category" value="rx">

+ 22 - 3
resources/views/layouts/template.blade.php

@@ -317,12 +317,14 @@
                     $(elem).attr('ac-initialized', 1);
                 });
                 $('[rx-section] input[type="text"][name="contentText"]:not([ac-initialized])').each(function() {
-                    var elem = this,
-                        dynID = 'rx-' + Math.ceil(Math.random() * 1000000);
+                    let elem = this,
+                        randPart = Math.ceil(Math.random() * 1000000),
+                        dynID = 'rx-' + randPart;
                     $(elem).attr('id', dynID);
                     var strengthElem = $(elem).closest('form').find('[name="strength"]')[0],
-                        dynStrengthsID = 'rx-' + Math.ceil(Math.random() * 1000000) + '-strengths';
+                        dynStrengthsID = 'rx-' + randPart + '-strengths';
                     $(strengthElem).attr('id', dynStrengthsID);
+                    $(strengthElem).attr('rx-id', dynID);
                     new window.Def.Autocompleter.Prefetch(dynStrengthsID, []);
                     new window.Def.Autocompleter.Search(dynID,
                         'https://clinicaltables.nlm.nih.gov/api/rxterms/v3/search?ef=STRENGTHS_AND_FORMS');
@@ -335,6 +337,23 @@
                     });
                     $(elem).attr('ac-initialized', 1);
                 });
+                window.rxEditMoeOpened = function() { // note "this" is the "form"
+                    let form = $(this),
+                        rxElem = form.find('input[type="text"][name="contentText"]').first(),
+                        strengthElem = form.find('input[type="text"][name="strength"]').first(),
+                        q = $.trim(rxElem.val());
+                    if(q !== '') {
+                        $.get('https://clinicaltables.nlm.nih.gov/api/rxterms/v3/search?' +
+                            'authenticity_token=' + (window._token || '') + '&' +
+                            'maxList=100&' +
+                            'terms=' + encodeURIComponent(q) + '&' +
+                            'ef=STRENGTHS_AND_FORMS', function(_data) {
+                            if(Array.isArray(_data) && _data.length >= 3 && Array.isArray(_data[2]['STRENGTHS_AND_FORMS']) && Array.isArray(_data[2]['STRENGTHS_AND_FORMS'][0])) {
+                                strengthElem[0].autocomp.setListAndField(_data[2]['STRENGTHS_AND_FORMS'][0], '', true);
+                            }
+                        }, 'json');
+                    }
+                }
             }
             addMCInitializer('patient-single', window.initAutoRxAndICDComplete);
         })();