SurveyService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Services;
  3. use Illuminate\Support\Facades\Http;
  4. use Illuminate\Support\Facades\View;
  5. use App\Models\Survey;
  6. use App\Models\Client;
  7. class SurveyService
  8. {
  9. public $internalName;
  10. public $defaultHTML;
  11. public function __construct($internalName)
  12. {
  13. $this->internalName = $internalName;
  14. $surveyFormPath = resource_path(Survey::FORM_PATH . '/' . $this->internalName . '.blade.php');
  15. if(file_exists($surveyFormPath)){
  16. $this->defaultHTML = (string) view('app.patient.surveys.forms.templates.'.$this->internalName);
  17. }
  18. }
  19. public function getInitializedData($entityType, $entityUid){
  20. if($this->internalName === 'sleep'){
  21. if($entityType === 'Client'){
  22. $client = Client::where('uid', $entityUid)->first();
  23. if($client){
  24. return [
  25. 'nameFirst' => $client->name_first,
  26. 'nameMiddle' => $client->name_middle,
  27. 'nameLast' => $client->name_last,
  28. 'description' => null
  29. ];
  30. }
  31. }
  32. }
  33. return null;
  34. }
  35. }