repository = $patient; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Liteerp\Patient\Repositories\Criteria\PatientResourceCriteria::class); } /** * Display a list of patient. * * @return Response */ public function index(PatientRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Liteerp\Patient\Repositories\Presenter\PatientPresenter::class) ->$function(); } $patients = $this->repository->paginate(); return $this->response->title(trans('patient::patient.names')) ->view('patient::patient.index', true) ->data(compact('patients')) ->output(); } /** * Display patient. * * @param Request $request * @param Model $patient * * @return Response */ public function show(PatientRequest $request, Patient $patient) { if ($patient->exists) { $view = 'patient::patient.show'; } else { $view = 'patient::patient.new'; } return $this->response->title(trans('app.view') . ' ' . trans('patient::patient.name')) ->data(compact('patient')) ->view($view, true) ->output(); } /** * Show the form for creating a new patient. * * @param Request $request * * @return Response */ public function create(PatientRequest $request) { $patient = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('patient::patient.name')) ->view('patient::patient.create', true) ->data(compact('patient')) ->output(); } /** * Create new patient. * * @param Request $request * * @return Response */ public function store(PatientRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $patient = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('patient::patient.name')])) ->code(204) ->status('success') ->url(guard_url('patient/patient/' . $patient->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/patient/patient')) ->redirect(); } } /** * Show patient for editing. * * @param Request $request * @param Model $patient * * @return Response */ public function edit(PatientRequest $request, Patient $patient) { return $this->response->title(trans('app.edit') . ' ' . trans('patient::patient.name')) ->view('patient::patient.edit', true) ->data(compact('patient')) ->output(); } /** * Update the patient. * * @param Request $request * @param Model $patient * * @return Response */ public function update(PatientRequest $request, Patient $patient) { try { $attributes = $request->all(); $patient->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('patient::patient.name')])) ->code(204) ->status('success') ->url(guard_url('patient/patient/' . $patient->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('patient/patient/' . $patient->getRouteKey())) ->redirect(); } } /** * Remove the patient. * * @param Model $patient * * @return Response */ public function destroy(PatientRequest $request, Patient $patient) { try { $patient->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('patient::patient.name')])) ->code(202) ->status('success') ->url(guard_url('patient/patient/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('patient/patient/' . $patient->getRouteKey())) ->redirect(); } } /** * Remove multiple patient. * * @param Model $patient * * @return Response */ public function delete(PatientRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('patient::patient.name')])) ->status("success") ->code(202) ->url(guard_url('patient/patient')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/patient/patient')) ->redirect(); } } /** * Restore deleted patients. * * @param Model $patient * * @return Response */ public function restore(PatientRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('patient::patient.name')])) ->status("success") ->code(202) ->url(guard_url('/patient/patient')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/patient/patient/')) ->redirect(); } } }