From 55ae0efc66f8f00a0460739477aa458551604b30 Mon Sep 17 00:00:00 2001 From: pajri Date: Tue, 27 Dec 2022 15:55:21 +0700 Subject: [PATCH] add exclusion diagnosis done --- .../Controllers/Api/CorporateController.php | 13 +- .../Api/CorporateServiceController.php | 66 +- .../Api/DiagnosisExclusionController.php | 131 ++- Modules/Internal/Routes/api.php | 1 + .../Internal/Services/ExclusionService.php | 68 +- .../CorporateServiceConfigResource.php | 2 +- .../DiagnosisExclusionResource.php | 33 +- .../Corporates/DiagnosisExclusion/Index.tsx | 4 +- .../Corporates/DiagnosisExclusion/List.tsx | 799 ++++++++++++++---- .../src/pages/Corporates/Services/Create.tsx | 178 +++- 10 files changed, 1064 insertions(+), 231 deletions(-) diff --git a/Modules/Internal/Http/Controllers/Api/CorporateController.php b/Modules/Internal/Http/Controllers/Api/CorporateController.php index 044629cf..8dcf6428 100755 --- a/Modules/Internal/Http/Controllers/Api/CorporateController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporateController.php @@ -252,11 +252,22 @@ class CorporateController extends Controller public function show($id) { $corporate = Corporate::query() - ->with(['currentPolicy']) + ->with(['currentPolicy', 'plans']) ->withCount('corporatePlans') ->withCount('employees') // ->withCount('employees.claims') ->findOrFail($id); + $plans = $corporate['plans']->map(function ($plan) { + return [ + 'id' => $plan['id'], + 'code' => $plan['code'], + 'corporate_id' => $plan['corporate_id'], + 'corporate_plan_id' => $plan['corporate_plan_id'], + ]; + }); + + unset($corporate['plans']); + $corporate['plans'] = $plans; return response()->json($corporate); } diff --git a/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php b/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php index 93472ef1..0ff43933 100755 --- a/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php @@ -117,9 +117,7 @@ class CorporateServiceController extends Controller ->where('service_code', $service_code) ->with([ 'configs', 'service', - 'specialities' => function ($speciality) { - $speciality->where('active', true); - }, + 'specialities', 'specialities.speciality', 'specialities.exclusions.rules' ]) @@ -206,16 +204,25 @@ class CorporateServiceController extends Controller ->with('exclusions.rules') ->first(); + if (empty($corporateServiceSpeciality)) { + $corporateServiceSpeciality = CorporateServiceSpeciality::create([ + 'corporate_service_id' => $corporateService->id, + 'speciality_id' => $request->speciality_id, + 'active' => false, + ]); + + $corporateServiceSpeciality->exclusions()->updateOrCreate([ + 'corporate_id' => $corporate_id, + 'service_code' => $service_code, + ], [ + 'corporate_id' => $corporate_id, + 'service_code' => $service_code, + 'type' => 'speciality', + ]); + } + $exclusion = $corporateServiceSpeciality->exclusions()->where('corporate_id', $corporate_id)->where('service_code', $service_code)->first(); - // dd($exclusion); - // ->updateOrCreate([ - // 'corporate_id' => $corporate_id, - // 'service_code' => $service_code, - // ], [ - // 'corporate_id' => $corporate_id, - // 'service_code' => $service_code, - // 'type' => 'speciality', - // ]); + if ($request->type == 'msc') { @@ -372,7 +379,36 @@ class CorporateServiceController extends Controller 'name' => 'plan', ], [ 'name' => 'plan', - 'values' => $plan, + 'values' => $plan ?? '', + ]); + } + + if ($request->type == "one_row") { + $data = $request->one_row; + + $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'] ?? '', ]); } @@ -389,9 +425,7 @@ class CorporateServiceController extends Controller ->where('service_code', $service_code) ->with([ 'configs', 'service', - 'specialities' => function ($speciality) { - $speciality->where('active', true); - }, + 'specialities', 'specialities.speciality', 'specialities.exclusions.rules' ]) diff --git a/Modules/Internal/Http/Controllers/Api/DiagnosisExclusionController.php b/Modules/Internal/Http/Controllers/Api/DiagnosisExclusionController.php index 8c1f690f..1c4897e8 100755 --- a/Modules/Internal/Http/Controllers/Api/DiagnosisExclusionController.php +++ b/Modules/Internal/Http/Controllers/Api/DiagnosisExclusionController.php @@ -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)); + } } diff --git a/Modules/Internal/Routes/api.php b/Modules/Internal/Routes/api.php index 26fb664b..99f427f6 100755 --- a/Modules/Internal/Routes/api.php +++ b/Modules/Internal/Routes/api.php @@ -81,6 +81,7 @@ Route::prefix('internal')->group(function () { Route::get('corporates/{corporate_id}/diagnosis-exclusions', [DiagnosisExclusionController::class, 'index']); + Route::post('corporates/{corporate_id}/diagnosis-exclusions/store', [DiagnosisExclusionController::class, 'storeExclusion']); Route::post('corporates/{corporate_id}/diagnosis-exclusions/import', [DiagnosisExclusionController::class, 'import']); Route::get('corporates/{corporate_id}/services', [CorporateServiceController::class, 'index']); diff --git a/Modules/Internal/Services/ExclusionService.php b/Modules/Internal/Services/ExclusionService.php index 1c166fae..af7e6b62 100755 --- a/Modules/Internal/Services/ExclusionService.php +++ b/Modules/Internal/Services/ExclusionService.php @@ -32,10 +32,10 @@ class ExclusionService 'service_code' => 'OP', 'type' => 'diagnosis' ]); - + if (!empty($excl_array[1])) { //msc $msc = explode(',', $excl_array[1]); - collect($msc)->each(function($m) use ($exclusion) { + collect($msc)->each(function ($m) use ($exclusion) { $exclusion->rules()->create([ 'name' => 'msc', 'values' => $m @@ -44,11 +44,18 @@ class ExclusionService } if (!empty($excl_array[2])) { //genders $genders = explode(',', $excl_array[2]); - collect($genders)->each(function($gender) use ($exclusion) { - $exclusion->rules()->create([ - 'name' => 'gender', - 'values' => $gender - ]); + collect($genders)->each(function ($gender) use ($exclusion) { + if ($gender == 'M') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'male' + ]); + } else if ($gender == 'F') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'female' + ]); + } }); } if (!empty($excl_array[3])) { //min_age @@ -84,10 +91,10 @@ class ExclusionService 'service_code' => 'OP', 'type' => 'diagnosis' ]); - + if (!empty($excl_array[1])) { //msc $msc = explode(',', $excl_array[1]); - collect($msc)->each(function($m) use ($exclusion) { + collect($msc)->each(function ($m) use ($exclusion) { $exclusion->rules()->create([ 'name' => 'msc', 'values' => $m @@ -96,11 +103,18 @@ class ExclusionService } if (!empty($excl_array[2])) { //genders $genders = explode(',', $excl_array[2]); - collect($genders)->each(function($gender) use ($exclusion) { - $exclusion->rules()->create([ - 'name' => 'gender', - 'values' => $gender - ]); + collect($genders)->each(function ($gender) use ($exclusion) { + if ($gender == 'M') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'male' + ]); + } else if ($gender == 'F') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'female' + ]); + } }); } if (!empty($excl_array[3])) { //min_age @@ -133,10 +147,10 @@ class ExclusionService 'service_code' => 'OP', 'type' => 'diagnosis' ]); - + if (!empty($excl_array[1])) { //msc $msc = explode(',', $excl_array[1]); - collect($msc)->each(function($m) use ($exclusion) { + collect($msc)->each(function ($m) use ($exclusion) { $exclusion->rules()->create([ 'name' => 'msc', 'values' => $m @@ -145,11 +159,18 @@ class ExclusionService } if (!empty($excl_array[2])) { //genders $genders = explode(',', $excl_array[2]); - collect($genders)->each(function($gender) use ($exclusion) { - $exclusion->rules()->create([ - 'name' => 'gender', - 'values' => $gender - ]); + collect($genders)->each(function ($gender) use ($exclusion) { + if ($gender == 'M') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'male' + ]); + } else if ($gender == 'F') { + $exclusion->rules()->create([ + 'name' => 'gender', + 'values' => 'female' + ]); + } }); } if (!empty($excl_array[3])) { //min_age @@ -177,7 +198,6 @@ class ExclusionService $excl_array = explode('|', $row['ma_exclusion']); dd($excl_array); if ($excl_array[0]) { - } } @@ -185,7 +205,6 @@ class ExclusionService $excl_array = explode('|', $row['sp_exclusion']); dd($excl_array); if ($excl_array[0]) { - } } @@ -193,7 +212,6 @@ class ExclusionService $excl_array = explode('|', $row['pre_exist_exclusion']); dd($excl_array); if ($excl_array[0]) { - } } @@ -201,7 +219,6 @@ class ExclusionService $excl_array = explode('|', $row['op_de_exclusion']); dd($excl_array); if ($excl_array[0]) { - } } @@ -209,7 +226,6 @@ class ExclusionService $excl_array = explode('|', $row['maternity_waiting']); dd($excl_array); if ($excl_array[0]) { - } } return true; diff --git a/Modules/Internal/Transformers/CorporateServiceConfigResource.php b/Modules/Internal/Transformers/CorporateServiceConfigResource.php index bbfc2100..6e506dbc 100755 --- a/Modules/Internal/Transformers/CorporateServiceConfigResource.php +++ b/Modules/Internal/Transformers/CorporateServiceConfigResource.php @@ -23,7 +23,7 @@ class CorporateServiceConfigResource extends JsonResource 'name' => $this->service->name, 'description' => $this->service->description, 'configurations' => $this->configs->pluck('value', 'name'), - 'selected_specialities' => $this->specialities->pluck('speciality.name', 'speciality_id'), + 'selected_specialities' => $this->specialities->where('active', true)->pluck('speciality.name', 'speciality_id'), 'exclusions' => $this->specialities->map(function ($speciality) { return [ 'speciality_id' => $speciality->speciality_id, diff --git a/Modules/Internal/Transformers/DiagnosisExclusionResource.php b/Modules/Internal/Transformers/DiagnosisExclusionResource.php index 04fd00a9..5ecc8267 100755 --- a/Modules/Internal/Transformers/DiagnosisExclusionResource.php +++ b/Modules/Internal/Transformers/DiagnosisExclusionResource.php @@ -14,7 +14,7 @@ class DiagnosisExclusionResource extends JsonResource */ public function toArray($request) { - return [ + $data = [ 'id' => $this->id, 'code' => $this->exclusionable->code, 'name' => $this->exclusionable->name, @@ -25,5 +25,36 @@ class DiagnosisExclusionResource extends JsonResource return [$item['name'] => $item['values']]; }) ]; + + $msc = explode(',', $this->rules->where('name', 'msc')->first()->values ?? ''); + $list_msc = [ + 'm' => in_array('m', $msc), + 's' => in_array('s', $msc), + 'c' => in_array('c', $msc), + ]; + + $gender = explode(',', $this->rules->where('name', 'gender')->first()->values ?? ''); + $list_gender = [ + 'male' => in_array('male', $gender), + 'female' => in_array('female', $gender), + ]; + + $min_age = $this->rules->where('name', 'min_age')->first()->values ?? ''; + $max_age = $this->rules->where('name', 'max_age')->first()->values ?? ''; + $plan = $this->rules->where('name', 'plan')->first()->values ?? ''; + + $value_plan = [ + 'plan' => $plan, + 'gender' => $list_gender, + 'msc' => $list_msc, + 'min_age' => $min_age, + 'max_age' => $max_age, + ]; + + $data['value_rules'] = $value_plan; + + + + return $data; } } diff --git a/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/Index.tsx b/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/Index.tsx index d022b746..05a3808b 100755 --- a/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/Index.tsx +++ b/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/Index.tsx @@ -15,11 +15,13 @@ export default function Divisions() { const { corporate_id } = useParams(); const [corporate, setCorporate] = useState(); + const [plans, setPlans] = useState([]); const configuredCorporateContext = useContext(ConfiguredCorporateContext); useEffect(() => { setCorporate(configuredCorporateContext.currentCorporate); + setPlans(configuredCorporateContext.currentCorporate?.plans ?? []); }, [configuredCorporateContext]); const pageTitle = 'Diagnosis Exclusion'; @@ -45,7 +47,7 @@ export default function Divisions() { - + ); diff --git a/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/List.tsx b/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/List.tsx index 051d01ad..0fb034cf 100755 --- a/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/List.tsx +++ b/frontend/dashboard/src/pages/Corporates/DiagnosisExclusion/List.tsx @@ -1,5 +1,39 @@ // @mui -import { Box, Button, Card, Collapse, IconButton, InputLabel, MenuItem, OutlinedInput, Paper, Select, SelectChangeEvent, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography, Badge, Tab, Tabs, CardHeader, Stack, Menu, ButtonGroup } from '@mui/material'; +import { + Autocomplete, + Box, + Button, + Card, + Collapse, + IconButton, + MenuItem, + OutlinedInput, + Paper, + Select, + SelectChangeEvent, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + TextField, + Typography, + Badge, + Tab, + Tabs, + CardHeader, + Stack, + Menu, + ButtonGroup, + Dialog, + DialogContent, + DialogTitle, + FormControl, + FormControlLabel, + Checkbox, + Grid, +} from '@mui/material'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'; import AddIcon from '@mui/icons-material/Add'; @@ -16,34 +50,43 @@ import { Icd } from '../../../@types/diagnosis'; import BasePagination from '../../../components/BasePagination'; import { enqueueSnackbar } from 'notistack'; -export default function List() { +export default function List(props: any) { const { themeStretch } = useSettings(); - const { corporate_id } = useParams(); + const { corporate_id, service_code } = useParams(); const [searchParams, setSearchParams] = useSearchParams(); const [importResult, setImportResult] = useState(null); - + function SearchInput(props: any) { - // SEARCH + // SEARCH const searchInput = useRef(null); - const [searchText, setSearchText] = useState(""); + const [searchText, setSearchText] = useState(''); const handleSearchChange = (event: any) => { - const newSearchText = event.target.value ?? '' + const newSearchText = event.target.value ?? ''; setSearchText(newSearchText); - } + }; const handleSearchSubmit = (event: any) => { event.preventDefault(); props.onSearch(searchText); // Trigger to Parent - } + }; - useEffect(() => { // Trigger First Search + useEffect(() => { + // Trigger First Search setSearchText(searchParams.get('search') ?? ''); - }, [searchParams]) + }, [searchParams]); return (
- + ); } @@ -53,8 +96,8 @@ export default function List() { // Create Button Menu const [anchorEl, setAnchorEl] = React.useState(null); const createMenu = Boolean(anchorEl); - const importForm = useRef(null) - const [currentImportFileName, setCurrentImportFileName] = useState(null) + const importForm = useRef(null); + const [currentImportFileName, setCurrentImportFileName] = useState(null); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); @@ -69,52 +112,66 @@ export default function List() { handleClose(); importForm.current ? importForm.current.click() : console.log('No File selected'); } else { - alert('No file selected') + alert('No file selected'); } - } + }; const handleCancelImportButton = () => { - importForm.current.value = ""; - importForm.current.dispatchEvent(new Event("change", { bubbles: true })); - } + importForm.current.value = ''; + importForm.current.dispatchEvent(new Event('change', { bubbles: true })); + }; const handleImportChange = (event: any) => { if (event.target.files[0]) { - setCurrentImportFileName(event.target.files[0].name) + setCurrentImportFileName(event.target.files[0].name); } else { setCurrentImportFileName(null); } - } + }; const handleUpload = () => { if (importForm.current?.files.length) { const formData = new FormData(); - formData.append("file", importForm.current?.files[0]) - axios.post(`corporates/${corporate_id}/diagnosis-exclusions/import`, formData ) - .then(response => { + formData.append('file', importForm.current?.files[0]); + axios + .post(`corporates/${corporate_id}/diagnosis-exclusions/import`, formData) + .then((response) => { handleCancelImportButton(); loadDataTableData(); - setImportResult(response.data) + setImportResult(response.data); // alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows'); }) - .catch(response => { - enqueueSnackbar('Looks like something went wrong. Please check your data and try again. ' + response.message, { variant: 'error' }) - }) + .catch((response) => { + enqueueSnackbar( + 'Looks like something went wrong. Please check your data and try again. ' + + response.message, + { variant: 'error' } + ); + }); } else { - enqueueSnackbar('No File Selected', { variant: 'warning' }) + enqueueSnackbar('No File Selected', { variant: 'warning' }); } - } - + }; + return (
- - {( !currentImportFileName && - - {/*

kjasndkjandskjasndkjansdkjansd

*/} - - - + {currentImportFileName && ( + + + + + - - + +
)} - {( importResult && - - Last Import Result Report : {importResult.result_file?.name ?? "-"} - + {importResult && ( + + + Last Import Result Report :{' '} + + {importResult.result_file?.name ?? '-'} + + + )}
); } // Called on every row to map the data to the columns - function createData( icd: Icd ): Icd { + function createData(icd: Icd): Icd { return { ...icd, - } + }; + } + const plans = props?.data.map((plan: any) => { + return { + value: plan.code, + label: plan.code, + }; + }); + const [exclusions, setExclusions] = useState([ + { + min_age: '', + max_age: '', + plan: '', + msc: { + m: '', + s: '', + c: '', + }, + gneder: { + male: '', + female: '', + }, + }, + ]); + + function CollapseEdit(props: { + row: ReturnType; + data: any; + index: any; + setExclusions: any; + exclusions: any; + }) { + const { row, index, data } = props; } - // Generate the every row of the table - function Row(props: { row: ReturnType }) { - const { row } = props; + function Row(props: { + row: ReturnType; + data: any; + index: any; + setExclusions: any; + exclusions: any; + }) { + const { row, index, data } = props; + const [open, setOpen] = React.useState(false); + const [openEdit, setOpenEdit] = React.useState(false); + + console.log('open', open); + console.log('openEdit', openEdit); + + // const [plans, setPlans] = useState([]); + + const plans = data; + + const [minAge, setMinAge] = useState(''); + const [maxAge, setMaxAge] = useState(''); + const [valuePlan, setValuePlan] = useState([]); + + const handleMinAge = (event: ChangeEvent) => { + setMinAge(event.target.value); + }; + + const handleMaxAge = (event: ChangeEvent) => { + setMaxAge(event.target.value); + }; + + const handlePlanChange = (event: ChangeEvent, value: any) => { + setValuePlan(value); + }; + + // const [currentValuePlan, setCurrentValuePlan] = useState([]); + + const converToArray = (value: any) => { + console.log('value', value); + if (value == null || value == '') { + return null; + } + const array = value.split(',') ?? []; + const currentValuePlan = array.map((item: any) => ({ + value: item, + label: item, + })); + console.log('currentValuePlan', currentValuePlan); + + return currentValuePlan; + }; + // const [exclusionModal, setExclusionModal] = useState(false); + + const handleConfigExclusion = ( + event: ChangeEvent, + icd: any, + value: string, + type: string + ) => { + // console.log(event.target.checked, service, icd, value, type); + const allData = tempExclusions.find((item: any) => item.icd_id === icd.id); + if (allData) { + try { + axios + .post(`/corporates/${corporate_id}/diagnosis-exclusions/store`, { + // service_code: service.service_code, + icd_id: icd.id, + checked: event.target.checked ? '1' : '0', + value: value, + type: type, + one_row: allData, + }) + .then((res) => { + console.log('update', res.data); + loadDataTableData(); + }); + + enqueueSnackbar('Exclusion Updated', { + variant: 'success', + }); + } catch (error) { + console.log(error); + enqueueSnackbar('Exclusion Update Failed', { + variant: 'error', + }); + } + } + }; + + const [tempExclusions, setTempExclusions] = useState([ + { + min_age: '', + max_age: '', + plan: '', + msc: { + m: '', + s: '', + c: '', + }, + gneder: { + male: '', + female: '', + }, + }, + ]); + + console.log('tempExclusions', tempExclusions); + + const handleChange = (index: any, evnt: any, type: any, row: any, value: any) => { + if (type == 'min_age' || type == 'max_age') { + const { name, value } = evnt.target; + const list = [...exclusions]; + + console.log('list', list); + list[index][type] = value; + list[index].icd_id = row; + setTempExclusions(list); + } else if (type == 'msc' || type == 'gender') { + // const { name, value } = evnt.target; + const list = [...exclusions]; + console.log('checked', evnt.target.checked); + console.log('exc', exclusions); + console.log('list', list); + console.log('index', index); + console.log('type', type); + + list[index][type][value] = evnt.target.checked; + list[index].icd_id = row; + + setTempExclusions(list); + } else { + const data = value.map((item: any) => item.value); + + const string = data.join(','); + const list = [...exclusions]; + list[index][type] = string; + list[index].icd_id = row; + + setTempExclusions(list); + } + }; + + console.log('exclusions', exclusions); return ( *': { borderBottom: 'unset' } }}> - setOpen(!open)} - > + setOpen(!open)}> {open ? : } @@ -191,38 +431,288 @@ export default function List() { {row.name} {Object.keys(row.rules).length ? 'With Rules' : 'All'} - - + + + + + {openEdit ? ( + + ) : ( + + )} + {/* */} + {/* COLLAPSIBLE ROW */} - - { Object.keys(row.rules).length ? ( -
- - Excluded Only for : - - { row.rules.msc && ( - MSC : {row.rules.msc.join(', ') ?? "-"} - )} - { row.rules.gender && ( - Gender : {row.rules.gender.join(', ') ?? "-"} - )} - { (row.rules.min_age || row.rules.max_age) && ( - Age : {row.rules.min_age ?? "-"} - {row.rules.max_age ?? "-"} - )} - { row.rules.plan && ( - Plan : {row.rules.plan.join(', ') ?? "-"} - )} -
+ {open == true ? ( + openEdit == false ? ( + + {Object.keys(row.rules).length ? ( +
+ + Excluded Only for : + + + {row.rules.msc && ( + + MSC : {row.rules.msc.join(', ') ?? '-'} + + )} + {row.rules.gender && ( + + Gender : {row.rules.gender.join(', ') ?? '-'} + + )} + {(row.rules.min_age || row.rules.max_age) && ( + + Age : {row.rules.min_age ?? '-'} - {row.rules.max_age ?? '-'} + + )} + {row.rules.plan && ( + + Plan : {row.rules.plan.join(', ') ?? '-'} + + )} +
+ ) : ( + + Excluded for All + + )} +
) : ( - - Excluded for All - - )} -
+ // + + + Edit Exclusion : + + + + + + + MSC + + + + + + { + // handleConfigExclusion(event, row, 'm', 'msc'); + handleChange(index, event, 'msc', row.id, 'm'); + }} + /> + } + label="Member" + /> + + + { + // handleConfigExclusion(event, row, 's', 'msc'); + handleChange(index, event, 'msc', row.id, 's'); + }} + /> + } + label="Spouse" + /> + + + { + // handleConfigExclusion(event, row, 'c', 'msc'); + handleChange(index, event, 'msc', row.id, 'c'); + }} + /> + } + label="Child" + /> + + + + + + + + + + Gender + + + + + { + // handleConfigExclusion(event, row, 'male', 'gender'); + handleChange(index, event, 'gender', row.id, 'male'); + }} + /> + } + label="Male" + /> + + + { + // handleConfigExclusion(event, row, 'female', 'gender'); + handleChange(index, event, 'gender', row.id, 'female'); + }} + /> + } + label="Female" + /> + + + + + + + + + Age + + + + + { + handleMinAge(event); + handleChange(index, event, 'min_age', row.id); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion(event, row, minAge, 'min_age'); + } + }} + /> + + + { + handleMaxAge(event); + handleChange(index, event, 'max_age', row.id); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion(event, row, maxAge, 'max_age'); + } + }} + /> + + + + + + + + + Plan + + + + + option.label} + defaultValue={converToArray(row.value_rules.plan) || []} + isOptionEqualToValue={(option, value) => + option.value === value.value + } + onChange={(event, value) => { + handlePlanChange(event, value); + handleChange(index, event, 'plan', row.id, value); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion(event, row, valuePlan, 'plan'); + } + }} + renderInput={(params) => ( + + )} + /> + + + + + + + + ) + ) : null}
@@ -237,93 +727,118 @@ export default function List() { const [dataTableData, setDataTableData] = useState({ current_page: 1, data: [], - path: "", - first_page_url: "", + path: '', + first_page_url: '', last_page: 1, - last_page_url: "", - next_page_url: "", - prev_page_url: "", + last_page_url: '', + next_page_url: '', + prev_page_url: '', per_page: 10, from: 0, to: 0, - total: 0 + total: 0, }); - const loadDataTableData = async (appliedFilter : any | null = null) => { + const loadDataTableData = async (appliedFilter: any | null = null) => { setDataTableLoading(true); const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]); - const response = await axios.get('/corporates/'+corporate_id+'/diagnosis-exclusions', { params: filter }); + const response = await axios.get('/corporates/' + corporate_id + '/diagnosis-exclusions', { + params: filter, + }); setDataTableLoading(false); setDataTableData(response.data); - } + + var data = response.data.data; + var value_rules = data.map((item: any) => item.value_rules); + + setExclusions(value_rules); + }; const headStyle = { fontWeight: 'bold', }; const applyFilter = async (searchFilter: any) => { - await loadDataTableData({ "search" : searchFilter }); - setSearchParams({ "search" : searchFilter }); - } + await loadDataTableData({ search: searchFilter }); + setSearchParams({ search: searchFilter }); + }; - const handlePageChange = (event : ChangeEvent, value: number) => { - const filter = Object.fromEntries([...searchParams.entries(), ["page", value]]); + const handlePageChange = (event: ChangeEvent, value: number) => { + const filter = Object.fromEntries([...searchParams.entries(), ['page', value]]); loadDataTableData(filter); setSearchParams(filter); - } + }; useEffect(() => { loadDataTableData(); - }, []) - + }, []); + return ( - + {/* The Main Table */} - Service - Code - Name - Rules - Status - Action + + Service + + + Code + + + Name + + + Rules + + + Status + + + Action + - {dataTableIsLoading ? - ( - - - Loading - - - ) : ( - dataTableData.data.length == 0 ? - ( - - - No Data - - - ) : ( - - {dataTableData.data.map(row => ( - - ))} - - ) + {dataTableIsLoading ? ( + + + + Loading + + + + ) : dataTableData.data.length == 0 ? ( + + + + No Data + + + + ) : ( + + {dataTableData.data.map((row: any, index: any) => ( + + ))} + )}
- - -
+ + +
); } diff --git a/frontend/dashboard/src/pages/Corporates/Services/Create.tsx b/frontend/dashboard/src/pages/Corporates/Services/Create.tsx index 468a6d32..d72fe8a0 100755 --- a/frontend/dashboard/src/pages/Corporates/Services/Create.tsx +++ b/frontend/dashboard/src/pages/Corporates/Services/Create.tsx @@ -43,7 +43,7 @@ import { RHFCheckbox, RHFCustomMultiCheckbox, } from '../../../components/hook-form'; -import { useForm } from 'react-hook-form'; +import { Controller, useForm } from 'react-hook-form'; import { useParams } from 'react-router-dom'; import HeaderBreadcrumbs from '../../../components/HeaderBreadcrumbs'; import Page from '../../../components/Page'; @@ -54,7 +54,7 @@ import { ChangeEvent, useEffect, useMemo, useState } from 'react'; import axios from '../../../utils/axios'; import { CorporateService } from '../../../@types/corporates'; import { InfoIcon } from '../../../theme/overrides/CustomIcons'; -import { includes, set } from 'lodash'; +import { includes, min, set } from 'lodash'; import { array } from 'yup/lib/locale'; import CancelIcon from '@mui/icons-material/Cancel'; import { enqueueSnackbar, useSnackbar } from 'notistack'; @@ -75,6 +75,7 @@ export default function Divisions() { const [specialities, setSpecialities] = useState([]); const [plans, setPlans] = useState([]); + // const [dataExclusions, setDataExclusions] = useState([]); // console.log('specialities', specialities); @@ -87,8 +88,39 @@ export default function Divisions() { label: item.code, })) ); + setSpecialities(res.data.specialities); - setExclusion(res.data.service?.exclusions); + // var dataExclusions = res.data.service?.exclusions; + var dataExclusions = res.data.service?.exclusions; + console.log('dataExclusions', dataExclusions); + + var defaultExclusion = res.data.specialities.map((item: any) => { + var findExclusion = dataExclusions.find( + (exclusion: any) => exclusion.speciality_id == item.id + ); + + if (findExclusion) { + return findExclusion; + } else { + return { + speciality_id: item.id, + msc: { + m: false, + s: false, + c: false, + }, + gender: { + male: false, + female: false, + }, + min_age: null, + max_age: null, + plan: '', + }; + } + }); + + setExclusion(defaultExclusion); }); }, [corporate_id, service_code]); @@ -110,16 +142,17 @@ export default function Divisions() { }); }; - const [exclusion, setExclusion] = useState([]); - const handleConfigExclusion = ( event: ChangeEvent, service: any, speciality: any, - value: string, + value: any, type: string ) => { console.log(event.target.checked, service, speciality, value, type); + + const allData = exclusion.find((item: any) => item.speciality_id === speciality.id); + try { axios .post(`/corporates/${corporate_id}/services/${service_code}/specialities/exclusion`, { @@ -128,6 +161,7 @@ export default function Divisions() { checked: event.target.checked ? '1' : '0', value: value, type: type, + one_row: allData, }) .then((res) => { console.log('update', res.data); @@ -186,6 +220,81 @@ export default function Divisions() { } }; + const [minAge, setMinAge] = useState(''); + const [maxAge, setMaxAge] = useState(''); + const [valuePlan, setValuePlan] = useState([]); + + const [exclusion, setExclusion] = useState([ + { + min_age: '', + max_age: '', + plan: '', + }, + ]); + + console.log('exclusion', exclusion); + + const handleChange = (index: any, evnt: any, type: any, row: any, value: any) => { + if (type !== 'plan') { + const { name, value } = evnt.target; + const list = [...exclusion]; + + console.log('list', list); + list[index][type] = value; + list[index].speciality_id = row; + setExclusion(list); + } else { + const data = value.map((item: any) => item.value); + + const string = data.join(','); + const list = [...exclusion]; + list[index][type] = string; + setExclusion(list); + } + }; + + // const handleSubmit = (event: any, service: any, row: any) => { + // const allData = exclusion.find((item: any) => item.speciality_id === row.id); + + // try { + // axios + // .post(`/corporates/${corporate_id}/services/${service_code}/specialities/all-exclusion`, { + // // service_code: service.service_code, + // speciality_id: row.id, + // one_row: allData, + // }) + // .then((res) => { + // console.log('update', res.data); + // setService({ + // ...service, + // selected_specialities: res.data?.selected_specialities, + // exclusions: res.data?.service?.exclusions, + // }); + // }); + + // enqueueSnackbar('Exclusion Updated', { + // variant: 'success', + // }); + // } catch (error) { + // console.log(error); + // enqueueSnackbar('Exclusion Update Failed', { + // variant: 'error', + // }); + // } + // }; + + console.log('object', exclusion); + + console.log('plan', valuePlan); + console.log('max age', maxAge); + console.log('min age', minAge); + + const handleSaveConfigExclusion = ( + event: ChangeEvent, + service: any, + speciality: any + ) => {}; + const specialityModalStyle = { position: 'absolute' as 'absolute', top: '50%', @@ -222,12 +331,6 @@ export default function Divisions() { }, ]; - const [minAge, setMinAge] = useState(''); - const [maxAge, setMaxAge] = useState(''); - const [valuePlan, setValuePlan] = useState([]); - - console.log('plan', valuePlan); - const handleMinAge = (event: ChangeEvent) => { setMinAge(event.target.value); }; @@ -239,12 +342,11 @@ export default function Divisions() { const handlePlanChange = (event: ChangeEvent, value: any) => { setValuePlan(value); }; - // const [currentValuePlan, setCurrentValuePlan] = useState([]); - const converToArray = (value: any) => { + const convertToArray = (value: any) => { console.log('value', value); - if (value == null) { + if (value == null || value == '') { return null; } const array = value.split(',') ?? []; @@ -514,10 +616,11 @@ export default function Divisions() { Max Age Plan + - {specialities.map((row) => ( + {specialities.map((row: any, index: any) => ( + (item: { speciality_id: any; msc: { m: string } }) => item.speciality_id == row.id && item.msc?.m == '1' )} onChange={(event) => { @@ -555,7 +658,7 @@ export default function Divisions() { control={ + (item: { speciality_id: any; msc: { s: string } }) => item.speciality_id == row.id && item.msc?.s == '1' )} onChange={(event) => { @@ -569,7 +672,7 @@ export default function Divisions() { control={ + (item: { speciality_id: any; msc: { c: string } }) => item.speciality_id == row.id && item.msc?.c == '1' )} onChange={(event) => { @@ -587,7 +690,10 @@ export default function Divisions() { control={ + (item: { + speciality_id: any; + gender: { male: string }; + }) => item.speciality_id == row.id && item.gender?.male == '1' )} @@ -608,7 +714,10 @@ export default function Divisions() { control={ + (item: { + speciality_id: any; + gender: { female: string }; + }) => item.speciality_id == row.id && item.gender?.female == '1' )} @@ -632,13 +741,16 @@ export default function Divisions() { item.speciality_id == row.id + (item: { speciality_id: any }) => + item.speciality_id == row.id )?.min_age } onChange={(event) => { handleMinAge(event); + handleChange(index, event, 'min_age', row.id); }} onKeyDown={(event) => { if (event.key === 'Enter') { @@ -657,13 +769,16 @@ export default function Divisions() { item.speciality_id == row.id + (item: { speciality_id: any }) => + item.speciality_id == row.id )?.max_age } onChange={(event) => { handleMaxAge(event); + handleChange(index, event, 'max_age', row.id); }} onKeyDown={(event) => { if (event.key === 'Enter') { @@ -687,9 +802,10 @@ export default function Divisions() { fullWidth getOptionLabel={(option) => option.label} defaultValue={ - converToArray( + convertToArray( service.exclusions.find( - (item) => item.speciality_id == row.id + (item: { speciality_id: any }) => + item.speciality_id == row.id )?.plan ) || [] } @@ -698,6 +814,7 @@ export default function Divisions() { } onChange={(event, value) => { handlePlanChange(event, value); + handleChange(index, event, 'plan', row.id, value); }} onKeyDown={(event) => { if (event.key === 'Enter') { @@ -715,6 +832,17 @@ export default function Divisions() { )} /> + + + ))}