فهرست منبع

Allow save plan only if different from prev

Vijayakrishnan 3 سال پیش
والد
کامیت
3efa8329e4

+ 7 - 0
app/Helpers/helpers.php

@@ -642,4 +642,11 @@ if(!function_exists('vsRoElement')) {
             'name="' . $name . '" ' .
             'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
     }
+}
+
+if(!function_exists('str_compact')) {
+    function str_compact($_str)
+    {
+        return preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($_str));
+    }
 }

+ 24 - 2
resources/views/app/patient/note/segment_script.blade.php

@@ -131,13 +131,35 @@
                 dataField.val(JSON.stringify(parsed));
             }
 
-            if(!_silent) showMask();
-
             let closeOnSave = false, noteSection = form.closest('.note-section');
             if($(_trigger).closest('[visit-moe]').is('[close-on-save]')) {
                 closeOnSave = true;
             }
 
+            // disallow-if-value-same-as
+            let compareWith = false;
+            if(form.find('.disallow-if-value-same-as')) {
+                compareWith = $.trim(form.find('.disallow-if-value-same-as').text());
+                if(compareWith && parsed) {
+                    if(!parsed.value) {
+                        alert('Plan cannot be empty!');
+                        return false;
+                    }
+                    let newValue = $('<div/>').html(parsed.value).text().replace(/[^a-zA-Z0-9]/g, '');
+                    alert(newValue);
+                    if(newValue === '') {
+                        alert('Plan cannot be empty!');
+                        return false;
+                    }
+                    if(newValue === compareWith) {
+                        alert('New plan should be different from the previous plan!');
+                        return false;
+                    }
+                }
+            }
+
+            if(!_silent) showMask();
+
             $.post(form.attr('url'), form.serialize(), _data => {
                 if(!hasResponseError(_data)) {
                     if(!_silent) {

+ 4 - 0
resources/views/app/patient/segment-templates/_child_plan/edit-plan.php

@@ -33,6 +33,10 @@ else {
         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
         <input type="hidden" name="data">
 
+        <?php if($segment->segmentTemplate->internal_name === 'plan_problems' && $previousValue): ?>
+        <div class="d-none disallow-if-value-same-as"><?= str_compact($previousValue) ?></div>
+        <?php endif; ?>
+
         <p class="mb-2"><b>Plan</b></p>
 
         <?php if($previousValue): ?>