|
@@ -14,7 +14,8 @@ use App\Models\SectionTemplate;
|
|
|
|
|
|
class NoteController extends Controller
|
|
|
{
|
|
|
- public function dashboard(Request $request, Client $patient, Note $note )
|
|
|
+
|
|
|
+ public function dashboard(Request $request, Client $patient, Note $note)
|
|
|
{
|
|
|
$pros = Pro::all();
|
|
|
$noteSections = $note->sections;
|
|
@@ -22,7 +23,7 @@ class NoteController extends Controller
|
|
|
foreach ($allSections as $section) {
|
|
|
$section->used = false;
|
|
|
foreach ($noteSections as $noteSection) {
|
|
|
- if($noteSection->sectionTemplate->id === $section->id) {
|
|
|
+ if ($noteSection->sectionTemplate->id === $section->id) {
|
|
|
$section->used = true;
|
|
|
$section->section_uid = $noteSection->uid;
|
|
|
break;
|
|
@@ -41,136 +42,86 @@ class NoteController extends Controller
|
|
|
return view('client/note', compact('note', 'client'));
|
|
|
}
|
|
|
|
|
|
- public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
|
|
|
+ // JAVA ONLY
|
|
|
+ public function getDefaultValueForSection($patientID, $sectionTemplateID)
|
|
|
{
|
|
|
- $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'));
|
|
|
+ $contentData = [];
|
|
|
+ $summaryHtml = '';
|
|
|
+ $patient = Client::where('id', $patientID)->first();
|
|
|
+ $sectionTemplate = SectionTemplate::where('id', $sectionTemplateID)->first();
|
|
|
+
|
|
|
+ if (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) {
|
|
|
+ // default should simply assign to $contentData and $summaryHtml as needed
|
|
|
+ include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'));
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'contentData' => $contentData,
|
|
|
+ 'summaryHtml' => $summaryHtml
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- public function sectionUpdateForm($section_uid, Request $request)
|
|
|
+ public function processFormSubmit(Request $request)
|
|
|
{
|
|
|
+ // TODO require
|
|
|
+ $section_uid = $request->get('section_uid');
|
|
|
+
|
|
|
$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 getDefaultValueForSection($section, $patient_uid) {
|
|
|
- $defaultData = [
|
|
|
- "summary" => "",
|
|
|
- "value" => ""
|
|
|
- ];
|
|
|
- $patient = Client::where('uid', $patient_uid)->first();
|
|
|
- if(file_exists(storage_path('sections/' . $section . '/default.php'))) {
|
|
|
- include(storage_path('sections/' . $section . '/default.php'));
|
|
|
- }
|
|
|
- return json_encode($defaultData);
|
|
|
- }
|
|
|
-
|
|
|
- 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 CREATE
|
|
|
- if($section == null){
|
|
|
- // TODO require valid note_uid & section_template_uid
|
|
|
- $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();
|
|
|
- }
|
|
|
|
|
|
- // our intention is to now process a submit...
|
|
|
- // ... the point of which is to have newContentData and newSummaryHtml
|
|
|
$newContentData = [];
|
|
|
$newSummaryHtml = "";
|
|
|
|
|
|
- // we wish to pass THESE arguments into this include:
|
|
|
- // if CREATE, $note and $sectionTemplate, and $request
|
|
|
- // if UPDATE, $section, and $request
|
|
|
-
|
|
|
- // remember: the existence of form.php overrides section_template.is_canvas == TRUE
|
|
|
+ $sectionInternalName = $sectionTemplate->internal_name;
|
|
|
+ if ($sectionTemplate->is_canvas) {
|
|
|
|
|
|
- if($sectionTemplate->is_canvas){
|
|
|
- if(file_exists()){
|
|
|
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
|
|
|
- }else{
|
|
|
+ if (file_exists("app.patient.canvas-sections.{$sectionInternalName}.processor")) {
|
|
|
+ include("app.patient.canvas-sections.{$sectionInternalName}.processor");
|
|
|
+ } else {
|
|
|
$newContentData = json_decode($request->get('data'), true);
|
|
|
}
|
|
|
ob_start();
|
|
|
- // TODO include the resource_path
|
|
|
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
|
|
|
+ include("app.patient.canvas-sections.{$sectionInternalName}.summary");
|
|
|
$newSummaryHtml = ob_get_contents();
|
|
|
ob_end_clean();
|
|
|
- }elseif(file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) {
|
|
|
+ } elseif (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) {
|
|
|
|
|
|
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();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
+
|
|
|
$newContentData = json_decode($request->get('data'), true);
|
|
|
- if(isset($newContentData['value'])){
|
|
|
+ if (isset($newContentData['value'])) {
|
|
|
$newSummaryHtml = $newContentData['value'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$response = null;
|
|
|
- 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
|
|
|
- // if default.php, run it to hydrate $newContentData and $newSummaryHtml
|
|
|
-
|
|
|
- if(file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) {
|
|
|
- include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'));
|
|
|
- }
|
|
|
-
|
|
|
- $data = [
|
|
|
- 'noteUid' => $note->uid,
|
|
|
- 'sectionTemplateUid' => $sectionTemplate->uid,
|
|
|
- 'contentData' => json_encode($newContentData),
|
|
|
- 'summaryHtml' => $newSummaryHtml
|
|
|
- ];
|
|
|
-
|
|
|
- $response = $this->callJava($request, '/section/create', $data);
|
|
|
- //TODO: handle if response->success == false
|
|
|
- }
|
|
|
- return redirect(route('patients.view.notes',$note->client->uid));
|
|
|
- return [
|
|
|
- 'success' => $response->success,
|
|
|
- 'newSummaryHtml' => $newSummaryHtml
|
|
|
- ];
|
|
|
+ $data = [
|
|
|
+ 'uid' => $section->uid,
|
|
|
+ 'contentData' => json_encode($newContentData),
|
|
|
+ 'summaryHtml' => $newSummaryHtml
|
|
|
+ ];
|
|
|
+ $response = $this->calljava($request, '/section/update', $data);
|
|
|
+ return [
|
|
|
+ 'success' => $response['success'],
|
|
|
+ 'newSummaryHtml' => $newSummaryHtml
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- private function callJava($request, $endPoint, $data){
|
|
|
+ // TODO move to utility
|
|
|
+ private function callJava($request, $endPoint, $data)
|
|
|
+ {
|
|
|
$url = config('stag.backendUrl') . $endPoint;
|
|
|
$response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
- ->post($url, $data)
|
|
|
- ->json();
|
|
|
+ ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
|
|
|
+ ->post($url, $data)
|
|
|
+ ->json();
|
|
|
return $response;
|
|
|
}
|
|
|
+
|
|
|
}
|