Browse Source

PM/Soc/Surg Hx - ability to remove custom items

Vijayakrishnan 3 năm trước cách đây
mục cha
commit
55d8a7df4d

+ 1 - 0
app/Models/Pro.php

@@ -156,6 +156,7 @@ class Pro extends Model
     public function canvasCustomItems($_key) {
         return ClientCanvasDataCustomItem::where('key', $_key)
             ->where('pro_id', $this->id)
+            ->where('is_removed', false)
             ->orderBy('label')
             ->get();
     }

+ 16 - 2
resources/views/app/patient/segment-templates/_custom_items/edit.blade.php

@@ -21,13 +21,13 @@
             </div>
         </div>
         <div class="row custom-items-container">
-            <div class="col-4" v-for="item in customFields" v-if="!item.other">
+            <div class="col-4" v-for="(item, itemIndex) in customFields" v-if="!item.other">
                 <label class="d-flex align-items-start mb-1">
                     <input type="checkbox" class="mx-0 mt-1"
                            v-model="item.value">
                     <div class="ml-2 pr-3">
                         <div>
-                            <span class="mr-2 custom-item">@{{ item.label }}</span>
+                            <span class="mr-1 custom-item">@{{ item.label }}</span>
                             <div moe relative no-mask v-show="item.value" >
                                 <a href="#" start show>
                                     <i class="fa-comment" :class="item.comments ? 'fas' : 'far'"></i>
@@ -41,6 +41,20 @@
                                     </div>
                                 </div>
                             </div>
+                            <div moe relative no-mask class="ml-1">
+                                <a href="#" start show>
+                                    <i class="fa fa-trash-alt text-danger on-hover-opaque"></i>
+                                </a>
+                                <div custom-item-form url="/nop">
+                                    <p class="mb-2 text-nowrap">
+                                        Remove this custom item?
+                                    </p>
+                                    <div class="">
+                                        <button type="button" class="btn btn-sm btn-danger" v-on:click.prevent="removeCustomItem(item, itemIndex)" cancel>Yes</button>
+                                        <button type="button" class="btn btn-sm btn-default border" cancel>No</button>
+                                    </div>
+                                </div>
+                            </div>
                         </div>
                         <span v-show="item.value && item.comments"
                               v-html="item.comments"

+ 18 - 1
resources/views/app/patient/segment-templates/_custom_items/script.blade.php

@@ -40,6 +40,11 @@ saveCustomItem: function(_label) {
                 label: _label,
                 value: '',
                 comments: '',
+                uid: _data.data
+            });
+            Vue.nextTick(() => {
+                $('[data-segment-template-name="<?= !!@$segment ? $segment->segmentTemplate->internal_name : $segmentInternalName ?>"]').find('[moe][initialized]').removeAttr('initialized');
+                initMoes();
             });
         }
         else {
@@ -52,4 +57,16 @@ cancelCustomItem: function() {
     hideMoeFormMask();
     $('[custom-item-form]').hide();
     return false;
-},
+},
+removeCustomItem: function(_item, _index) {
+    _item.value = false;
+    $('[custom-item-form]').hide();
+    $.post('/api/clientCanvasCustomItem/remove', {uid: _item.uid}, _data => {
+        if(!hasResponseError(_data)) {
+            this.customFields.splice(_index, 1);
+            Vue.nextTick(() => {
+                $('[data-segment-template-name="<?= !!@$segment ? $segment->segmentTemplate->internal_name : $segmentInternalName ?>"]').find('textarea').first().trigger('input')
+            });
+        }
+    });
+}

+ 23 - 10
resources/views/app/patient/segment-templates/history_social/edit.blade.php

@@ -28,9 +28,9 @@ $fields = [
 ];
 
 $customFields = $pro->canvasCustomItems('sochx');
-$customFields = array_map(function($_item) {
+/*$customFields = array_map(function($_item) {
     return $_item['label'];
-}, $customFields->toArray());
+}, $customFields->toArray());*/
 
 if(!$customFields) $customFields = [];
 
@@ -54,9 +54,7 @@ for ($i = 0; $i < count($fields); $i++) {
         }
     }
 }
-
 ?>
-
 <hr class="hide-outside-popup mt-3 mb-0">
 <div class="p-3 mcp-theme-1">
     <div {{!!$segment ? 'visit-moe' : 'moe'}} close-on-save close-on-cancel class="d-block">
@@ -157,21 +155,36 @@ for ($i = 0; $i < count($fields); $i++) {
                 model.customFields = [];
             }
             for (let i = 0; i < myCustomFields.length; i++) {
-                let found = model.customFields.filter(function(_item) {
-                    return _item.label === myCustomFields[i];
-                }).length;
-                if(!found) {
+                let foundAt = -1;
+                for (let j = 0; j < model.customFields.length; j++) {
+                    if(model.customFields[j].label === myCustomFields[i].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     model.customFields.push({
-                        label: myCustomFields[i],
+                        label: myCustomFields[i].label,
                         value: '',
                         comments: '',
+                        uid: myCustomFields[i].uid
                     })
                 }
+                else {
+                    model.customFields[foundAt].uid = myCustomFields[i].uid;
+                }
             }
 
             // if not own AND not active - remove from model.customFields
             for (let i = model.customFields.length - 1; i >= 0 ; i--) {
-                if(myCustomFields.indexOf(model.customFields[i].label) === -1) {
+                let foundAt = -1;
+                for (let j = 0; j < myCustomFields.length; j++) {
+                    if(model.customFields[i].label === myCustomFields[j].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     if(!!model.customFields[i].value) {
                         model.customFields[i].other = true;
                     }

+ 23 - 10
resources/views/app/patient/segment-templates/history_surgical/edit.blade.php

@@ -25,9 +25,9 @@ $fields = [
 ];
 
 $customFields = $pro->canvasCustomItems('pshx');
-$customFields = array_map(function($_item) {
+/*$customFields = array_map(function($_item) {
     return $_item['label'];
-}, $customFields->toArray());
+}, $customFields->toArray());*/
 
 if(!$customFields) $customFields = [];
 
@@ -51,9 +51,7 @@ for ($i = 0; $i < count($fields); $i++) {
         }
     }
 }
-
 ?>
-
 <hr class="hide-outside-popup mt-3 mb-0">
 <div class="p-3 mcp-theme-1">
     <div {{!!$segment ? 'visit-moe' : 'moe'}} close-on-save close-on-cancel class="d-block">
@@ -157,21 +155,36 @@ for ($i = 0; $i < count($fields); $i++) {
                 model.customFields = [];
             }
             for (let i = 0; i < myCustomFields.length; i++) {
-                let found = model.customFields.filter(function(_item) {
-                    return _item.label === myCustomFields[i];
-                }).length;
-                if(!found) {
+                let foundAt = -1;
+                for (let j = 0; j < model.customFields.length; j++) {
+                    if(model.customFields[j].label === myCustomFields[i].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     model.customFields.push({
-                        label: myCustomFields[i],
+                        label: myCustomFields[i].label,
                         value: '',
                         comments: '',
+                        uid: myCustomFields[i].uid
                     })
                 }
+                else {
+                    model.customFields[foundAt].uid = myCustomFields[i].uid;
+                }
             }
 
             // if not own AND not active - remove from model.customFields
             for (let i = model.customFields.length - 1; i >= 0 ; i--) {
-                if(myCustomFields.indexOf(model.customFields[i].label) === -1) {
+                let foundAt = -1;
+                for (let j = 0; j < myCustomFields.length; j++) {
+                    if(model.customFields[i].label === myCustomFields[j].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     if(!!model.customFields[i].value) {
                         model.customFields[i].other = true;
                     }

+ 23 - 8
resources/views/app/patient/segment-templates/past_medical_history/edit.blade.php

@@ -37,9 +37,9 @@ $fields = [
 ];
 
 $customFields = $pro->canvasCustomItems('pmhx');
-$customFields = array_map(function($_item) {
+/*$customFields = array_map(function($_item) {
     return $_item['label'];
-}, $customFields->toArray());
+}, $customFields->toArray());*/
 
 if(!$customFields) $customFields = [];
 
@@ -195,21 +195,36 @@ for ($i = 0; $i < count($fields); $i++) {
                 model.customFields = [];
             }
             for (let i = 0; i < myCustomFields.length; i++) {
-                let found = model.customFields.filter(function(_item) {
-                    return _item.label === myCustomFields[i];
-                }).length;
-                if(!found) {
+                let foundAt = -1;
+                for (let j = 0; j < model.customFields.length; j++) {
+                    if(model.customFields[j].label === myCustomFields[i].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     model.customFields.push({
-                        label: myCustomFields[i],
+                        label: myCustomFields[i].label,
                         value: '',
                         comments: '',
+                        uid: myCustomFields[i].uid
                     })
                 }
+                else {
+                    model.customFields[foundAt].uid = myCustomFields[i].uid;
+                }
             }
 
             // if not own AND not active - remove from model.customFields
             for (let i = model.customFields.length - 1; i >= 0 ; i--) {
-                if(myCustomFields.indexOf(model.customFields[i].label) === -1) {
+                let foundAt = -1;
+                for (let j = 0; j < myCustomFields.length; j++) {
+                    if(model.customFields[i].label === myCustomFields[j].label) {
+                        foundAt = j;
+                        break;
+                    }
+                }
+                if(foundAt === -1) {
                     if(!!model.customFields[i].value) {
                         model.customFields[i].other = true;
                     }