Browse Source

added template notes

Josh Kamau 5 years ago
parent
commit
d83461af15

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

@@ -0,0 +1,112 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Http;
+use App\HttpModels\ClientLobbyModel;
+use App\HttpModels\MeetingModel;
+use App\Models\AppSession;
+use Cookie;
+
+use App\Models\Note;
+use App\Models\Client;
+use App\Models\Section;
+use App\Models\SectionTemplate;
+
+class NoteController extends Controller
+{
+
+    public function renderNote($noteUid, Request $request)
+    {
+
+        $note = Note::where('uid', $noteUid)->first();
+        $client = Client::where('id', $note->client_id)->first();
+
+        return view('client/note', compact('note', 'client'));
+    }
+
+    public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
+    {
+        $note = Note::where('uid', $note_uid)->first();
+        $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
+        $section = null; // convenience
+        include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
+    }
+
+    public function sectionUpdateForm($section_uid, Request $request)
+    {
+        $section = Section::where('uid', $section_uid)->first();
+        $note = Note::where('id', $section->note_id)->first();
+        $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
+        include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
+    }
+
+    public function processFormSubmit(Request $request)
+    {
+        // for CREATE
+        $note_uid =  $request->note_uid;
+        $section_template_uid =  $request->section_template_uid;
+        
+        // for UPDATE
+        $section_uid =  $request->section_uid;
+
+        $section = $section_uid ? Section::where('uid', $section_uid)->first() : null;
+        $note = null;
+        $sectionTemplate = null;
+        
+        if($section == null){
+            $note = Note::where('uid', $note_uid)->first();
+            $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
+        } else {
+            $note = Note::where('id', $section->note_id)->first();
+            $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
+        }
+
+        $newContentData = [];
+        
+        // we wish to pass THESE arguments into this include: 
+        // if CREATE, $note and $sectionTemplate, and $request
+        // if UPDATE, $section, and $request
+        include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
+
+        // now, create summaryHtml appropriate
+        ob_start();
+        include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
+        $newSummaryHtml = ob_get_contents();
+        ob_end_clean();
+
+        if($section){
+            // call Java to update section
+            $data = [
+                'uid' => $section->uid,
+                'contentData' => json_encode($newContentData),
+                'summaryHtml' => $newSummaryHtml
+            ];
+            $response = $this->calljava($request, '/section/update', $data);
+            //TODO: handle if response->success == false
+        }else{
+            // call Java to create section
+            $data = [
+                'noteUid' => $note->uid,
+                'sectionTemplateUid' => $sectionTemplate->uid,
+                'contentData' => json_encode($newContentData),
+                'summaryHtml' => $newSummaryHtml
+            ];
+
+            $response = $this->callJava($request, '/section/create', $data);
+            dd($response);
+            //TODO: handle if response->success == false
+        }
+        return redirect(route('patients.view.notes',$note->client->uid));
+    }
+
+    private function callJava($request, $endPoint, $data){
+        $url = env('BACKEND_URL', 'http://localhost:8080') . $endPoint;
+        $response = Http::asForm()
+        ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
+        ->post($url, $data)
+        ->json();
+        return $response;
+    }
+}

+ 3 - 1
app/Http/Controllers/PatientController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 
 use App\Models\Client;
 use App\Models\Client;
 use App\Models\Pro;
 use App\Models\Pro;
+use App\Models\SectionTemplate;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 
 
 class PatientController extends Controller
 class PatientController extends Controller
@@ -63,7 +64,8 @@ class PatientController extends Controller
     public function notes(Request $request, Client $patient )
     public function notes(Request $request, Client $patient )
     {
     {
         $pros = Pro::all();
         $pros = Pro::all();
-        return view('app.patient.notes', compact('patient','pros'));
+        $sectionTemplates = SectionTemplate::all();
+        return view('app.patient.notes', compact('patient','pros', 'sectionTemplates'));
     }
     }
 
 
     public function flowSheets(Request $request, Client $patient )
     public function flowSheets(Request $request, Client $patient )

+ 1 - 1
app/Http/Middleware/VerifyCsrfToken.php

@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
      * @var array
      * @var array
      */
      */
     protected $except = [
     protected $except = [
-        //
+        "/process_form_submit"
     ];
     ];
 }
 }

+ 20 - 8
app/Models/Note.php

@@ -6,18 +6,30 @@ namespace App\Models;
 
 
 class Note extends Model
 class Note extends Model
 {
 {
-   protected $table = "note";
+    protected $table = "note";
 
 
-    public function hcpPro(){
-        return $this->hasOne(Pro::class,'id', 'hcp_pro_id');
+    public function client()
+    {
+        return $this->hasOne(Client::class, 'id', 'client_id');
     }
     }
 
 
-    public function allyPro(){
-        return $this->hasOne(Pro::class,'id', 'ally_pro_id');
+    public function hcpPro()
+    {
+        return $this->hasOne(Pro::class, 'id', 'hcp_pro_id');
     }
     }
 
 
-   public function bills(){
-       return $this->hasMany(Bill::class, 'note_id', 'id');
-   }
+    public function allyPro()
+    {
+        return $this->hasOne(Pro::class, 'id', 'ally_pro_id');
+    }
+
+    public function bills()
+    {
+        return $this->hasMany(Bill::class, 'note_id', 'id');
+    }
 
 
+    public function sections()
+    {
+        return $this->hasMany(Section::class, 'note_id', 'id');
+    }
 }
 }

+ 1 - 1
app/Models/Section.php

@@ -6,5 +6,5 @@ namespace App\Models;
 
 
 class Section extends Model
 class Section extends Model
 {
 {
-    //
+    protected $table = 'section';
 }
 }

+ 1 - 1
app/Models/SectionTemplate.php

@@ -6,5 +6,5 @@ namespace App\Models;
 
 
 class SectionTemplate extends Model
 class SectionTemplate extends Model
 {
 {
-    //
+    protected $table = 'section_template';
 }
 }

+ 12 - 14
resources/views/app/patient/notes.blade.php

@@ -98,21 +98,19 @@
             </div>
             </div>
             <div class="card-body">
             <div class="card-body">
                 <div>
                 <div>
-                    {{$note->free_text_html}}
-                    <div moe>
-                        <a href="" show start><i class="fa fa-edit"></i></a>
-                        <form url="/api/note/putFreeTextHtml">
-                            <input type="hidden" name="uid" value="{{$note->uid}}">
-                            <div class="form-group">
-                                <label for="" class="control-label">Free Text HTML</label>
-                                <textarea cols="30" rows="10" name="freeTextHtml" value="{{$note->free_text_html}}" class="form-control"></textarea>
-                            </div>
-                            <div class="form-group">
-                                <button class="btn btn-primary btn-sm" submit>Submit</button>
-                                <button class="btn btn-danger btn-sm" cancel>Cancel</button>
-                            </div>
-                        </form>
+                    @foreach ($sectionTemplates as $sectionTemplate)
+                        <a href="{{route('section_create_form', [$note->uid, $sectionTemplate->uid])}}" show start>add '{{$sectionTemplate->title}}' section</a> 
+                    @endforeach
+                    @if($note->sections->count())
+                    @foreach ($note->sections as $section)
+                    <div class="mt-2">
+                        <div>
+                            {!! $section->summary_html !!}
+                            <a href="{{route('section_update_form', $section->uid)}}">update section</a> 
+                        </div>
                     </div>
                     </div>
+                    @endforeach
+                    @endif
                     @if($note->bills->count())
                     @if($note->bills->count())
                     <div class="mt-2">
                     <div class="mt-2">
                         <table class="table table-sm tabe-striped">
                         <table class="table table-sm tabe-striped">

+ 74 - 41
resources/views/layouts/patient.blade.php

@@ -270,48 +270,81 @@
                                         <i class="fa fa-plus-circle"></i>
                                         <i class="fa fa-plus-circle"></i>
                                         Note
                                         Note
                                     </a>
                                     </a>
-                                    <form url="/api/note/createUsingFreeTextHtml" right>
+                                    <form url="/api/note/create" right>
                                         <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                                         <input type="hidden" name="clientUid" value="{{$patient->uid}}">
-                                        <div class="form-group">
-                                            <label for="" class="control-label">HCP Pro</label>
-                                            <select name="hcpProUid" class="form-control">
-                                                <option value="">-- select hcp pro --</option>
-                                                @foreach ($pros as $pro)
-                                                    <option
-                                                        value="{{$pro->uid}}">{{$pro->name_display}}</option>
-                                                @endforeach
-                                            </select>
-                                        </div>
-                                        <div class="form-group">
-                                            <label for="" class="control-label">Ally Pro</label>
-                                            <select name="allyProUid" class="form-control">
-                                                <option value="">-- select ally pro --</option>
-                                                @foreach ($pros as $pro)
-                                                    <option
-                                                        value="{{$pro->uid}}">{{$pro->name_display}}</option>
-                                                @endforeach
-                                            </select>
-                                        </div>
-                                        <div class="form-group">
-                                            <label for="" class="control-label text-left">Title</label>
-                                            <input type="text" name="title" class="form-control">
-                                        </div>
-                                        <div class="form-group">
-                                            <label for="" class="control-label text-left">Effective date</label>
-                                            <input type="date" name="effectiveDateEST" class="form-control">
-                                        </div>
-
-                                        <div class="form-group">
-                                            <label for="" class="control-label text-left">Effective time</label>
-                                            <input type="time" name="effectiveTime" class="form-control">
-                                        </div>
-                                        
-                                        <div class="form-group">
-                                            <textarea name="freeTextHtml" id="" cols="30" rows="10" class="form-control"></textarea>
-                                        </div>
-                                        <div class="form-group">
-                                            <button class="btn btn-primary" submit>Submit</button>
-                                            <button class="btn btn-danger" cancel>Cancel</button>
+                                        <div class="row">
+                                            <div class="col-md-6">
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">HCP Pro</label>
+                                                    <select name="hcpProUid" class="form-control">
+                                                        <option value="">-- select hcp pro --</option>
+                                                        @foreach ($pros as $pro)
+                                                            <option
+                                                                value="{{$pro->uid}}">{{$pro->name_display}}</option>
+                                                        @endforeach
+                                                    </select>
+                                                </div>
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">Ally Pro</label>
+                                                    <select name="allyProUid" class="form-control">
+                                                        <option value="">-- select ally pro --</option>
+                                                        @foreach ($pros as $pro)
+                                                            <option
+                                                                value="{{$pro->uid}}">{{$pro->name_display}}</option>
+                                                        @endforeach
+                                                    </select>
+                                                </div>
+                                                <div class="form-group">
+                                                    <label for="" class="control-label text-left">Title</label>
+                                                    <input type="text" name="title" class="form-control">
+                                                </div>
+                                                <div class="form-group">
+                                                    <label for="" class="control-label text-left">Effective date</label>
+                                                    <input type="date" name="effectiveDateEST" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label text-left">Effective time</label>
+                                                    <input type="time" name="effectiveTime" class="form-control">
+                                                </div>
+                                            </div>
+                                            <div class="col-md-6">
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">reason1</label> 
+                                                    <input type="text" name="reason1" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">reason2</label> 
+                                                    <input type="text" name="reason2" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">reason3</label> 
+                                                    <input type="text" name="reason3" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">reason3Plus</label> 
+                                                    <input type="text" name="reason3Plus" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">serviceLocation</label> 
+                                                    <input type="text" name="serviceLocation" class="form-control">
+                                                </div>
+        
+                                                <div class="form-group">
+                                                    <label for="" class="control-label">category</label> 
+                                                    <input type="text" name="category" class="form-control">
+                                                </div>
+                                            </div>
+                                            <div class="col-md-12">
+                                                <div class="form-group">
+                                                    <button class="btn btn-primary" submit>Submit</button>
+                                                    <button class="btn btn-danger" cancel>Cancel</button>
+                                                </div>
+                                            </div>
                                         </div>
                                         </div>
                                     </form>
                                     </form>
                                 </div>
                                 </div>

+ 6 - 0
routes/web.php

@@ -76,4 +76,10 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/pro/meet/{uid?}', 'PracticeManagementController@meet');
     Route::get('/pro/meet/{uid?}', 'PracticeManagementController@meet');
     Route::get('/pro/get-opentok-session-key/{uid}', 'PracticeManagementController@getOpentokSessionKey');
     Route::get('/pro/get-opentok-session-key/{uid}', 'PracticeManagementController@getOpentokSessionKey');
 
 
+    //Notes stuff
+    Route::get('/note/{note_uid}', 'NoteController@renderNote')->name('render-note');
+    Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
+    Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');
+    Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
+
 });
 });

+ 43 - 0
storage/sections/test1/form.blade.php

@@ -0,0 +1,43 @@
+<?php
+$contentData = [
+    'nickname'=>'',
+    'favoriteColor'=>''
+]; 
+if($section){
+    $contentData = json_decode($section->content_data, true);
+}
+?>
+<div id="section_form">
+
+    <div class="card">
+        <div class="card-header">
+            <?php if(!$section):?>
+            <div class="alert alert-info">Create section</div>
+            <?php else: ?>
+            <div class="alert alert-info">Update section</div>
+            <?php endif; ?>
+        </div>
+        <div class="card-body">
+            <form method="POST" up-target="#note-container" action="/process_form_submit" up-history="false">
+                <?php if($section): ?>
+                    <input type="hidden" name="section_uid" value="<?= $section->uid?>">
+                <?php else: ?>
+                    <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">
+                    <label for="">Nickname</label>
+                    <input type="text" class="form-control" name="nickname" value="<?= $contentData['nickname'] ?>" placeholder="nickname">
+                </div>
+                <div class="form-group">
+                    <label for="">Favorite color</label>
+                    <input type="text" class="form-control" name="favoriteColor" value="<?= $contentData['favoriteColor'] ?>" placeholder="Favorite color">
+                </div>
+                <div class="form-group">
+                    <button class="btn btn-primary">Submit</button>
+                </div>
+            </form>
+        </div>
+
+    </div>
+</div>

+ 9 - 0
storage/sections/test1/processor.php

@@ -0,0 +1,9 @@
+<?php 
+
+$nickname = $request->get('nickname');
+$favoriteColor = $request->get('favoriteColor');
+
+$newContentData = [
+    'nickname'=>$nickname,
+    'favoriteColor'=>$favoriteColor
+];

+ 3 - 0
storage/sections/test1/summary.php

@@ -0,0 +1,3 @@
+<div class="p-5" style="background-color:<?= $newContentData['favoriteColor']; ?>; ">
+    <h1><?= $newContentData['nickname']; ?></h1>
+</div>