浏览代码

Overhaul sochx section

Vijayakrishnan Krishnan 4 年之前
父节点
当前提交
8122ca9f8e
共有 3 个文件被更改,包括 150 次插入9 次删除
  1. 73 6
      storage/sections/sochx/form.blade.php
  2. 33 2
      storage/sections/sochx/processor.php
  3. 44 1
      storage/sections/sochx/summary.php

+ 73 - 6
storage/sections/sochx/form.blade.php

@@ -1,13 +1,44 @@
 <?php
+$fields = [
+    [
+        "Tobacco:::Current every day smoker|Current some day smoker|Former smoker|Heavy tobacco smoker|Light tobacco smoker|Never smoker|Smoker, current status unknown|Unknown if ever smoked ",
+    ],
+    [
+        "Alcohol:::Do not drink|Drink daily|Frequently drink|Hx of Alcoholism|Occasional drink",
+        "Drug Abuse:::IVDU|Illicit drug use|No illicit drug use",
+    ],
+    [
+        "Cardiovascular:::Eat healthy meals|Regular exercise|Take daily aspirin",
+        "Safety:::Household Smoke detector|Keep Firearms in home|Wear seatbelts",
+    ],
+    [
+        "Sexual Activity:::Exposure to STI|Homosexual encounters|Not sexually active|Safe sex practices|Sexually active",
+        "Birth Gender:::Male|Female|Undifferentiated",
+    ]
+];
+
 $contentData = false;
 if($section){
     $contentData = json_decode($section->content_data, true);
 }
-if(!$contentData || !isset($contentData['value'])) {
-    $contentData = [
-        'value'=>''
-    ];
+if(!$contentData) {
+    $contentData = [];
 }
+for ($i = 0; $i < count($fields); $i++) {
+    for($j = 0; $j < count($fields[$i]); $j++) {
+        $parts = explode(":::", $fields[$i][$j]);
+        $head = 'custom';
+        if(!empty($parts[0])) $head = $parts[0];
+        $values = explode("|", $parts[1]);
+        for($k = 0; $k < count($values); $k++) {
+            $fName = $head . '_' . sanitize_field_name($values[$k]);
+            if(!isset($contentData[$fName])) {
+                $contentData[$fName] = '';
+            }
+        }
+    }
+}
+
 $formID = rand(0, 100000);
 ?>
 <form method="POST" action="/process_form_submit" onsubmit="return submitForm_NoteSection_{{ $formID }}(this);">
@@ -17,9 +48,45 @@ $formID = rand(0, 100000);
         <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 class="row">
+        @for ($i = 0; $i < count($fields); $i++)
+            <div class="col-md-3">
+                @for($j = 0; $j < count($fields[$i]); $j++)
+                    <?php
+                        $parts = explode(":::", $fields[$i][$j]);
+                        $head = 'custom';
+                        if(!empty($parts[0])) $head = $parts[0];
+                        $values = explode("|", $parts[1]);
+                    ?>
+                    <div class="mb-3">
+                        @if($head !== 'custom')
+                            <div class="font-weight-bold mb-2">{{ $head }}</div>
+                        @endif
+                        @for($k = 0; $k < count($values); $k++)
+                            <?php
+                                $fName = $head . '_' . sanitize_field_name($values[$k]);
+                            ?>
+                             <label class="d-flex align-items-center mb-1">
+                                 <input type="checkbox" name="{{ $fName }}" {{ $contentData[$fName] ? 'checked' : '' }} class="m-0">
+                                 <span class="ml-2">{{ $values[$k] }}</span>
+                             </label>
+                        @endfor
+                    </div>
+                @endfor
+            </div>
+        @endfor
+    </div>
+
+    <div class="row mb-3">
+        <div class="col-12">
+            <textarea rte type="text" class="form-control form-control-sm p-2"
+                      name="comments"
+                      data-shortcuts="{{ $shortcuts }}"
+                      placeholder="Value"><?= isset($contentData['comments']) ? $contentData['comments'] : '' ?></textarea>
+        </div>
     </div>
+
     <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>

+ 33 - 2
storage/sections/sochx/processor.php

@@ -1,4 +1,35 @@
 <?php
-$newContentData = [
-    'value' => $request->get('value')
+$fields = [
+    [
+        "Tobacco:::Current every day smoker|Current some day smoker|Former smoker|Heavy tobacco smoker|Light tobacco smoker|Never smoker|Smoker, current status unknown|Unknown if ever smoked ",
+    ],
+    [
+        "Alcohol:::Do not drink|Drink daily|Frequently drink|Hx of Alcoholism|Occasional drink",
+        "Drug Abuse:::IVDU|Illicit drug use|No illicit drug use",
+    ],
+    [
+        "Cardiovascular:::Eat healthy meals|Regular exercise|Take daily aspirin",
+        "Safety:::Household Smoke detector|Keep Firearms in home|Wear seatbelts",
+    ],
+    [
+        "Sexual Activity:::Exposure to STI|Homosexual encounters|Not sexually active|Safe sex practices|Sexually active",
+        "Birth Gender:::Male|Female|Undifferentiated",
+    ]
 ];
+
+$newContentData = [];
+
+for ($i = 0; $i < count($fields); $i++) {
+    for($j = 0; $j < count($fields[$i]); $j++) {
+        $parts = explode(":::", $fields[$i][$j]);
+        $head = 'custom';
+        if(!empty($parts[0])) $head = $parts[0];
+        $values = explode("|", $parts[1]);
+        for($k = 0; $k < count($values); $k++) {
+            $fName = $head . '_' . sanitize_field_name($values[$k]);
+            $newContentData[$fName] = $request->get($fName);
+        }
+    }
+}
+
+$newContentData['comments'] = $request->get('comments');

+ 44 - 1
storage/sections/sochx/summary.php

@@ -1 +1,44 @@
-<div><?= $newContentData['value']; ?></div>
+<?php
+$fields = [
+    [
+        "Tobacco:::Current every day smoker|Current some day smoker|Former smoker|Heavy tobacco smoker|Light tobacco smoker|Never smoker|Smoker, current status unknown|Unknown if ever smoked ",
+    ],
+    [
+        "Alcohol:::Do not drink|Drink daily|Frequently drink|Hx of Alcoholism|Occasional drink",
+        "Drug Abuse:::IVDU|Illicit drug use|No illicit drug use",
+    ],
+    [
+        "Cardiovascular:::Eat healthy meals|Regular exercise|Take daily aspirin",
+        "Safety:::Household Smoke detector|Keep Firearms in home|Wear seatbelts",
+    ],
+    [
+        "Sexual Activity:::Exposure to STI|Homosexual encounters|Not sexually active|Safe sex practices|Sexually active",
+        "Birth Gender:::Male|Female|Undifferentiated",
+    ]
+];
+
+for ($i = 0; $i < count($fields); $i++) {
+    for($j = 0; $j < count($fields[$i]); $j++) {
+        $parts = explode(":::", $fields[$i][$j]);
+        $head = 'custom';
+        if(!empty($parts[0])) $head = $parts[0];
+        $values = explode("|", $parts[1]);
+        for($k = 0; $k < count($values); $k++) {
+            $fName = $head . '_' . sanitize_field_name($values[$k]);
+            if(isset($newContentData[$fName])) { ?>
+                <div>
+                    <?= ucwords($head) ?>
+                    <i class="fa fa-arrow-right text-sm text-secondary"></i>
+                    <span class="font-weight-bold"><?= $values[$k] ?></span>
+                </div>
+            <?php }
+        }
+    }
+}
+
+if(isset($newContentData['comments'])) { ?>
+    <div class="mt-2 mb-1">
+        <div class="font-weight-bold">Comments:</div>
+        <div><?= $newContentData['comments'] ?></div>
+    </div>
+<?php }