add exclusion diagnosis done

This commit is contained in:
pajri
2022-12-27 15:55:21 +07:00
parent 9400145990
commit 55ae0efc66
10 changed files with 1064 additions and 231 deletions

View File

@@ -5,6 +5,7 @@ namespace Modules\Internal\Http\Controllers\Api;
use App\Exceptions\ImportRowException;
use App\Helpers\Helper;
use App\Models\Corporate;
use App\Models\CorporateService;
use App\Models\Exclusion;
use App\Models\Icd;
use App\Models\ImportLog;
@@ -26,10 +27,11 @@ class DiagnosisExclusionController extends Controller
public function index(Request $request, $corporate_id)
{
$exclusions = Exclusion::query()
->where('corporate_id', $corporate_id)
->with(['exclusionable', 'rules'])
->filter($request->toArray())
->paginate();
->where('corporate_id', $corporate_id)
->where('type', 'diagnosis')
->with(['exclusionable', 'rules'])
->filter($request->toArray())
->paginate();
// return $exclusions;
return Helper::paginateResources(DiagnosisExclusionResource::collection($exclusions));
}
@@ -100,10 +102,10 @@ class DiagnosisExclusionController extends Controller
'file' => 'required|file|mimes:xls,xlsx,csv,txt',
]);
// dd($request->toArray());
$file_name = now()->getPreciseTimestamp(3).'-'.$request->file('file')->getClientOriginalName();
$file_name = now()->getPreciseTimestamp(3) . '-' . $request->file('file')->getClientOriginalName();
$file = $request->file('file')->storeAs('temp', $file_name);
$corporate = Corporate::findOrFail($corporate_id);
// $importLog = $corporate->importLogs()->create([
// 'type' => 'diagnosis-exclusions',
// 'file_path' => $file,
@@ -112,8 +114,8 @@ class DiagnosisExclusionController extends Controller
// ]);
$import = new ImportService();
$import->read(Storage::path('temp/'.$file_name));
$import->write(Storage::disk('public')->path('temp/result-'.$file_name), 'xsls');
$import->read(Storage::path('temp/' . $file_name));
$import->write(Storage::disk('public')->path('temp/result-' . $file_name), 'xsls');
foreach ($import->sheetsIterator() as $sheetIndex => $sheet) {
$doc_headers_indexes = [];
@@ -121,8 +123,8 @@ class DiagnosisExclusionController extends Controller
if ($index == 1) { // First Row Must be Header
foreach ($row->getCells() as $index => $cell) {
$title = $cell->getValue();
$title = preg_replace( "/\r|\n/", " ", $title );
$title = preg_replace('/\xc2\xa0/', " ", $title );
$title = preg_replace("/\r|\n/", " ", $title);
$title = preg_replace('/\xc2\xa0/', " ", $title);
$title = rtrim($title);
$title = ltrim($title);
$doc_headers_indexes[$index] = $title;
@@ -148,12 +150,12 @@ class DiagnosisExclusionController extends Controller
9 => 'keterangan',
10 => 'maternity_waiting'
];
foreach ($row->getCells() as $header_index => $cell) {
if (isset($row_map[$header_index])) {
$value = $cell->getValue();
$value = preg_replace( "/\r|\n/", " ", $value );
$value = preg_replace('/\xc2\xa0/', " ", $value );
$value = preg_replace("/\r|\n/", " ", $value);
$value = preg_replace('/\xc2\xa0/', " ", $value);
$value = rtrim($value);
$value = ltrim($value);
$row_data[$row_map[$header_index]] = $cell->getValue();
@@ -171,7 +173,8 @@ class DiagnosisExclusionController extends Controller
empty($row_data['sp_exclusion']) &&
empty($row_data['pre_exis_exclusion']) &&
empty($row_data['op_de_exclusion']) &&
empty($row_data['maternity_waiting'])) {
empty($row_data['maternity_waiting'])
) {
continue;
}
@@ -184,7 +187,6 @@ class DiagnosisExclusionController extends Controller
'Ingest Code' => 200,
'Ingest Note' => 'Success',
]), $sheet->getName());
} catch (ImportRowException $e) {
// Write Data Validation Error to File
$import->addArrayToRow(array_merge($row_data, [
@@ -205,7 +207,7 @@ class DiagnosisExclusionController extends Controller
break; // Only Read First Row
}
$import->reader->close();
Storage::delete('temp/'.$file_name);
Storage::delete('temp/' . $file_name);
$import->writer->close();
return [
@@ -213,9 +215,102 @@ class DiagnosisExclusionController extends Controller
// 'total_failed_row' => count($failed_plan_data),
// 'failed_row' => $failed_plan_data,
'result_file' => [
'url' => Storage::disk('public')->url('temp/result-'.$file_name),
'name' => 'result-'.$file_name,
'url' => Storage::disk('public')->url('temp/result-' . $file_name),
'name' => 'result-' . $file_name,
]
];
}
public function storeExclusion(Request $request, $corporate_id)
{
$exclusion = Exclusion::where('corporate_id', $corporate_id)
->where('id', $request->icd_id)
->where('type', 'diagnosis')
->first();
if ($request->type == "one_row") {
$data = $request->one_row;
foreach ($data['msc'] as $key => $value) {
if ($key == 'm' && $value == "1") {
$msc[] = $key;
} elseif ($key == 's' && $value == "1") {
$msc[] = $key;
} elseif ($key == 'c' && $value == "1") {
$msc[] = $key;
} else {
$msc[] = "";
}
}
$msc = implode(",", $msc);
$msc = trim($msc, ",");
$msc = str_replace(",,", ",", $msc);
foreach ($data['gender'] as $key => $value) {
if ($key == 'male' && $value == "1") {
$gender[] = $key;
} elseif ($key == 'female' && $value == "1") {
$gender[] = $key;
} else {
$gender[] = "";
}
}
$gender = implode(",", $gender);
$gender = trim($gender, ",");
$exclusion->rules()->updateOrCreate([
'exclusion_id' => $exclusion->id,
'name' => 'msc',
], [
'name' => 'msc',
'values' => $msc ?? '',
]);
$exclusion->rules()->updateOrCreate([
'exclusion_id' => $exclusion->id,
'name' => 'gender',
], [
'name' => 'gender',
'values' => $gender ?? '',
]);
$exclusion->rules()->updateOrCreate([
'exclusion_id' => $exclusion->id,
'name' => 'min_age',
], [
'name' => 'min_age',
'values' => $data['min_age'] ?? '',
]);
$exclusion->rules()->updateOrCreate([
'exclusion_id' => $exclusion->id,
'name' => 'max_age',
], [
'name' => 'max_age',
'values' => $data['max_age'] ?? '',
]);
$exclusion->rules()->updateOrCreate([
'exclusion_id' => $exclusion->id,
'name' => 'plan',
], [
'name' => 'plan',
'values' => $data['plan'] ?? '',
]);
}
$exclusions = Exclusion::query()
->where('corporate_id', $corporate_id)
->where('type', 'diagnosis')
->with(['exclusionable', 'rules'])
->filter($request->toArray())
->paginate();
// return $exclusions;
return Helper::paginateResources(DiagnosisExclusionResource::collection($exclusions));
}
}