update
This commit is contained in:
@@ -20,14 +20,13 @@ class BiorepositoryController extends Controller
|
||||
|
||||
$data = [];
|
||||
$data['cabinetOptions'] = BioCabinet::orderBy('name', 'ASC')->get();
|
||||
$data['rackOptions'] = BioRack::with('cabinet')->orderBy('name', 'ASC')->get();
|
||||
$data['totalCabinets'] = BioCabinet::count();
|
||||
$data['totalRacks'] = BioRack::count();
|
||||
$data['totalSpecimens'] = BioSpecimen::count();
|
||||
|
||||
$data['cabinets'] = BioCabinet::with([
|
||||
'racks' => function ($query) {
|
||||
$query->orderBy('level', 'ASC')->orderBy('name', 'ASC');
|
||||
$query->orderBy('level', 'ASC')->orderBy('rack_number', 'ASC');
|
||||
},
|
||||
'racks.specimens' => function ($query) {
|
||||
$query->orderBy('stored_at', 'ASC');
|
||||
@@ -77,7 +76,9 @@ class BiorepositoryController extends Controller
|
||||
'code' => 'required|max:50',
|
||||
'name' => 'required|max:150',
|
||||
'level' => 'required|integer|min:1',
|
||||
'capacity' => 'nullable|integer|min:0',
|
||||
'rack_number' => 'required|integer|min:1',
|
||||
'box_number' => 'required|integer|min:1',
|
||||
'capacity' => 'required|integer|min:1',
|
||||
'notes' => 'nullable',
|
||||
]);
|
||||
|
||||
@@ -98,7 +99,9 @@ class BiorepositoryController extends Controller
|
||||
'code' => $request->input('code'),
|
||||
'name' => $request->input('name'),
|
||||
'level' => $request->input('level'),
|
||||
'capacity' => $request->input('capacity') ?? 0,
|
||||
'rack_number' => $request->input('rack_number'),
|
||||
'box_number' => $request->input('box_number'),
|
||||
'capacity' => $request->input('capacity'),
|
||||
'notes' => $request->input('notes'),
|
||||
]);
|
||||
|
||||
@@ -109,14 +112,15 @@ class BiorepositoryController extends Controller
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'rack_id' => 'required|exists:bio_racks,id',
|
||||
'specimen_code' => 'required|max:100|unique:bio_specimens,specimen_code',
|
||||
'specimen_name' => 'required|max:200',
|
||||
'patient_name' => 'nullable|max:200',
|
||||
'collected_at' => 'nullable|date',
|
||||
'kategorisimpan' => 'required|in:A,B,C,D',
|
||||
'shelfnomor' => 'required|integer|min:1',
|
||||
'raknomor' => 'required|integer|min:1',
|
||||
'slotnomor' => 'required|integer|min:1',
|
||||
'boxnomor' => 'required|integer|min:1',
|
||||
'tubenomor' => 'required|integer|min:1',
|
||||
'nmbakteri' => 'required|max:200',
|
||||
'strain' => 'required|in:Gram Negatif,Gram Positif',
|
||||
'stored_at' => 'required|date',
|
||||
'volume' => 'nullable|max:50',
|
||||
'storage_condition' => 'nullable|max:100',
|
||||
'notes' => 'nullable',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -124,20 +128,80 @@ class BiorepositoryController extends Controller
|
||||
}
|
||||
|
||||
$rack = BioRack::find($request->input('rack_id'));
|
||||
$expectedRackNo = $rack->rack_number ?: $rack->id;
|
||||
$expectedBoxNo = $rack->box_number ?: 1;
|
||||
|
||||
if ((int) $request->input('shelfnomor') !== (int) $rack->level ||
|
||||
(int) $request->input('raknomor') !== (int) $expectedRackNo ||
|
||||
(int) $request->input('boxnomor') !== (int) $expectedBoxNo) {
|
||||
return back()->withErrors(['slotnomor' => 'Posisi slot tidak sesuai dengan konfigurasi rack.'])->withInput();
|
||||
}
|
||||
|
||||
if ((int) $request->input('slotnomor') > (int) $rack->capacity) {
|
||||
return back()->withErrors(['slotnomor' => 'Slot melebihi kapasitas rack.'])->withInput();
|
||||
}
|
||||
|
||||
$slotTaken = BioSpecimen::where('rack_id', $rack->id)
|
||||
->where('slot_number', $request->input('slotnomor'))
|
||||
->exists();
|
||||
|
||||
if ($slotTaken) {
|
||||
return back()->withErrors(['slotnomor' => 'Slot ini sudah terisi spesimen.'])->withInput();
|
||||
}
|
||||
|
||||
$atccByUser = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', Session::get('nama', 'UNKNOWN')));
|
||||
if ($atccByUser === '') {
|
||||
$atccByUser = 'UNKNOWN';
|
||||
}
|
||||
|
||||
$generatedCode = implode('-', [
|
||||
$request->input('kategorisimpan'),
|
||||
$request->input('shelfnomor'),
|
||||
$request->input('raknomor'),
|
||||
$request->input('slotnomor'),
|
||||
$request->input('boxnomor'),
|
||||
$atccByUser,
|
||||
]);
|
||||
|
||||
$baseCode = $generatedCode;
|
||||
$counter = 1;
|
||||
while (BioSpecimen::where('specimen_code', $generatedCode)->exists()) {
|
||||
$counter++;
|
||||
$generatedCode = $baseCode.'-'.$counter;
|
||||
}
|
||||
|
||||
BioSpecimen::create([
|
||||
'cabinet_id' => $rack->cabinet_id,
|
||||
'rack_id' => $rack->id,
|
||||
'specimen_code' => $request->input('specimen_code'),
|
||||
'specimen_name' => $request->input('specimen_name'),
|
||||
'patient_name' => $request->input('patient_name'),
|
||||
'collected_at' => $request->input('collected_at'),
|
||||
'specimen_code' => $generatedCode,
|
||||
'specimen_name' => $request->input('nmbakteri'),
|
||||
'category_storage' => $request->input('kategorisimpan'),
|
||||
'shelf_number' => $request->input('shelfnomor'),
|
||||
'rack_number' => $request->input('raknomor'),
|
||||
'slot_number' => $request->input('slotnomor'),
|
||||
'box_number' => $request->input('boxnomor'),
|
||||
'tube_number' => $request->input('tubenomor'),
|
||||
'bacteria_name' => $request->input('nmbakteri'),
|
||||
'strain' => $request->input('strain'),
|
||||
'atcc' => $atccByUser,
|
||||
'input_by' => Session::get('nama'),
|
||||
'stored_at' => $request->input('stored_at'),
|
||||
'volume' => $request->input('volume'),
|
||||
'storage_condition' => $request->input('storage_condition'),
|
||||
'storage_condition' => $this->mapStorageCondition($request->input('kategorisimpan')),
|
||||
'notes' => $request->input('notes'),
|
||||
]);
|
||||
|
||||
return redirect('/biorepository')->with('success', 'Spesimen berhasil ditambahkan.');
|
||||
return redirect('/biorepository')->with('success', 'Spesimen berhasil disimpan ke slot terpilih.');
|
||||
}
|
||||
|
||||
private function mapStorageCondition($category)
|
||||
{
|
||||
$mapping = [
|
||||
'A' => 'Suhu Ruang',
|
||||
'B' => '4 Derajat',
|
||||
'C' => '20 Derajat',
|
||||
'D' => '80 Derajat',
|
||||
];
|
||||
|
||||
return $mapping[$category] ?? 'Tidak Diketahui';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user