|
@@ -16,6 +16,7 @@ use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Support\Facades\Response;
|
|
|
+use App\Http\Services\SurveyService;
|
|
|
|
|
|
class GuestController extends Controller
|
|
|
{
|
|
@@ -118,20 +119,17 @@ class GuestController extends Controller
|
|
|
|
|
|
if(!$entity) abort(404);
|
|
|
$layout = 'app.patient.surveys.partials.form-layout';
|
|
|
- return view('app.patient.surveys.forms.'.$survey->internal_name, compact('entity', 'survey', 'layout'));
|
|
|
+ return view('app.patient.surveys.forms.form', compact('entity', 'survey', 'layout'));
|
|
|
}
|
|
|
|
|
|
public function viewSurveyFormSubmit(Request $request, $accessKey){
|
|
|
$survey = Survey::where('access_key', $accessKey)->where('is_accessible_to_target', true)->where('is_active', true)->first();
|
|
|
if(!$survey) abort(404);
|
|
|
|
|
|
- $data = $request->all();
|
|
|
- unset($data['_token']);
|
|
|
-
|
|
|
$formData = [
|
|
|
'uid' => $survey->uid,
|
|
|
- 'surveyDataJson' => json_encode($data),
|
|
|
- 'surveyHTML' => (string) $this->viewSurveyFormPreview($request, $survey->uid),
|
|
|
+ 'surveyDataJson' => $request->get('data'),
|
|
|
+ 'surveyHTML' => $survey->surveyhtml,
|
|
|
];
|
|
|
$url = '/survey/submitData';
|
|
|
$response = $this->calljava($request, $url, $formData);
|
|
@@ -144,44 +142,21 @@ class GuestController extends Controller
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function viewSurveyFormPreview(Request $request, $uid){
|
|
|
- $survey = Survey::where('uid', $uid)->first();
|
|
|
- if(!$survey) return null;
|
|
|
-
|
|
|
- $surveyFormPath = resource_path(Survey::FORM_PATH . '/' . $survey->internal_name . '.blade.php');
|
|
|
- if(!file_exists($surveyFormPath)) return null;
|
|
|
-
|
|
|
- $entity = null;
|
|
|
- if($survey->entity_type === 'Client'){
|
|
|
- $entity = Client::where('uid', $survey->entity_uid)->first();
|
|
|
- }
|
|
|
-
|
|
|
- if(!$entity) return null;
|
|
|
- $preview = true;
|
|
|
- $layout = 'app.patient.surveys.partials.preview-layout';
|
|
|
- $html = (string) view('app.patient.surveys.forms.'.$survey->internal_name, compact('entity', 'survey', 'preview', 'layout'));
|
|
|
- return $html;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
public function surveyTemplatePreview(Request $request, $internalName){
|
|
|
-
|
|
|
- $surveyFormPath = resource_path(Survey::FORM_PATH . '/' . $internalName . '.blade.php');
|
|
|
- if(!file_exists($surveyFormPath)) return null;
|
|
|
+ $surveyService = new SurveyService($internalName);
|
|
|
+ $defaultHtml = $surveyService->defaultHTML;
|
|
|
+ if(!$defaultHtml) return 'No default HTML template found for ' . $internalName;
|
|
|
|
|
|
$entityType = $request->get('entityType');
|
|
|
$entityUid = $request->get('entityUid');
|
|
|
- $entity = null;
|
|
|
- if($entityType === 'Client'){
|
|
|
- $entity = Client::where('uid', $entityUid)->first();
|
|
|
- }
|
|
|
|
|
|
- if(!$entity) return null;
|
|
|
+ $initializedData = $surveyService->getInitializedData($entityType, $entityUid);
|
|
|
+
|
|
|
+ $survey = new Survey;
|
|
|
+ $survey->surveyhtml = $defaultHtml;
|
|
|
+ $survey->survey_data = json_encode($initializedData);
|
|
|
|
|
|
- $preview = true;
|
|
|
- $layout = 'app.patient.surveys.partials.preview-layout';
|
|
|
- $html = (string) view('app.patient.surveys.forms.'.$internalName, compact('entity', 'preview', 'layout'));
|
|
|
- return $html;
|
|
|
+ return $survey;
|
|
|
|
|
|
}
|
|
|
}
|