Bläddra i källkod

Fix vitals section

Vijayakrishnan Krishnan 4 år sedan
förälder
incheckning
e7a8d2e21b

+ 62 - 0
storage/sections/vitals/actions.php

@@ -0,0 +1,62 @@
+<?php
+
+$vitalMap = [
+    'heightInches' => 'Ht. (in.)',
+    'weightPounds' => 'Wt. (lbs.)',
+    'temperatureF' => 'Temp. (F)',
+    'pulseRatePerMinute' => 'Pulse',
+    'respirationRatePerMinute' => 'Resp.',
+    'pulseOx' => 'Pulse Ox.',
+    'systolicBP' => 'SBP',
+    'diastolicBP' => 'DBP',
+    'smokingStatus' => 'Smoking Status'
+];
+$vitalLabels = ['Ht. (in.)', 'Wt. (lbs.)', 'Temp. (F)', 'Pulse', 'Resp.', 'Pulse Ox.', 'SBP', 'DBP', 'Smoking Status'];
+$vitalValues = [];
+foreach ($patient->measurements as $measurement) {
+    if (!empty($measurement->label) && in_array($measurement->label, $vitalLabels)) {
+        $vitalValues[$measurement->label] = [
+            'value' => $measurement->value,
+            'effectiveDate' => $measurement->effective_date
+        ];
+    }
+}
+
+$value = [];
+global $defaultData;
+foreach ($vitalValues as $lbl => $line):
+    $rows[] = '<label class="d-flex align-items-center current-vital-item mb-1 c-pointer">' .
+        '<input type="checkbox" checked class="my-0 mr-2">' .
+        '<span>' . $lbl . ': <b>' . $line['value'] . '</b> ' .
+        '<span class="text-sm">(as on ' . friendly_date_time($line['effectiveDate'], false) . ')</span>' .
+        '</span></label>';
+endforeach;
+?>
+
+<div moe class="position-relative d-none if-edit ml-3 pl-3 border-left">
+    <a start show href="#">Current Vitals</a>
+    <form url="/no-op" class="current-vital-form">
+        <div class="min-width-300px">
+            <?= implode("", $rows) ?>
+            <div class="mt-2 mb-0">
+                <button class="btn btn-primary btn-sm mr-1" type="button" onclick="return applySelectedVital()">Apply</button>
+                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+            </div>
+        </div>
+    </form>
+</div>
+
+<script>
+    function applySelectedVital() {
+        let html = [];
+        $('.current-vital-item input:checkbox:checked').each(function() {
+            html.push('<p>' + $(this).next().html() + '</p>');
+        });
+        $('.current-vital-form').hide();
+        hideMask();
+        hideMoeFormMask();
+        $('.ql-editor[contenteditable]:visible').first().html(html.join('')).focus();
+        return false;
+    }
+</script>
+

+ 36 - 0
storage/sections/vitals/default.php

@@ -0,0 +1,36 @@
+<?php
+
+$vitalMap = [
+    'heightInches' => 'Ht. (in.)',
+    'weightPounds' => 'Wt. (lbs.)',
+    'temperatureF' => 'Temp. (F)',
+    'pulseRatePerMinute' => 'Pulse',
+    'respirationRatePerMinute' => 'Resp.',
+    'pulseOx' => 'Pulse Ox.',
+    'systolicBP' => 'SBP',
+    'diastolicBP' => 'DBP',
+    'smokingStatus' => 'Smoking Status'
+];
+$vitalLabels = ['Ht. (in.)','Wt. (lbs.)','Temp. (F)','Pulse','Resp.','Pulse Ox.','SBP','DBP','Smoking Status'];
+$vitalValues = [];
+foreach($patient->measurements as $measurement) {
+    if(!empty($measurement->label) && in_array($measurement->label, $vitalLabels)){
+        $vitalValues[$measurement->label] = [
+            'value'=>$measurement->value,
+            'effectiveDate' => $measurement->effective_date
+        ];
+    }
+}
+
+$value = [];
+global $defaultData;
+foreach ($vitalValues as $lbl => $line):
+    $value[] = '<p>' . $lbl . ': <b>' . $line['value'] . '</b>' .
+        '<span class="text-sm"> (as on ' . friendly_date_time($line['effectiveDate'], false) . ')</span>' .
+        '</p>';
+endforeach;
+$value = implode("", $value);
+$defaultData = [
+    "summary" => $value,
+    "value" => $value,
+];

+ 25 - 89
storage/sections/vitals/form.blade.php

@@ -3,101 +3,37 @@ $contentData = false;
 if($section){
     $contentData = json_decode($section->content_data, true);
 }
-if(!$contentData) {
-    $contentData = [];
+if(!$contentData || !isset($contentData['value'])) {
+    $contentData = [
+        'value'=>''
+    ];
 }
 $formID = rand(0, 100000);
 ?>
-<form method="POST" action="/process_form_submit"
-      id="measurements_{{ $formID }}">
-
-    <div v-for="(item, index) in items" class="note-section-item-row">
-        <div class="row mb-2">
-            <div class="col-md-3">
-                <label v-if="index === 0" class="text-secondary text-sm mb-1 d-block">Vital Type</label>
-                <input class="form-control form-control-sm" type="text" v-model="item.label" required>
-            </div>
-            <div class="col-md-3">
-                <label v-if="index === 0" class="text-secondary text-sm mb-1 d-block">Value</label>
-                <input class="form-control form-control-sm" type="text" v-model="item.value" required>
-            </div>
-            <div class="col-md-3">
-                <label v-if="index === 0" class="text-secondary text-sm mb-1 d-block">Related To:</label>
-                <input class="form-control form-control-sm" type="date" max="{{ date('Y-m-d') }}"  v-model="item.effectiveDate">
-            </div>
-            <div class="col-md-3">
-                <label v-if="index === 0" class="text-secondary text-sm mb-1 d-block">&nbsp;</label>
-                <a v-if="items.length > 1" href="#" v-on:click.prevent="removeItem(index)"
-                   class="on-hover-opaque text-danger mt-1 d-inline-block">
-                    <i class="fa fa-trash-alt"></i>
-                </a>
-            </div>
-        </div>
+<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?>">
+    <?php else: ?>
+    <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">
+        <textarea rte type="text" class="form-control form-control-sm p-2" name="value" placeholder="Value"><?= $contentData['value'] ?></textarea>
     </div>
-
-    <div class="form-group mt-3 mb-0 d-flex">
-        <button class="btn btn-sm btn-primary mr-2" v-on:click.prevent="submitForm()">Submit</button>
-        <button class="btn btn-sm btn-default text-primary border border-primary mr-2"
-                v-on:click.prevent="addItem()"
-            >Add Vital</button>
-        <button class="btn btn-sm btn-default border" type="button" v-on:click.prevent="cancelForm()">Cancel</button>
+    <div class="form-group m-0 d-flex">
+        <button class="btn btn-sm btn-primary mr-2">Submit</button>
+        <button class="btn btn-sm btn-default border" onclick="return cancelForm_NoteSection_{{ $formID }}(this)">Cancel</button>
     </div>
 </form>
 <script>
-    (function() {
-
-        let input = {!! json_encode($contentData)  !!};
-        if(!input) input = {};
-        if(!input.measurements || !input.measurements.length) {
-            input.measurements = [{
-                label: '',
-                value: '',
-                effectiveDate: '',
-                memo: 'Created from note'
-            }];
-        }
-
-        window.measurementsApp = new Vue({
-            el: '#measurements_{{ $formID }}',
-            data: {
-                form: $('#measurements_{{ $formID }}'),
-                items: input.measurements
-            },
-            methods: {
-                addItem: function() {
-                    this.items.push({
-                        label: '',
-                        value: '',
-                        effectiveDate: '',
-                        memo: 'Created from note'
-                    });
-                },
-                removeItem: function(_index) {
-                    this.items.splice(_index, 1);
-                },
-                submitForm: function() {
-                    var payload = {};
-                    <?php if($section): ?>
-                        payload.section_uid = '<?= $section->uid ?>';
-                    <?php else: ?>
-                        payload.note_uid = '<?= $note->uid ?>';
-                        payload.section_template_uid = '<?= $sectionTemplate->uid ?>';
-                    <?php endif; ?>
-                    payload.measurements = JSON.stringify(this.items);
-                    $.post('/process_form_submit', payload, function(_data) {
-                        fastReload();
-                    });
-                },
-                cancelForm: function () {
-                    this.form.closest('.note-section').toggleClass('edit');
-                    return false;
-                }
-            },
-            mounted: function () {
-                this.form = $('#measurements_{{ $formID }}');
-            }
+    function submitForm_NoteSection_{{ $formID }}(_form) {
+        $.post(_form.action, $(_form).serialize(), function(_data) {
+            fastReload();
         });
-
-    })();
-
+        return false;
+    }
+    function cancelForm_NoteSection_{{ $formID }}(_trigger) {
+        $(_trigger).closest('.note-section').toggleClass('edit');
+        return false;
+    }
 </script>

+ 1 - 3
storage/sections/vitals/processor.php

@@ -1,6 +1,4 @@
 <?php
-
-$inputs = json_decode($request->get('measurements'));
 $newContentData = [
-    "measurements" => $inputs
+    'value' => $request->get('value')
 ];

+ 1 - 16
storage/sections/vitals/summary.php

@@ -1,16 +1 @@
-<?php
-if(!$newContentData || !$newContentData["measurements"]) {
-    echo "-";
-}
-else {
-    for ($i = 0; $i < count($newContentData["measurements"]); $i++) { ?>
-
-        <div class="mb-1">
-            <?= $newContentData["measurements"][$i]->label ?>:
-            <b><?= $newContentData["measurements"][$i]->value ?></b>
-            <span class="text-secondary text-sm ml-1">(as on <?= friendly_date_time($newContentData["measurements"][$i]->effectiveDate, false) ?>)</span>
-        </div>
-
-    <?php }
-}
-
+<div><?= $newContentData['value']; ?></div>