Sfoglia il codice sorgente

cc_may21 - v1 (wip)

Vijayakrishnan 4 anni fa
parent
commit
dc321405ff

+ 7 - 2
app/Http/Controllers/NoteController.php

@@ -90,8 +90,13 @@ class NoteController extends Controller
 
                 // for canvas section where we have pro mapped data, use hcpProId
                 $hcpPro = null;
-                if(\request()->input('hcpProId')) {
-                    $hcpPro = Pro::where('id', \request()->input('hcpProId'))->first();
+                if(\request()->input('hcpProUId')) {
+                    $hcpPro = Pro::where('uid', \request()->input('hcpProUid'))->first();
+                }
+
+                $note = null;
+                if(\request()->input('noteUid')) {
+                    $note = Note::where('uid', \request()->input('noteUid'))->first();
                 }
 
                 // default should simply assign to $contentData

+ 54 - 0
resources/views/app/patient/canvas-sections/cc_may21/default.php

@@ -0,0 +1,54 @@
+<?php
+
+use App\Models\Client;
+use App\Models\Note;
+
+/** @var Client $patient */
+/** @var Note $note */
+
+$canvasData = [
+    "text" => '',
+    "was_confirmed" => false,
+    "note_uid" => '',
+];
+
+$patientDx = null;
+
+if ($patient->canvas_data) {
+    $canvasData = json_decode($patient->canvas_data, true);
+    if (isset($canvasData["dx"])) {
+        $patientDx = $canvasData["dx"];
+    }
+    if (isset($canvasData["cc_may21"])) {
+        $canvasData = $canvasData["cc_may21"];
+    }
+}
+$contentData = $canvasData;
+
+if (!isset($contentData['note_uid']) || $contentData['note_uid'] !== @$note->uid) {
+    $prefix = $patient->name_prefix ?: '';
+    if (!$prefix) {
+        $prefix = $patient->sex === 'M' ? 'Mr. ' : 'Ms. ';
+    }
+
+    $lines = [];
+    $output = '';
+    if ($patientDx && isset($patientDx['items'])) {
+        $lines = $patientDx['items'];
+        foreach ($lines as $i => $line) {
+            if ($i > 0) {
+                $output .= ($i < count($lines) - 2 ? ', ' : ($i === count($lines) - 2 ? ' and ' : ''));
+            }
+            $output .= $line['title'];
+        }
+    }
+
+    $contentData['text'] =
+        $prefix . $patient->name_first . ' ' . $patient->name_last . ' ' .
+        'is a ' . $patient->age_in_years . ' y.o. ' . $patient->sex . ' ' .
+        (!empty($output) ? (' with ' . $output) : '') . ' ' .
+        'presenting today ' .
+        (@$note ? (@$note->new_or_fu_or_na === 'NEW' ? 'to establish care' : 'for follow-up') : '') . '.';
+    $contentData['was_confirmed'] = false;
+    $contentData['note_uid'] = @$note->uid;
+}

+ 106 - 0
resources/views/app/patient/canvas-sections/cc_may21/form.blade.php

@@ -0,0 +1,106 @@
+<?php
+if(!$contentData || !isset($contentData['text']) || !isset($contentData['was_confirmed'])) {
+    $contentData = [
+        "text" => '',
+        "was_confirmed" => false,
+        "note_uid" => (@$note ? $note->uid : ''),
+    ];
+}
+
+$formID = rand(0, 100000);
+?>
+<div id="ccMay21Section">
+    <input type="hidden" name="data" value="{{json_encode($contentData)}}">
+    <div class="border-right border-left">
+        <textarea class="form-group mb-2">{{$contentData['text']}}</textarea>
+    </div>
+    <label class="d-flex align-items-center my-3">
+        <input type="checkbox" v-model="data.was_confirmed" {{$contentData['was_confirmed'] ? 'checked' : ''}} class="my-0 mr-2">
+        <span>Confirm</span>
+    </label>
+</div>
+<script>
+    (function() {
+        function init() {
+            window.clientCCMay21App = new Vue({
+                el: '#ccMay21Section',
+                data: {
+                    data: <?= json_encode($contentData) ?>
+                },
+                mounted: function() {
+                    this.initRTE();
+                },
+                watch: {
+                    $data: {
+                        handler: function(val, oldVal) {
+                            $(this.$el).closest('#ccMay21Section').find('[name="data"]').val(JSON.stringify({
+                                text: this.data.text,
+                                was_confirmed: this.data.was_confirmed,
+                                note_uid: '{{(@$note ? $note->uid : '')}}',
+                            }));
+                        },
+                        deep: true
+                    }
+                },
+                methods: {
+                    cleanArray: function(_source) {
+                        let plItems = [], plObject = {};
+                        for (let x=0; x<_source.length; x++) {
+                            plObject = {};
+                            for (let y in _source[x]) {
+                                if(_source[x].hasOwnProperty(y)) {
+                                    plObject[y] = _source[x][y];
+                                }
+                            }
+                            plItems.push(plObject);
+                        }
+                        return plItems;
+                    },
+                    initRTE: function() {
+                        let self = this;
+                        $('#ccMay21Section textarea').each(function() {
+
+                            $(this).wrap(
+                                $('<div class="rte-holder"/>')
+                                    .attr('data-shortcuts', '')
+                            );
+
+                            // give a unique id to this editor instance
+                            var editorID = Math.ceil(Math.random() * 99999);
+
+                            $('<div data-editor-id="' + editorID + '" data-field="' + this.name + '"/>')
+                                .html(this.value)
+                                .insertBefore(this);
+
+                            $(this).remove();
+
+                            var qe = new Quill('[data-editor-id="' + editorID + '"]', {
+                                theme: 'snow',
+                                modules: stagQuillConfig
+                            });
+
+                            var toolbar = $(qe.container).prev('.ql-toolbar');
+
+                            // add button for new shortcut
+                            var newSCButton = $('<button type="button" tabindex="-1" ' +
+                                'class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
+                                'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
+                            toolbar.append(newSCButton);
+
+                            qe.on('text-change', function() {
+                                self.data.text = qe.root.innerHTML;
+                            });
+
+                            $(qe.container)
+                                .find('.ql-editor[contenteditable]')
+                                .attr('data-editor-id', editorID)
+                                .attr('with-shortcuts', 1);
+
+                        });
+                    }
+                }
+            });
+        }
+        addMCInitializer('client-ccMay21', init, '#ccMay21Section');
+    })();
+</script>

+ 26 - 0
resources/views/app/patient/canvas-sections/cc_may21/summary.php

@@ -0,0 +1,26 @@
+<?php
+
+use App\Models\Client;
+use App\Models\Note;
+
+/** @var Client $patient */
+/** @var Note $note */
+
+if(!@$contentData) {
+    $contentData = [
+        "text" => '',
+        "was_confirmed" => false,
+        "note_uid" => (@$note ? $note->uid : '')
+    ];
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["cc_may21"])) {
+            $contentData = $canvasData["cc_may21"];
+            if (!isset($contentData['text'])) $contentData['text'] = '';
+            if (!isset($contentData['was_confirmed'])) $contentData['was_confirmed'] = false;
+        }
+    }
+}
+?>
+
+<p><?= $contentData['text'] ? $contentData['text'] : '-' ?></p>