wip
This commit is contained in:
parent
a1d063b0dd
commit
16307a4c19
@ -32,8 +32,11 @@ public function save(StudyHistoryRequest $request)
|
|||||||
abort_unless(auth()->user()->can(Permission::StudyHistoryEdit) || auth()->user()->isAdmin(), 403);
|
abort_unless(auth()->user()->can(Permission::StudyHistoryEdit) || auth()->user()->isAdmin(), 403);
|
||||||
$this->decodeKeys();
|
$this->decodeKeys();
|
||||||
$details = StudyDetails::historyOnly($this->key);
|
$details = StudyDetails::historyOnly($this->key);
|
||||||
$details->update($request->validated());
|
$payload = array_trim_strings($request->validated());
|
||||||
|
unset($payload['study_id']);
|
||||||
|
$details->update($payload);
|
||||||
|
|
||||||
return redirect()->route('staff.history.view', _h($this->key));
|
// return redirect()->route('staff.history.view', _h($this->key));
|
||||||
|
return redirect()->route('staff.history.view', $details->hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Study;
|
||||||
|
use App\Rules\ExistsByHash;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class StudyHistoryRequest extends FormRequest
|
class StudyHistoryRequest extends FormRequest
|
||||||
@ -9,7 +11,7 @@ class StudyHistoryRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'study_id' => ['required', 'exists:studies'],
|
'study_id' => ['required', new ExistsByHash(Study::class)],
|
||||||
'clinical_history' => ['nullable'],
|
'clinical_history' => ['nullable'],
|
||||||
'surgical_history' => ['nullable'],
|
'surgical_history' => ['nullable'],
|
||||||
'lab_results' => ['nullable'],
|
'lab_results' => ['nullable'],
|
||||||
|
@ -30,11 +30,11 @@ protected function casts(): array
|
|||||||
|
|
||||||
public static function historyOnly(int $studyId): self
|
public static function historyOnly(int $studyId): self
|
||||||
{
|
{
|
||||||
return self::where('study_id', $studyId)->first(['id', 'study_id', 'clinical_history', 'surgical_history', 'lab_results', 'clinical_diagnosis']);
|
return self::where('study_id', $studyId)->firstOrFail(['id', 'study_id', 'clinical_history', 'surgical_history', 'lab_results', 'clinical_diagnosis']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function seriesOnly(int $studyId): self
|
public static function seriesOnly(int $studyId): self
|
||||||
{
|
{
|
||||||
return self::where('study_id', $studyId)->first(['id', 'study_id', 'series']);
|
return self::where('study_id', $studyId)->firstOrFail(['id', 'study_id', 'series']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@ public static function idToHash(int $key): string
|
|||||||
return _h($key);
|
return _h($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function hashToId(string $hash): int
|
||||||
|
{
|
||||||
|
return unhash_it($hash);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get HashId column name.
|
* Get HashId column name.
|
||||||
*/
|
*/
|
||||||
|
@ -25,16 +25,16 @@ public function __construct(string $class)
|
|||||||
{
|
{
|
||||||
$this->model = new $class;
|
$this->model = new $class;
|
||||||
|
|
||||||
if (! method_exists($this->model, 'bootHashableId')) {
|
if (! method_exists($this->model, 'getHashAttribute')) {
|
||||||
throw new InvalidArgumentException('Class does not use HashableId');
|
throw new InvalidArgumentException('Class does not use HashableId');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($class, $this->model->shouldHashPersist() ? $this->model->getHashColumnName() : $this->model->getKeyName());
|
parent::__construct($class, $this->model->getKeyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||||
{
|
{
|
||||||
if (! $value || (! $this->model->shouldHashPersist() && ! $value = $this->model::hashToId($value))) {
|
if (! $value || (! $value = $this->model::hashToId($value))) {
|
||||||
$this->fail($attribute, $fail);
|
$this->fail($attribute, $fail);
|
||||||
|
|
||||||
return;
|
return;
|
@ -31,6 +31,20 @@ function array_purge(array $ary): array
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('array_trim_strings')) {
|
||||||
|
function array_trim_strings(array $ary): array
|
||||||
|
{
|
||||||
|
return array_filter($ary, function ($v) {
|
||||||
|
if (! is_string($v)) {
|
||||||
|
return $v;
|
||||||
|
}
|
||||||
|
$v = trim($v);
|
||||||
|
|
||||||
|
return blank($v) ? null : $v;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! function_exists('sync_agent_id')) {
|
if (! function_exists('sync_agent_id')) {
|
||||||
function sync_agent_id(): int
|
function sync_agent_id(): int
|
||||||
{
|
{
|
||||||
|
@ -11,40 +11,34 @@
|
|||||||
<div class="mt-10 sm:mt-0">
|
<div class="mt-10 sm:mt-0">
|
||||||
<h4>Clinical Information</h4>
|
<h4>Clinical Information</h4>
|
||||||
|
|
||||||
@dd($details)
|
<form action="{{ route('staff.history.save', $details->hash) }}" method="post">
|
||||||
|
|
||||||
<form action="{{ route('staff.history.save', _h($details->study_id)) }}" method="post">
|
|
||||||
@csrf
|
@csrf
|
||||||
<input type="hidden" name="study_id" value="{{ $details->study_id }}">
|
<input type="hidden" name="study_id" value="{{ $details->hash }}">
|
||||||
<h5>Clinical History</h5>
|
<h5>Clinical History</h5>
|
||||||
<div class="p-4 border-gray-100">
|
<div class="p-4 border-gray-100">
|
||||||
<textarea name="clinical_history" id="clinical_history" cols="30" rows="10"
|
<textarea name="clinical_history" id="clinical_history" cols="90"
|
||||||
value="{!! $details->clinical_history !!}">
|
rows="10">{!! $details->clinical_history !!}</textarea>
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
<x-section-border/>
|
<x-section-border/>
|
||||||
|
|
||||||
<h5>surgical history</h5>
|
<h5>surgical history</h5>
|
||||||
<div class="p-4 border-gray-100">
|
<div class="p-4 border-gray-100">
|
||||||
<textarea name="surgical_history" id="surgical_history" cols="30" rows="10"
|
<textarea name="surgical_history" id="surgical_history" cols="90"
|
||||||
value="{!! $details->surgical_history !!}">
|
rows="10">{!! $details->surgical_history !!}</textarea>
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
<x-section-border/>
|
<x-section-border/>
|
||||||
|
|
||||||
<h5>lab results</h5>
|
<h5>lab results</h5>
|
||||||
<div class="p-4 border-gray-100">
|
<div class="p-4 border-gray-100">
|
||||||
<textarea name="lab_results" id="lab_results" cols="30" rows="10"
|
<textarea name="lab_results" id="lab_results" cols="90"
|
||||||
value="{!! $details->lab_results !!}">
|
rows="10">{!! $details->lab_results !!}</textarea>
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
<x-section-border/>
|
<x-section-border/>
|
||||||
|
|
||||||
<h5>clinical diagnosis</h5>
|
<h5>clinical diagnosis</h5>
|
||||||
<div class="p-4 border-gray-100">
|
<div class="p-4 border-gray-100">
|
||||||
<textarea name="clinical_diagnosis" id="clinical_diagnosis" cols="30" rows="10"
|
<textarea name="clinical_diagnosis" id="clinical_diagnosis" cols="90"
|
||||||
value="{!! $details->clinical_diagnosis !!}">
|
rows="10">{!! $details->clinical_diagnosis !!}</textarea>
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
<button type="submit">Save</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user