Просмотр исходного кода

Updated medication section [WIP]

Vijayakrishnan Krishnan 4 лет назад
Родитель
Сommit
186a646688

+ 12 - 0
app/Http/Controllers/NoteController.php

@@ -57,6 +57,18 @@ class NoteController extends Controller
         include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
     }
 
+    public function getDefaultValueForSection($section, $patient_uid) {
+        $defaultData = [
+            "summary" => "",
+            "value" => ""
+        ];
+        $patient = Client::where('uid', $patient_uid)->first();
+        if(file_exists(storage_path('sections/' . $section . '/default.php'))) {
+            include(storage_path('sections/' . $section . '/default.php'));
+        }
+        return json_encode($defaultData);
+    }
+
     public function processFormSubmit(Request $request)
     {
         // for CREATE

+ 18 - 16
resources/views/app/patient/note/dashboard.blade.php

@@ -647,7 +647,7 @@
                 <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
                      :title="section.title + ' - Click to add'"
                      v-if="!section.used"
-                     v-on:click.prevent="add(section.uid)">
+                     v-on:click.prevent="add(section.uid, section.internal_name)">
                     <span class="mx-2">
                         <a class="font-12" href="#">
                             <i class="fa fa-plus-circle"></i>
@@ -672,24 +672,26 @@
                         sections: allSections
                     },
                     methods: {
-                        add: function(_uid) {
-                            $.post('/api/section/create', {
-                                noteUid: '{{$note->uid}}',
-                                summaryHtml: '',
-                                contentData: '',
-                                sectionTemplateUid: _uid,
-                            }, function(_data) {
-                                if(_data) {
-                                    if(_data.success) {
-                                        fastReload();
+                        add: function(_uid, _section) {
+                            $.get('/get-default-section-data/' + _section + '/{{$patient->uid}}' , function(_data) {
+                                $.post('/api/section/create', {
+                                    noteUid: '{{$note->uid}}',
+                                    summaryHtml: _data.summary,
+                                    contentData: JSON.stringify({value: _data.value}),
+                                    sectionTemplateUid: _uid,
+                                }, function(_data) {
+                                    if(_data) {
+                                        if(_data.success) {
+                                            fastReload();
+                                        }
+                                        else {
+                                            toastr.error(_data.message);
+                                        }
                                     }
                                     else {
-                                        toastr.error(_data.message);
+                                        toastr.error('Unable to add section!');
                                     }
-                                }
-                                else {
-                                    toastr.error('Unable to add section!');
-                                }
+                                }, 'json');
                             }, 'json');
                         },
                         remove: function(_uid) {

+ 1 - 0
routes/web.php

@@ -130,4 +130,5 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
     Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');
     Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
+    Route::get("/get-default-section-data/{section}/{uid}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');
 });

+ 19 - 0
storage/sections/medication/default.php

@@ -0,0 +1,19 @@
+<?php
+$value = [];
+$infoLines = json_decode($patient->info_lines);
+$infoLines = !$infoLines ? [] : $infoLines;
+global $defaultData;
+foreach($infoLines as $category => $lines):
+    if($category === "rx"):
+        foreach ($lines as $line):
+            $value[] = '<b>' . $line->contentText . '</b> ';
+            $value[] = @$line->contentDetail->strength;
+            $value[] = '<br>';
+        endforeach;
+    endif;
+endforeach;
+$value = implode("", $value);
+$defaultData = [
+    "summary" => $value,
+    "value" => $value,
+];

+ 6 - 13
storage/sections/medication/form.blade.php

@@ -3,29 +3,22 @@ $contentData = false;
 if($section){
     $contentData = json_decode($section->content_data, true);
 }
-if(!$contentData || !isset($contentData['clientInfoLineMulti'])) {
+if(!$contentData || !isset($contentData['value'])) {
     $contentData = [
-        'clientInfoLineMulti'=> [
-            'category' => 'rx',
-            'contentTexts' => ''
-        ]
+        'value'=>''
     ];
 }
 $formID = rand(0, 100000);
 ?>
 <form method="POST" action="/process_form_submit" onsubmit="return submitForm_NoteSection_{{ $formID }}(this);">
     <?php if($section): ?>
-        <input type="hidden" name="section_uid" value="<?= $section->uid?>">
+    <input type="hidden" name="section_uid" value="<?= $section->uid?>">
     <?php else: ?>
-        <input type="hidden" name="note_uid" value="<?= $note->uid?>">
-        <input type="hidden" name="section_template_uid" value="<?= $sectionTemplate->uid ?>">
+    <input type="hidden" name="note_uid" value="<?= $note->uid?>">
+    <input type="hidden" name="section_template_uid" value="<?= $sectionTemplate->uid ?>">
     <?php endif; ?>
     <div class="form-group mb-2">
-        <label class="text-secondary text-sm mb-1 d-block">One medication per line:</label>
-        <?php
-        $value = $contentData['clientInfoLineMulti']['contentTexts'];
-        ?>
-        <textarea type="text" class="form-control form-control-sm p-2" name="value" placeholder="Value"><?= $value ?></textarea>
+        <textarea rte type="text" class="form-control form-control-sm p-2" name="value" placeholder="Value"><?= $contentData['value'] ?></textarea>
     </div>
     <div class="form-group m-0 d-flex">
         <button class="btn btn-sm btn-primary mr-2">Submit</button>

+ 1 - 5
storage/sections/medication/processor.php

@@ -1,8 +1,4 @@
 <?php
 $newContentData = [
-    "clientInfoLineMulti" => [
-        "category" => "rx",
-        "contentTexts" => $request->get('value')
-    ]
+    'value' => $request->get('value')
 ];
-

+ 1 - 4
storage/sections/medication/summary.php

@@ -1,4 +1 @@
-<?php if(!empty($newContentData['clientInfoLineMulti']) && isset($newContentData['clientInfoLineMulti']['contentTexts'])): ?>
-<pre><?= $newContentData['clientInfoLineMulti']['contentTexts'] ?></pre>
-<?php else: ?>-<?php endif; ?>
-
+<div><?= $newContentData['value']; ?></div>