Pārlūkot izejas kodu

Dynamic questions engine (wip)

Vijayakrishnan 3 gadi atpakaļ
vecāks
revīzija
bfcb78edeb

+ 32 - 3
resources/views/app/dq-engine/edit.blade.php

@@ -6,8 +6,37 @@ inputs:
 --}}
 <?php
 $template = json_decode(file_get_contents(resource_path('views/app/dq-templates/' . $template)));
+$loadedData = $data;
+if(!$loadedData || !@$loadedData->lines || !@$loadedData->dataMap) {
+    $loadedData = $template;
+}
 ?>
-@foreach ($template->lines as $line)
-    @include('app.dq-engine.line', compact('line'))
-@endforeach
+<div class="dq-edit-container">
+    <div class="dq-definition"><?= json_encode($loadedData->lines) ?></div>
+    <div class="dq-data-map"><?= json_encode($loadedData->dataMap) ?></div>
+    @foreach ($template->lines as $line)
+        @include('app.dq-engine.line', compact('line'))
+    @endforeach
+</div>
+<script>
+    (function() {
+        function init() {
+            $('.dq-edit-container')
+                .off('change input paste', 'input, textarea, select')
+                .on('change input paste', 'input, textarea, select', function() {
+                    let key = $(this).closest('.dq-line').attr('dq-key'),
+                        dataElem = $(this).closest('.dq-edit-container').find('>.dq-data-map').first(),
+                        current = JSON.parse(dataElem.text());
+                    current[key] = $(this).val();
+                    dataElem.text(JSON.stringify(current));
+                });
+        }
+        function populate() {
+
+        }
+        addMCInitializer('dq-edit', init, '.dq-edit-container');
+    }).call(window);
+</script>
+
+
 

+ 1 - 1
resources/views/app/dq-engine/field/date.blade.php

@@ -1 +1 @@
-<input type="date" class="form-control form-control-sm" id="">
+<input type="date" class="form-control form-control-sm" id="" value="{{ @$loadedData->dataMap->{$line->key} ?: '' }}>

+ 1 - 1
resources/views/app/dq-engine/field/numeric.blade.php

@@ -1 +1 @@
-<input type="number" class="form-control form-control-sm" id="">
+<input type="number" class="form-control form-control-sm" id="" value="{{ @$loadedData->dataMap->{$line->key} ?: '' }}>

+ 1 - 1
resources/views/app/dq-engine/field/radios.blade.php

@@ -1,7 +1,7 @@
 <div class="d-flex align-items-center">
     @foreach(@$line->options as $option)
         <label class="d-inline-flex align-items-center my-0 mr-3">
-            <input type="radio" value="{{$option}}" class="my-0 mr-1">
+            <input type="radio" value="{{$option}}" class="my-0 mr-1" {{ @$loadedData->dataMap->{$line->key} == $option ? 'checked' : '' }}>
             <span>{{$option}}</span>
         </label>
     @endforeach

+ 1 - 1
resources/views/app/dq-engine/field/select.blade.php

@@ -1,6 +1,6 @@
 <select class="form-control form-control-sm" id="">
     <option value="">-- select --</option>
     @foreach(@$line->options as $option)
-        <option value="{{$option}}">{{$option}}</option>
+        <option value="{{$option}}" {{ @$loadedData->dataMap->{$line->key} == $option ? 'selected' : '' }}>{{$option}}</option>
     @endforeach
 </select>

+ 1 - 1
resources/views/app/dq-engine/field/text.blade.php

@@ -1 +1 @@
-<textarea class="form-control form-control-sm" id="" rows="1"></textarea>
+<textarea class="form-control form-control-sm" id="" rows="1">{{ @$loadedData->dataMap->{$line->key} ?: '' }}</textarea>

+ 1 - 1
resources/views/app/dq-engine/field/time.blade.php

@@ -1 +1 @@
-<input type="time" class="form-control form-control-sm" id="">
+<input type="time" class="form-control form-control-sm" id="" value="{{ @$loadedData->dataMap->{$line->key} ?: '' }}>

+ 1 - 1
resources/views/app/dq-engine/line.blade.php

@@ -1,4 +1,4 @@
-<div class="mb-2">
+<div class="mb-2 dq-line" dq-key="{{$line->key}}">
     <label for="" class="mb-1 text-secondary">{{$line->helpText}}</label>
     @include('app.dq-engine.field.' . $line->fieldType)
     @if(@($line->lines) && count($line->lines))

+ 1 - 2
resources/views/app/dq-templates/hpi/core.json

@@ -80,6 +80,5 @@
     "severity" :  null,
     "coping" : null,
     "emotional_impact" :  null
-  },
-  "definition": null
+  }
 }

+ 20 - 0
resources/views/app/dq-templates/test.json

@@ -0,0 +1,20 @@
+{
+  "lines": [
+    {
+      "key": "onset",
+      "helpText": "When did the problem begin?",
+      "resultSummary": "Onset: {value}",
+      "fieldType": "date"
+    },
+    {
+      "key": "location",
+      "helpText": "Where is the CC located?",
+      "resultSummary": "Location: {value}",
+      "fieldType": "time"
+    }
+  ],
+  "dataMap": {
+    "onset" : null,
+    "location" : null
+  }
+}

+ 1 - 1
resources/views/app/patient/note/edit-hpi.blade.php

@@ -69,7 +69,7 @@
 
     <?php
     if(!@$template) {
-        $template = 'hpi/core.json';
+        $template = 'test.json';
     }
     $patient = $note->client;
     $data = $currentReview ? $currentReview : null;

+ 1 - 0
resources/views/app/patient/problems-center.blade.php

@@ -89,6 +89,7 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                                 <a class="pl-2 view-review-log"
                                    native target="_blank"
                                    open-in-stag-popup
+                                   mc-initer="dq-edit"
                                    popup-style="stag-popup-md"
                                    title="HPI<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?> / <?= $patient->displayName() ?>"
                                    href="/point/edit-hpi/<?= $note->uid ?>/<?= $problem->uid ?>?popupmode=1">