%PDF- %PDF-
Direktori : /var/www/html/klinisol/klinisol-api/app/Http/Controllers/Api/App/v1/ |
Current File : /var/www/html/klinisol/klinisol-api/app/Http/Controllers/Api/App/v1/PatientController.php |
<?php namespace App\Http\Controllers\Api\App\v1; use App\Http\Controllers\Api\ApiController; use App\Jobs\SendExceptionToSlack; use App\Models\PatientProtocol; use App\Models\Protocol; use App\Services\ESign; use App\Transformers\PatientProtocolTransformer; use App\Transformers\PatientTransformer; use Illuminate\Http\JsonResponse; class PatientController extends ApiController { /** * @var ESign */ private $esignApi; /** * PatientController constructor. * @param ESign $esignApi */ public function __construct(ESign $esignApi) { $this->esignApi = $esignApi; } /** * @return JsonResponse */ public function me() { $patient = auth() ->guard('patient') ->user(); return $this->item($patient, new PatientTransformer()); } /** * @return JsonResponse */ public function getProtocols() { $patient = auth() ->guard('patient') ->user(); return $this->collection($patient->protocols, new PatientProtocolTransformer()); } /** * @param $id * @return JsonResponse */ public function getDocumentPreview($id) { /** @var Protocol $protocol */ $protocol = Protocol::query() ->findOrFail($id); try { $template = $this->esignApi->getTemplate($protocol->template_id); return response()->json([ 'preview' => $template, ]); } catch (\Exception $e) { return response()->json(['message' => 'Can not load template document!'], 400); } } public function startSignProcess($id) { $patient = auth() ->guard('patient') ->user(); /** @var Protocol $protocol */ $protocol = Protocol::query() ->findOrFail($id); /** @var PatientProtocol $model */ $model = PatientProtocol::query() ->where('patient_id', $patient->id) ->where('protocol_id', $id) ->first(); $data = [ 'emailSubject' => 'Please sign the following concern form!', 'status' => 'sent', 'templateId' => $protocol->template_id, 'templateRoles' => [ [ 'email' => $patient->email, 'name' => $patient->fullName(), 'roleName' => 'Patient', ], [ "email" => env('DOCUSIGN_ADMIN_EMAIL'), "name" => env('DOCUSIGN_ADMIN_FULLNAME'), "roleName" => "Admin", ], ], ]; try { $response = $this->esignApi->createEnvelopes($data); $docusign = [ 'envelope_id' => $response->envelopeId, 'status' => $response->status, ]; $model->model()->create($docusign); $model->sent(); return response()->json(['message' => 'ok'], 200); } catch (\Exception $e) { dispatch(new SendExceptionToSlack($e->getMessage())); return response()->json(['message' => 'Can not create envelope!'], 400); } } }