Преглед изворни кода

Visit UI - CC - default auto-generation

Vijayakrishnan пре 3 година
родитељ
комит
9ab67c2a99

+ 15 - 0
app/Models/Point.php

@@ -85,4 +85,19 @@ class Point extends Model
         }
         return $points;
     }
+
+    public static function getPointsOfCategory(Client $_patient, String $_category, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('is_removed', false)
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
 }

+ 53 - 1
resources/views/app/patient/segment-templates/chief_complaint/edit.blade.php

@@ -1,4 +1,56 @@
 <?php
 $category = 'CHIEF_COMPLAINT';
 $endPoint = 'upsertNoteSingleton';
-include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');
+
+use App\Models\Point;
+
+$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
+$parsed = null;
+if ($point && !!@$point->data) {
+    $parsed = json_decode($point->data);
+}
+
+if(!$parsed || !@$parsed->free_text) {
+    $problemPoints = Point::getPointsOfCategory($patient, 'PROBLEM');
+    $problemNames = [];
+    foreach ($problemPoints as $problemPoint) {
+        $problemNames[] = $problemPoint->data->name;
+    }
+    $problems = '';
+    for($i = 0; $i < count($problemNames); $i++) {
+        if($i > 0) {
+            if($i === count($problemNames) - 1) {
+                $problems .= " and ";
+            }
+            else {
+                $problems .= ", ";
+            }
+        }
+        $problems .= $problemNames[$i];
+    }
+    $defaultCC = "Patient {$patient->name_first} {$patient->name_last} " .
+        "is a {$patient->age_in_years} year old" .
+        ($patient->sex ? ($patient->sex === 'F' ? ' female' : ($patient->sex === 'M' ? ' male' : ' ' . $patient->sex)) : '') .
+        ($problems ? " with a history of {$problems}" : "") .
+        ($note->new_or_fu_or_na === 'NEW' ? ' presenting for establishing care' : ' presenting for follow-up') .
+        ".";
+    $parsed = json_decode(json_encode([
+        "free_text" => $defaultCC
+    ]));
+}
+?>
+<div visit-moe close-on-save close-on-cancel class="d-block">
+    <form show url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">
+        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+        <input type="hidden" name="category" value="<?= $category ?>">
+        <input type="hidden" name="data">
+        <div note-rte
+             class="form-group mb-2 border-left border-right rte-holder"
+             data-field-name="free_text"
+        ><?= $parsed && @$parsed->free_text ? $parsed->free_text : '' ?></div>
+        <div>
+            <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
+            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+        </div>
+    </form>
+</div>

+ 49 - 1
resources/views/app/patient/segment-templates/chief_complaint/summary.blade.php

@@ -1,3 +1,51 @@
 <?php
 $category = 'CHIEF_COMPLAINT';
-include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');
+
+use App\Models\Point;
+
+$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
+$parsed = null;
+if ($point && !!@$point->data) {
+    $parsed = json_decode($point->data);
+}
+
+if(!$parsed || !@$parsed->free_text) {
+    $problemPoints = Point::getPointsOfCategory($patient, 'PROBLEM');
+    $problemNames = [];
+    foreach ($problemPoints as $problemPoint) {
+        $problemNames[] = $problemPoint->data->name;
+    }
+    $problems = '';
+    for($i = 0; $i < count($problemNames); $i++) {
+        if($i > 0) {
+            if($i === count($problemNames) - 1) {
+                $problems .= " and ";
+            }
+            else {
+                $problems .= ", ";
+            }
+        }
+        $problems .= $problemNames[$i];
+    }
+    $defaultCC = "Patient {$patient->name_first} {$patient->name_last} " .
+        "is a {$patient->age_in_years} year old" .
+        ($patient->sex ? ($patient->sex === 'F' ? ' female' : ($patient->sex === 'M' ? ' male' : ' ' . $patient->sex)) : '') .
+        ($problems ? " with a history of {$problems}" : "") .
+        ($note->new_or_fu_or_na === 'NEW' ? ' presenting for establishing care' : ' presenting for follow-up') .
+        ".";
+    $parsed = json_decode(json_encode([
+        "free_text" => $defaultCC
+    ]));
+}
+?>
+<div>
+    <?php
+    if (!!$parsed && @$parsed->free_text) {
+        echo $parsed->free_text;
+    }
+    else {
+        echo "-";
+    }
+    ?>
+</div>
+