Переглянути джерело

implemented medication like segments

= 3 роки тому
батько
коміт
ab82f41645
35 змінених файлів з 877 додано та 170 видалено
  1. 3 0
      app/Http/Controllers/NoteController.php
  2. 42 0
      app/Models/Point.php
  3. 1 1
      app/Models/Segment.php
  4. 39 1
      public/css/style.css
  5. 2 2
      resources/views/app/patient/note/dashboard_script.blade.php
  6. 8 14
      resources/views/app/patient/note/segment.blade.php
  7. 69 126
      resources/views/app/patient/note/segment_script.blade.php
  8. 24 0
      resources/views/app/patient/segment-templates/_child_review/edit-review.php
  9. 14 0
      resources/views/app/patient/segment-templates/_child_review/last-review.php
  10. 55 0
      resources/views/app/patient/segment-templates/_common_actions/remove-undo.php
  11. 2 2
      resources/views/app/patient/segment-templates/_simple_text_segment/edit.php
  12. 87 1
      resources/views/app/patient/segment-templates/intake_allergies/edit.php
  13. 48 1
      resources/views/app/patient/segment-templates/intake_allergies/summary.php
  14. 87 1
      resources/views/app/patient/segment-templates/intake_goals/edit.php
  15. 47 1
      resources/views/app/patient/segment-templates/intake_goals/summary.php
  16. 101 1
      resources/views/app/patient/segment-templates/intake_medications/edit.php
  17. 50 1
      resources/views/app/patient/segment-templates/intake_medications/summary.php
  18. 93 1
      resources/views/app/patient/segment-templates/intake_problems/edit.php
  19. 49 1
      resources/views/app/patient/segment-templates/intake_problems/summary.php
  20. 4 1
      resources/views/app/patient/segment-templates/objective_free_text/edit.php
  21. 3 1
      resources/views/app/patient/segment-templates/objective_free_text/summary.php
  22. 4 1
      resources/views/app/patient/segment-templates/objective_imaging/edit.php
  23. 3 1
      resources/views/app/patient/segment-templates/objective_imaging/summary.php
  24. 4 1
      resources/views/app/patient/segment-templates/objective_labs/edit.php
  25. 3 1
      resources/views/app/patient/segment-templates/objective_labs/summary.php
  26. 4 1
      resources/views/app/patient/segment-templates/objective_measurements/edit.php
  27. 3 1
      resources/views/app/patient/segment-templates/objective_measurements/summary.php
  28. 4 1
      resources/views/app/patient/segment-templates/objective_other_investigations/edit.php
  29. 3 1
      resources/views/app/patient/segment-templates/objective_other_investigations/summary.php
  30. 4 1
      resources/views/app/patient/segment-templates/plan_free_text/edit.php
  31. 3 1
      resources/views/app/patient/segment-templates/plan_free_text/summary.php
  32. 4 1
      resources/views/app/patient/segment-templates/ros/edit.php
  33. 3 1
      resources/views/app/patient/segment-templates/ros/summary.php
  34. 4 1
      resources/views/app/patient/segment-templates/subjective_general/edit.php
  35. 3 1
      resources/views/app/patient/segment-templates/subjective_general/summary.php

+ 3 - 0
app/Http/Controllers/NoteController.php

@@ -87,6 +87,9 @@ class NoteController extends Controller
         $segment = Segment::where('uid', $segmentUid)->first();
         $segmentTemplate = $segment->segmentTemplate;
 
+        $note = $segment->note;
+        $patient = $note->client;
+
         ob_start();
         include(resource_path('views/app/patient/segment-templates/' . $segmentTemplate->internal_name . '/summary.php'));
         $summaryHtml = ob_get_contents();

+ 42 - 0
app/Models/Point.php

@@ -8,4 +8,46 @@ class Point extends Model
 {
     protected $table = 'point';
 
+    public function lastChildReview()
+    {
+        return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
+    }
+
+    public function lastChildReviewNote()
+    {
+        return $this->hasOne(Note::class, 'id', 'last_child_review_point_scoped_note_id');
+    }
+
+    public function lastChildPlan()
+    {
+        return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
+    }
+
+    public function lastChildPlanNote()
+    {
+        return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id');
+    }
+
+    public static function getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('addition_reason_category', 'ON_INTAKE')
+            ->where(function ($query1) use ($_note) {
+                $query1
+                    ->where('is_removed', false)
+                    ->orWhere(function ($query2) use ($_note) {
+                        $query2->where('is_removed', true)
+                            ->where('removed_in_note_id', $_note->id);
+                    });
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data);
+            }
+        }
+        return $points;
+    }
 }

+ 1 - 1
app/Models/Segment.php

@@ -17,6 +17,6 @@ class Segment extends Model
     }
 
     public function client() {
-        return $this->hasOne(Section::class, 'id', 'client_id');
+        return $this->hasOne(Client::class, 'id', 'client_id');
     }
 }

+ 39 - 1
public/css/style.css

@@ -1902,4 +1902,42 @@ body.in-iframe .main-row > .sidebar {
 }
 .stag-popup .hide-inside-popup {
     display: none !important;
-}
+}
+.strike-through {
+    text-decoration: line-through;
+}
+
+/* visit-moe */
+[visit-moe] [url]:not([show]){
+    display: none;
+}
+[visit-moe] {
+    display: inline-block;
+}
+[visit-moe][relative] {
+    position: relative;
+}
+[visit-moe] [url]:not([show]) {
+    z-index: 99999;
+    position: absolute;
+    background-color: white;
+    padding: 10px;
+    border: 1px solid gray;
+}
+[visit-moe][fixed-center] [url]:not([show]) {
+    position: fixed !important;
+    top: 50% !important;
+    left: 50% !important;
+    width: 600px;
+    transform: translate(-50%, -50%) !important;
+}
+[visit-moe] [url][right] {
+    right: 0;
+    min-width: 200px;
+}
+[visit-moe][large] form, [visit-moe][large] [url] {
+    width: 450px;
+}
+[visit-moe][bottom] form {
+    bottom: 100%;
+}

+ 2 - 2
resources/views/app/patient/note/dashboard_script.blade.php

@@ -289,7 +289,7 @@
                     return false;
                 });
 
-                $(document)
+                /*$(document)
                     .off('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)')
                     .on('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)', function(e) {
                         if($(this).closest('.note-signed-by-hcp').length) return;
@@ -297,7 +297,7 @@
                         e.preventDefault();
                         $(this).find('.edit-trigger').first().click();
                         return false;
-                    });
+                    });*/
 
                 // $(document)
                 //     .off('mousedown.enable-edit', '.note-section:not(.edit).page-driven')

+ 8 - 14
resources/views/app/patient/note/segment.blade.php

@@ -11,22 +11,16 @@
 		</span>
 
 		<!-- refresh -->
-		<div moe class="ml-2 d-none if-edit">
-			<a start show class="font-weight-normal" title="Update with latest patient data">
-				<i class="fa fa-sync"></i>
-			</a>
-			<form url="/api/visit/updateSegmentHtml">
-				<p>Update with latest patient data?</p>
-				<input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-				<div class="d-flex align-items-center">
-					<button class="btn btn-sm btn-primary mr-2" type="button" submit>Update</button>
-					<button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
-				</div>
-			</form>
-		</div>
+		<a class="ml-3 font-weight-normal refresh-segment c-pointer"
+		   data-segment-uid="{{$segment->uid}}"
+		   title="Update with latest patient data">
+			Refresh
+		</a>
+
+		<span class="mx-2 text-secondary text-sm d-none if-edit">|</span>
 
 		<!-- toggle to read mode -->
-		<a class="ml-auto edit-trigger d-none if-edit c-pointer">Close</a>
+		<a class="edit-trigger d-none if-edit c-pointer">Close</a>
 	</div>
 
 	<div class="d-none if-not-edit inset-comment summary-container">

+ 69 - 126
resources/views/app/patient/note/segment_script.blade.php

@@ -1,6 +1,14 @@
 <script>
     (function() {
 
+        function updateAllSegmentsInResponse(_response) {
+            if(!hasResponseError(_response)) {
+                for (let i=0; i<_response.data.length; i++) {
+                    updateSegmentFromObject(_response.data[i]);
+                }
+            }
+        }
+
         function updateSegmentFromObject(_object) {
             let segment = $('.note-section[data-segment-uid="' + _object.segmentUid + '"]');
             if(segment && segment.length) {
@@ -8,29 +16,69 @@
                 segment.find('.edit-container').html(_object.editHtml);
                 initRTEs(segment);
                 initSegmentMoes(segment);
-                segment.removeClass('edit');
+                initMoes();
             }
         }
 
         function initSegmentMoes(_parent) {
+
+            $('body')
+                .off('mousedown.visit-moe-outside-click')
+                .on('mousedown.visit-moe-outside-click', function (e) {
+                    if ($(e.target).closest('[visit-moe]').length) {
+                        return;
+                    }
+                    $('[visit-moe] [url]:not([show])').hide();
+                });
+
             _parent.find('[visit-moe] [submit]')
                 .off('click.visit-moe-submit')
                 .on('click.visit-moe-submit', function() {
                     let form = $(this).closest('form');
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+                        parsed[$(this).attr('data-name')] = $(this).val();
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    showMask();
+
                     $.post(form.attr('url'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            for (let i=0; i<_data.data.length; i++) {
-                                updateSegmentFromObject(_data.data[i]);
-                            }
-                        }
+                        hideMask();
+                        updateAllSegmentsInResponse(_data);
                     }, 'json');
                     return false;
                 });
 
+            _parent.find('[visit-moe]>a[start]')
+                .off('click.visit-moe-show')
+                .on('click.visit-moe-show', function () {
+                    $('[visit-moe] [url]:not([show])').hide();
+                    $(this)
+                        .closest('[visit-moe]')
+                        .find('form[url]')
+                        .show();
+                    return false;
+                });
+
             _parent.find('[visit-moe] [cancel]')
                 .off('click.visit-moe-cancel')
                 .on('click.visit-moe-cancel', function() {
-                    $(this).closest('.note-section').removeClass('edit');
+                    $(this).closest('[visit-moe]').find('[url]:not([show])').hide();
                     return false;
                 });
         }
@@ -85,6 +133,20 @@
             initRTEs(parent);
             initSegmentMoes(parent);
 
+            // refresh segment
+            $(document)
+                .off('click.refresh-segment', '.refresh-segment')
+                .on('click.refresh-segment', '.refresh-segment', function() {
+                    showMask();
+                    $.post('/api/visit/updateSegmentHtml', {
+                        segmentUid: $(this).attr('data-segment-uid')
+                    }, _data => {
+                        hideMask();
+                        updateAllSegmentsInResponse(_data);
+                    }, 'json');
+                    return false;
+                });
+
             /*
             $('[btn-save-form]').on('click', function() {
                 doSave($(this).closest('.note-section'));
@@ -112,125 +174,6 @@
              */
         }
 
-        /*
-        const debounce = (func, wait) => {
-            let timeout;
-
-            return function executedFunction(...args) {
-                const later = () => {
-                    clearTimeout(timeout);
-                    func(...args);
-                };
-
-                clearTimeout(timeout);
-                timeout = setTimeout(later, wait);
-            };
-        };
-
-        function doSave(_section) {
-            console.log(_section.attr('data-section-template-name'));
-
-            _section.find('[btn-save-form]').prop('disabled', true);
-            _section.find('.text-saving').removeClass('d-none');
-            _section.find('.text-saved').addClass('d-none');
-
-            var dataField = _section.find('input[name=data]')
-            var value = $(dataField).val();
-
-            var summaryContainer = _section.find('.summary-container')
-
-            var sectionUid = _section.attr('data-section-uid')
-
-            var _form = _section.find('form[processed]')[0];
-            if(_form){
-                console.log("Form found. submitting normally");
-                $.post("/process_form_submit", $(_form).serialize(), function(resp) {
-                    handleSubmitResponse(resp,_section, summaryContainer)
-                }, 'json');
-            }else{
-                console.log("Form not found.");
-                var dataToPost = {
-                    "section_uid": sectionUid,
-                    "data": value,
-                }
-                @if(isset($guestAccessCode))
-                    dataToPost['guest_access_code'] = '{{$guestAccessCode}}';
-                @endif
-                $.post("/process_form_submit", dataToPost, function(resp) {
-                    handleSubmitResponse(resp,_section, summaryContainer);
-
-                    // if "dx", refresh "cc" if it exists in the note
-                    if(_section.attr('data-section-template-name') === 'dx') {
-                        let ccSection = $('[data-section-template-name="cc"]').first();
-                        if(ccSection.length) {
-                            let ccSectionUid = ccSection.attr('data-section-uid');
-                            let items = JSON.parse(value);
-                            if(items && items.items) {
-                                items = items.items
-                                    .filter((_x) => {
-                                        return !!_x.included;
-                                    })
-                                    .map((_x) => {
-                                        return _x.title;
-                                    });
-                            }
-                            let itemsText = '';
-                            if(items.length > 1) {
-                                let lastItem = items[items.length - 1];
-                                items.splice(items.length - 1, 1);
-                                itemsText = items.join(', ') + ' and ' + lastItem;
-                            }
-                            else {
-                                itemsText = items[0];
-                            }
-                            if(!!itemsText && !!ccSectionUid) {
-                                let ccValue = 'Patient {{$patient->name_first . ' ' . $patient->name_last}} ' +
-                                    'is a {{$patient->age_in_years}} year old {{$patient->sex}} with a history of ' +
-                                    itemsText + ' ' +
-                                    '{{ @$note ? (@$note->new_or_fu_or_na === 'NEW' ? 'presenting for establishing care' : 'presenting for follow-up') : '' }}.';
-                                let para = $('<p/>').text(ccValue)[0].outerHTML;
-                                ccSection.find('[name="data"]').first().val(JSON.stringify({value: para}));
-                                ccSection.find('.ql-editor').html(para);
-                                ccSection.find('[btn-save-form]').click();
-                            }
-                        }
-                    }
-
-                }, 'json');
-            }
-        }
-
-        function handleSubmitResponse(resp,_section, summaryContainer){
-            $('body').removeClass('blocking-mode');
-            hideMoeFormMask();
-            if (resp.success) {
-                summaryContainer.html(resp.newSummaryHtml);
-            }
-            _section.find('[btn-save-form]').prop('disabled', false);
-            _section.find('.text-saving').addClass('d-none');
-            if(resp.success) {
-                _section.find('.text-saved').text('Last saved at ' + (new Date().toLocaleTimeString())).removeClass('d-none');
-            }
-        }
-
-        function initChangeListener(_elem) {
-            new MutationObserver(debounce(function() {
-                if(_elem.closest('.note-section').is('.edit')) {
-                    // console.log('ALIX: In edit mode. Auto-saving', _elem.closest('.note-section').attr('data-section-template-name'))
-                    $('body').addClass('blocking-mode');
-                    showMoeFormMask('blocking-overlay');
-                    doSave(_elem.closest('.note-section'));
-                }
-                else {
-                    // console.log('ALIX: Not in edit mode. Not auto-saving', _elem.closest('.note-section').attr('data-section-template-name'))
-                }
-            }, 250))
-            .observe(_elem[0], {
-                attributes: true
-            });
-        }
-        */
-
         addMCInitializer('note-segments-list', init);
 
     })();

+ 24 - 0
resources/views/app/patient/segment-templates/_child_review/edit-review.php

@@ -0,0 +1,24 @@
+<div visit-moe>
+    <a start show href="#">Edit</a>
+    <form url="/api/visitPoint/upsertChildReview" class="mcp-theme-1">
+        <input type="hidden" name="uid" value="<?= $point->uid ?>">
+        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+        <input type="hidden" name="data">
+
+        <p class="mb-2"><b>Review</b></p>
+
+        <div class="mb-2">
+            <textarea data-name="value" class="form-control form-control-sm" rows="3"
+            ><?php
+                if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
+                    $parsedReview = json_decode($point->lastChildReview->data);
+                    echo $parsedReview->value;
+                }
+                ?></textarea>
+        </div>
+        <div>
+            <button submit class="btn btn-sm btn-primary mr-2">Save</button>
+            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+        </div>
+    </form>
+</div>

+ 14 - 0
resources/views/app/patient/segment-templates/_child_review/last-review.php

@@ -0,0 +1,14 @@
+<?php if($point->lastChildReview): ?>
+    <?php $parsedReview = json_decode($point->lastChildReview->data); ?>
+    <div><?= $parsedReview->value ?></div>
+    <div class="text-secondary text-sm"></div>
+    <?php if($point->last_child_review_point_scoped_note_id === $note->id): ?>
+        <span class="text-secondary text-sm">(reviewed on this note)</span>
+    <?php else: ?>
+        <a native target="_blank" href="<?= route('patients.view.notes.view.dashboard', ['patient'=>$patient, 'note'=>$point->lastChildReviewNote])?>">
+            <?= friendlier_date_time($point->last_child_review_effective_date) ?>
+        </a>
+    <?php endif; ?>
+<?php else: ?>
+    <span class="text-secondary text-sm">None</span>
+<?php endif; ?>

+ 55 - 0
resources/views/app/patient/segment-templates/_common_actions/remove-undo.php

@@ -0,0 +1,55 @@
+<?php if ($point->is_removed): ?>
+    <?php if ($point->is_removed_due_to_entry_error): ?>
+        <span class="font-weight-bold text-secondary mr-2">Entry error</span>
+    <?php else: ?>
+        <span class="font-weight-bold text-secondary mr-2">Removed on intake</span>
+    <?php endif; ?>
+    <div visit-moe>
+        <form show url="/api/visitPoint/undoMarkRemoved" class="mcp-theme-1">
+            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <a submit href="#">Undo</a>
+        </form>
+    </div>
+<?php else: ?>
+    <?php if($point->added_in_note_id === $note->id): ?>
+        <span class="font-weight-bold text-success mr-2">* Added on intake</span>
+    <?php endif; ?>
+    <div visit-moe>
+        <a start show href="#">Remove</a>
+        <form url="/api/visitPoint/markRemovedOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+
+            <p class="mb-2"><b>Remove <?= $label ?> (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Removal Reason</label>
+                <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+            </div>
+            <?php if($point->added_in_note_id === $note->id): ?>
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Is Entry Error?  *</label>
+                    <select name="isRemovedDueToEntryError" class="form-control form-control-sm" required>
+                        <option value="">-- select --</option>
+                        <option value="1" selected>Yes</option>
+                        <option value="0">No</option>
+                    </select>
+                </div>
+            <?php else: ?>
+                <input type="hidden" name="isRemovedDueToEntryError" value="0">
+            <?php endif; ?>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
+                <input type="date" name="removalEffectiveDate"
+                       value="<?= date('Y-m-d') ?>"
+                       max="<?= date('Y-m-d') ?>"
+                       class="form-control form-control-sm">
+            </div>
+            <div>
+                <button submit class="btn btn-sm btn-danger mr-2">Remove</button>
+                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+            </div>
+        </form>
+    </div>
+<?php endif; ?>

+ 2 - 2
resources/views/app/patient/segment-templates/_simple_text_segment/edit.php

@@ -8,8 +8,8 @@ if (!!@$point->data) {
     $parsed = json_decode($point->data);
 }
 ?>
-<div visit-moe>
-    <form url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">
+<div visit-moe 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">

+ 87 - 1
resources/views/app/patient/segment-templates/intake_allergies/edit.php

@@ -1 +1,87 @@
-<h1>Edit for intake_allergies</h1>
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$allergies = Point::getIntakePointsOfCategory($patient, 'ALLERGY', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Allergy</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($allergies as $allergy): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $allergy->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
+                                <?= !!@($allergy->data->description) ? '/&nbsp;' . @($allergy->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $allergy;
+                                $label = 'Allergy';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $allergy;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $allergy;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add allergy patient is ALREADY having, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="ALLERGY">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Allergy (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </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>
+</div>
+

+ 48 - 1
resources/views/app/patient/segment-templates/intake_allergies/summary.php

@@ -1 +1,48 @@
-<h1>Summary for intake_allergies</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$allergies = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'ALLERGY')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($allergies as $allergy) {
+    if ($allergy->data) {
+        $allergy->data = json_decode($allergy->data);
+    }
+}
+
+?>
+
+<?php if (!count($allergies)): ?>
+    <div class="text-secondary">No allergies</div>
+<?php else: ?>
+    <?php foreach ($allergies as $allergy): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $allergy->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
+                <?= !!@($allergy->data->description) ? '/&nbsp;' . @($allergy->data->description) : '' ?>
+            </div>
+            <?php if ($allergy->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($allergy->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 87 - 1
resources/views/app/patient/segment-templates/intake_goals/edit.php

@@ -1 +1,87 @@
-<h1>Edit for intake_goals</h1>
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$goals = Point::getIntakePointsOfCategory($patient, 'GOAL', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Goal</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($goals as $goal): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $goal->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($goal->data->name) ? @($goal->data->name) : '-' ?></b>
+                                <?= !!@($goal->data->description) ? '/&nbsp;' . @($goal->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $goal;
+                                $label = 'Goal';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $goal;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $goal;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add goal </a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="GOAL">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Goal (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </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>
+</div>
+

+ 47 - 1
resources/views/app/patient/segment-templates/intake_goals/summary.php

@@ -1 +1,47 @@
-<h1>Summary for intake_goals</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$goals = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'GOAL')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($goals as $goal) {
+    if ($goal->data) {
+        $goal->data = json_decode($goal->data);
+    }
+}
+
+?>
+
+<?php if (!count($goals)): ?>
+    <div class="text-secondary">No goals</div>
+<?php else: ?>
+    <?php foreach ($goals as $goal): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $goal->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($goal->data->name) ? @($goal->data->name) : '-' ?></b>
+                <?= !!@($goal->data->description) ? '/&nbsp;' . @($goal->data->description) : '' ?>
+            </div>
+            <?php if ($goal->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($goal->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>

+ 101 - 1
resources/views/app/patient/segment-templates/intake_medications/edit.php

@@ -1 +1,101 @@
-<h1>Edit for intake_medications</h1>
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Medication</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($medications as $medication): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                                <?= !!@($medication->data->frequency) ? '/&nbsp;' . @($medication->data->frequency) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $medication;
+                                $label = 'Medication';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $medication;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $medication;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add medication patient is ALREADY taking, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="MEDICATION">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Medication (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Dose</label>
+                <input type="text" data-name="dose" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Route</label>
+                <input type="text" data-name="route" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Frequency</label>
+                <input type="text" data-name="frequency" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </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>
+</div>
+

+ 50 - 1
resources/views/app/patient/segment-templates/intake_medications/summary.php

@@ -1 +1,50 @@
-<h1>Summary for intake_medications</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$medications = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($medications as $medication) {
+    if ($medication->data) {
+        $medication->data = json_decode($medication->data);
+    }
+}
+
+?>
+
+<?php if (!count($medications)): ?>
+    <div class="text-secondary">No medications</div>
+<?php else: ?>
+    <?php foreach ($medications as $medication): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                <?= !!@($medication->data->frequency) ? '/&nbsp;' . @($medication->data->frequency) : '' ?>
+            </div>
+            <?php if ($medication->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($medication->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 93 - 1
resources/views/app/patient/segment-templates/intake_problems/edit.php

@@ -1 +1,93 @@
-<h1>Edit for intake_problems</h1>
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$problems = Point::getIntakePointsOfCategory($patient, 'PROBLEM', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Problem</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($problems as $problem): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $problem->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
+                                <?= !!@($problem->data->description) ? '/&nbsp;' . @($problem->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $problem;
+                                $label = 'Problem';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $problem;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $problem;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add Problem patient is ALREADY having, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="PROBLEM">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Problem (on intake)</b></p>
+
+			<div class="mb-2">
+                <label class="text-sm text-secondary mb-1">ICD</label>
+                <input type="text" data-name="icd" class="form-control form-control-sm">
+            </div>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+			
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </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>
+</div>
+

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

@@ -1 +1,49 @@
-<h1>Summary for intake_problems</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$problems = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'PROBLEM')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($problems as $problem) {
+    if ($problem->data) {
+        $problem->data = json_decode($problem->data);
+    }
+}
+
+?>
+
+<?php if (!count($problems)): ?>
+    <div class="text-secondary">No problems</div>
+<?php else: ?>
+    <?php foreach ($problems as $problem): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $problem->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
+                <?= !!@($problem->data->icd) ? '/&nbsp;' . @($problem->data->icd) : '' ?>
+                <?= !!@($problem->data->description) ? '/&nbsp;' . @($problem->data->description) : '' ?>
+            </div>
+            <?php if ($problem->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($problem->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 4 - 1
resources/views/app/patient/segment-templates/objective_free_text/edit.php

@@ -1 +1,4 @@
-<h1>Edit for objective_free_text</h1>
+<?php
+$category = 'OBJECTIVE_FREE_TEXT';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/objective_free_text/summary.php

@@ -1 +1,3 @@
-<h1>Summary for objective_free_text</h1>
+<?php
+$category = 'OBJECTIVE_FREE_TEXT';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/objective_imaging/edit.php

@@ -1 +1,4 @@
-<h1>Edit for objective_imaging</h1>
+<?php
+$category = 'IMAGING';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/objective_imaging/summary.php

@@ -1 +1,3 @@
-<h1>Summary for objective_imaging</h1>
+<?php
+$category = 'IMAGING';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/objective_labs/edit.php

@@ -1 +1,4 @@
-<h1>Edit for objective_labs</h1>
+<?php
+$category = 'LABS';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/objective_labs/summary.php

@@ -1 +1,3 @@
-<h1>Summary for objective_labs</h1>
+<?php
+$category = 'LABS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/objective_measurements/edit.php

@@ -1 +1,4 @@
-<h1>Edit for objective_measurements</h1>
+<?php
+$category = 'MEASUREMENTS_RELEVANT_TO_NOTE';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/objective_measurements/summary.php

@@ -1 +1,3 @@
-<h1>Summary for objective_measurements</h1>
+<?php
+$category = 'MEASUREMENTS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/objective_other_investigations/edit.php

@@ -1 +1,4 @@
-<h1>Edit for objective_other_investigations</h1>
+<?php
+$category = 'OTHER_INVESTIGATIONS';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/objective_other_investigations/summary.php

@@ -1 +1,3 @@
-<h1>Summary for objective_other_investigations</h1>
+<?php
+$category = 'OTHER_INVESTIGATIONS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/plan_free_text/edit.php

@@ -1 +1,4 @@
-<h1>Edit for plan_free_text</h1>
+<?php
+$category = 'PLAN_FREE_TEXT';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/plan_free_text/summary.php

@@ -1 +1,3 @@
-<h1>Summary for plan_free_text</h1>
+<?php
+$category = 'PLAN_FREE_TEXT';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/ros/edit.php

@@ -1 +1,4 @@
-<h1>Edit for ros</h1>
+<?php
+$category = 'ROS';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/ros/summary.php

@@ -1 +1,3 @@
-<h1>Summary for ros</h1>
+<?php
+$category = 'ROS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 1
resources/views/app/patient/segment-templates/subjective_general/edit.php

@@ -1 +1,4 @@
-<h1>Edit for subjective_general</h1>
+<?php
+$category = 'SUBJECTIVE_GENERAL';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 1
resources/views/app/patient/segment-templates/subjective_general/summary.php

@@ -1 +1,3 @@
-<h1>Summary for subjective_general</h1>
+<?php
+$category = 'SUBJECTIVE_GENERAL';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');