فهرست منبع

Covid intake => change data-store to top_level / child_review

Vijayakrishnan 3 سال پیش
والد
کامیت
4702443b4a

+ 14 - 0
app/Helpers/helpers.php

@@ -11,6 +11,7 @@ use App\Models\Client;
 use App\Models\Pro;
 use App\Models\Bill;
 //require_once './class.Diff.php';
+use Illuminate\Support\Facades\Http;
 use Soundasleep\Html2Text as Html2Text;
 
 if(!function_exists('toFeetAndInches')) {
@@ -23,6 +24,19 @@ if(!function_exists('toFeetAndInches')) {
     }
 }
 
+if(!function_exists('callJava')) {
+    function callJava($endPoint, $data, $sessionKey) {
+        $url = config('stag.backendUrl') . $endPoint;
+        $response = Http::asForm()
+            ->withHeaders([
+                'sessionKey' => $sessionKey
+            ])
+            ->post($url, $data)
+            ->body();
+        return $response;
+    }
+}
+
 if(!function_exists('feetFromInches')) {
     function feetFromInches($value) {
         if(!$value) return 0;

+ 1 - 1
app/Http/Controllers/NoteController.php

@@ -108,7 +108,7 @@ class NoteController extends Controller
 
             $segment = Segment::where('uid', $segmentUid)->first();
 
-            $recalculatedHtml = $segment->getRecalculatedHtml($performer);
+            $recalculatedHtml = $segment->getRecalculatedHtml($performer, $sessionKey);
 
         } catch (\Throwable $e) {
             return response()->json([

+ 29 - 0
app/Models/Point.php

@@ -316,6 +316,35 @@ class Point extends Model
         return $point;
     }
 
+    public static function getOrCreateOnlyTopLevelPointOfCategory(Note $_note, String $_category, $_sessionKey, $_assoc = false) {
+        $point = Point
+            ::where('client_id', $_note->client_id)
+            ->where('category', $_category)
+            ->where('intention', 'TOP_LEVEL')
+            ->first();
+
+        if(!$point) {
+            $response = callJava('/visitPoint/addTopLevel', [
+                "category" => $_category,
+                "data" => '{}',
+                "noteUid" => $_note->uid,
+                "additionReasonCategory" => 'ON_INTAKE',
+            ], $_sessionKey);
+            // TODO: dont assume success
+            $point = Point
+                ::where('client_id', $_note->client_id)
+                ->where('category', $_category)
+                ->where('intention', 'TOP_LEVEL')
+                ->first();
+        }
+
+        if ($point && $point->data) {
+            $point->data = json_decode($point->data, $_assoc);
+        }
+
+        return $point;
+    }
+
     public static function fillPointStateAndBadge(Point $point, Note $note)
     {
 

+ 2 - 2
app/Models/Segment.php

@@ -37,7 +37,7 @@ class Segment extends Model
         return $this->hasOne(SegmentSummarySuggestion::class, 'id', 'accepted_segment_summary_suggestion_id');
     }
 
-    public function getRecalculatedHtml($performer){
+    public function getRecalculatedHtml($performer, $sessionKey){
         $pro = $performer->pro;
         $segment = $this; 
         $segmentTemplate = $this->segmentTemplate;
@@ -45,7 +45,7 @@ class Segment extends Model
         $note = $this->note;
         $patient = $note->client;
 
-        $data = compact('performer', 'pro', 'segment', 'segmentTemplate', 'note', 'patient');
+        $data = compact('performer', 'pro', 'segment', 'segmentTemplate', 'note', 'patient', 'sessionKey');
 
 
         $summaryHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/summary', $data)->render();

+ 8 - 6
resources/views/app/patient/segment-templates/covid_intake/edit.blade.php

@@ -3,9 +3,9 @@
 use App\Models\Point;
 
 $category = 'COVID_INTAKE';
-$endPoint = 'upsertGlobalSingleton';
 
-$point = Point::getGlobalSingletonOfCategory($patient, 'COVID_INTAKE', true);
+$point = Point::getOrCreateOnlyTopLevelPointOfCategory($note, 'COVID_INTAKE', $sessionKey, true);
+
 $contentData = [
 
 	"ans_cdc_guidelines_aarp_mental_health" => '',
@@ -133,16 +133,18 @@ $contentData = [
 
 ];
 
-if (!!@$point->data) {
-    $contentData = $point->data;
+if ($point->lastChildReview && $point->lastChildReview->data) {
+    $point->lastChildReview->data = json_decode($point->lastChildReview->data, true);
+    $contentData = $point->lastChildReview->data;
 }
 
 ?>
 
 <div visit-moe close-on-save close-on-cancel class="d-block p-3">
-    <form show url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">
+    <form show url="/api/visitPoint/upsertChildReview" class="mcp-theme-1">
+        <input type="hidden" name="uid" value="<?= $point->uid ?>">
+        <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-        <input type="hidden" name="category" value="<?= $category ?>">
         <input type="hidden" name="data" value="{{json_encode($contentData)}}">
         <p class="mb-2">Hi {{strtolower($patient->sex) === 'M' ? 'Mr.' : 'Mrs.'}} {{$patient->displayName()}}, My name is {{$pro->displayName()}}. I'm a board-certified nurse practitioner.</p>