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

@@ -252,11 +252,22 @@ class CorporateController extends Controller
public function show($id) public function show($id)
{ {
$corporate = Corporate::query() $corporate = Corporate::query()
->with(['currentPolicy']) ->with(['currentPolicy', 'plans'])
->withCount('corporatePlans') ->withCount('corporatePlans')
->withCount('employees') ->withCount('employees')
// ->withCount('employees.claims') // ->withCount('employees.claims')
->findOrFail($id); ->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); return response()->json($corporate);
} }

View File

@@ -117,9 +117,7 @@ class CorporateServiceController extends Controller
->where('service_code', $service_code) ->where('service_code', $service_code)
->with([ ->with([
'configs', 'service', 'configs', 'service',
'specialities' => function ($speciality) { 'specialities',
$speciality->where('active', true);
},
'specialities.speciality', 'specialities.speciality',
'specialities.exclusions.rules' 'specialities.exclusions.rules'
]) ])
@@ -206,16 +204,25 @@ class CorporateServiceController extends Controller
->with('exclusions.rules') ->with('exclusions.rules')
->first(); ->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(); $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') { if ($request->type == 'msc') {
@@ -372,7 +379,36 @@ class CorporateServiceController extends Controller
'name' => 'plan', 'name' => 'plan',
], [ ], [
'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) ->where('service_code', $service_code)
->with([ ->with([
'configs', 'service', 'configs', 'service',
'specialities' => function ($speciality) { 'specialities',
$speciality->where('active', true);
},
'specialities.speciality', 'specialities.speciality',
'specialities.exclusions.rules' 'specialities.exclusions.rules'
]) ])

View File

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

View File

@@ -81,6 +81,7 @@ Route::prefix('internal')->group(function () {
Route::get('corporates/{corporate_id}/diagnosis-exclusions', [DiagnosisExclusionController::class, 'index']); 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::post('corporates/{corporate_id}/diagnosis-exclusions/import', [DiagnosisExclusionController::class, 'import']);
Route::get('corporates/{corporate_id}/services', [CorporateServiceController::class, 'index']); Route::get('corporates/{corporate_id}/services', [CorporateServiceController::class, 'index']);

View File

@@ -32,10 +32,10 @@ class ExclusionService
'service_code' => 'OP', 'service_code' => 'OP',
'type' => 'diagnosis' 'type' => 'diagnosis'
]); ]);
if (!empty($excl_array[1])) { //msc if (!empty($excl_array[1])) { //msc
$msc = explode(',', $excl_array[1]); $msc = explode(',', $excl_array[1]);
collect($msc)->each(function($m) use ($exclusion) { collect($msc)->each(function ($m) use ($exclusion) {
$exclusion->rules()->create([ $exclusion->rules()->create([
'name' => 'msc', 'name' => 'msc',
'values' => $m 'values' => $m
@@ -44,11 +44,18 @@ class ExclusionService
} }
if (!empty($excl_array[2])) { //genders if (!empty($excl_array[2])) { //genders
$genders = explode(',', $excl_array[2]); $genders = explode(',', $excl_array[2]);
collect($genders)->each(function($gender) use ($exclusion) { collect($genders)->each(function ($gender) use ($exclusion) {
$exclusion->rules()->create([ if ($gender == 'M') {
'name' => 'gender', $exclusion->rules()->create([
'values' => $gender 'name' => 'gender',
]); 'values' => 'male'
]);
} else if ($gender == 'F') {
$exclusion->rules()->create([
'name' => 'gender',
'values' => 'female'
]);
}
}); });
} }
if (!empty($excl_array[3])) { //min_age if (!empty($excl_array[3])) { //min_age
@@ -84,10 +91,10 @@ class ExclusionService
'service_code' => 'OP', 'service_code' => 'OP',
'type' => 'diagnosis' 'type' => 'diagnosis'
]); ]);
if (!empty($excl_array[1])) { //msc if (!empty($excl_array[1])) { //msc
$msc = explode(',', $excl_array[1]); $msc = explode(',', $excl_array[1]);
collect($msc)->each(function($m) use ($exclusion) { collect($msc)->each(function ($m) use ($exclusion) {
$exclusion->rules()->create([ $exclusion->rules()->create([
'name' => 'msc', 'name' => 'msc',
'values' => $m 'values' => $m
@@ -96,11 +103,18 @@ class ExclusionService
} }
if (!empty($excl_array[2])) { //genders if (!empty($excl_array[2])) { //genders
$genders = explode(',', $excl_array[2]); $genders = explode(',', $excl_array[2]);
collect($genders)->each(function($gender) use ($exclusion) { collect($genders)->each(function ($gender) use ($exclusion) {
$exclusion->rules()->create([ if ($gender == 'M') {
'name' => 'gender', $exclusion->rules()->create([
'values' => $gender 'name' => 'gender',
]); 'values' => 'male'
]);
} else if ($gender == 'F') {
$exclusion->rules()->create([
'name' => 'gender',
'values' => 'female'
]);
}
}); });
} }
if (!empty($excl_array[3])) { //min_age if (!empty($excl_array[3])) { //min_age
@@ -133,10 +147,10 @@ class ExclusionService
'service_code' => 'OP', 'service_code' => 'OP',
'type' => 'diagnosis' 'type' => 'diagnosis'
]); ]);
if (!empty($excl_array[1])) { //msc if (!empty($excl_array[1])) { //msc
$msc = explode(',', $excl_array[1]); $msc = explode(',', $excl_array[1]);
collect($msc)->each(function($m) use ($exclusion) { collect($msc)->each(function ($m) use ($exclusion) {
$exclusion->rules()->create([ $exclusion->rules()->create([
'name' => 'msc', 'name' => 'msc',
'values' => $m 'values' => $m
@@ -145,11 +159,18 @@ class ExclusionService
} }
if (!empty($excl_array[2])) { //genders if (!empty($excl_array[2])) { //genders
$genders = explode(',', $excl_array[2]); $genders = explode(',', $excl_array[2]);
collect($genders)->each(function($gender) use ($exclusion) { collect($genders)->each(function ($gender) use ($exclusion) {
$exclusion->rules()->create([ if ($gender == 'M') {
'name' => 'gender', $exclusion->rules()->create([
'values' => $gender 'name' => 'gender',
]); 'values' => 'male'
]);
} else if ($gender == 'F') {
$exclusion->rules()->create([
'name' => 'gender',
'values' => 'female'
]);
}
}); });
} }
if (!empty($excl_array[3])) { //min_age if (!empty($excl_array[3])) { //min_age
@@ -177,7 +198,6 @@ class ExclusionService
$excl_array = explode('|', $row['ma_exclusion']); $excl_array = explode('|', $row['ma_exclusion']);
dd($excl_array); dd($excl_array);
if ($excl_array[0]) { if ($excl_array[0]) {
} }
} }
@@ -185,7 +205,6 @@ class ExclusionService
$excl_array = explode('|', $row['sp_exclusion']); $excl_array = explode('|', $row['sp_exclusion']);
dd($excl_array); dd($excl_array);
if ($excl_array[0]) { if ($excl_array[0]) {
} }
} }
@@ -193,7 +212,6 @@ class ExclusionService
$excl_array = explode('|', $row['pre_exist_exclusion']); $excl_array = explode('|', $row['pre_exist_exclusion']);
dd($excl_array); dd($excl_array);
if ($excl_array[0]) { if ($excl_array[0]) {
} }
} }
@@ -201,7 +219,6 @@ class ExclusionService
$excl_array = explode('|', $row['op_de_exclusion']); $excl_array = explode('|', $row['op_de_exclusion']);
dd($excl_array); dd($excl_array);
if ($excl_array[0]) { if ($excl_array[0]) {
} }
} }
@@ -209,7 +226,6 @@ class ExclusionService
$excl_array = explode('|', $row['maternity_waiting']); $excl_array = explode('|', $row['maternity_waiting']);
dd($excl_array); dd($excl_array);
if ($excl_array[0]) { if ($excl_array[0]) {
} }
} }
return true; return true;

View File

@@ -23,7 +23,7 @@ class CorporateServiceConfigResource extends JsonResource
'name' => $this->service->name, 'name' => $this->service->name,
'description' => $this->service->description, 'description' => $this->service->description,
'configurations' => $this->configs->pluck('value', 'name'), '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) { 'exclusions' => $this->specialities->map(function ($speciality) {
return [ return [
'speciality_id' => $speciality->speciality_id, 'speciality_id' => $speciality->speciality_id,

View File

@@ -14,7 +14,7 @@ class DiagnosisExclusionResource extends JsonResource
*/ */
public function toArray($request) public function toArray($request)
{ {
return [ $data = [
'id' => $this->id, 'id' => $this->id,
'code' => $this->exclusionable->code, 'code' => $this->exclusionable->code,
'name' => $this->exclusionable->name, 'name' => $this->exclusionable->name,
@@ -25,5 +25,36 @@ class DiagnosisExclusionResource extends JsonResource
return [$item['name'] => $item['values']]; 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;
} }
} }

View File

@@ -15,11 +15,13 @@ export default function Divisions() {
const { corporate_id } = useParams(); const { corporate_id } = useParams();
const [corporate, setCorporate] = useState<Corporate | null>(); const [corporate, setCorporate] = useState<Corporate | null>();
const [plans, setPlans] = useState<any[]>([]);
const configuredCorporateContext = useContext(ConfiguredCorporateContext); const configuredCorporateContext = useContext(ConfiguredCorporateContext);
useEffect(() => { useEffect(() => {
setCorporate(configuredCorporateContext.currentCorporate); setCorporate(configuredCorporateContext.currentCorporate);
setPlans(configuredCorporateContext.currentCorporate?.plans ?? []);
}, [configuredCorporateContext]); }, [configuredCorporateContext]);
const pageTitle = 'Diagnosis Exclusion'; const pageTitle = 'Diagnosis Exclusion';
@@ -45,7 +47,7 @@ export default function Divisions() {
<Card> <Card>
<CorporateTabNavigations position={'diagnosis-exclusions'} /> <CorporateTabNavigations position={'diagnosis-exclusions'} />
<List /> <List data={plans} />
</Card> </Card>
</Page> </Page>
); );

View File

@@ -1,5 +1,39 @@
// @mui // @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 KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'; import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import AddIcon from '@mui/icons-material/Add'; import AddIcon from '@mui/icons-material/Add';
@@ -16,34 +50,43 @@ import { Icd } from '../../../@types/diagnosis';
import BasePagination from '../../../components/BasePagination'; import BasePagination from '../../../components/BasePagination';
import { enqueueSnackbar } from 'notistack'; import { enqueueSnackbar } from 'notistack';
export default function List() { export default function List(props: any) {
const { themeStretch } = useSettings(); const { themeStretch } = useSettings();
const { corporate_id } = useParams(); const { corporate_id, service_code } = useParams();
const [searchParams, setSearchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const [importResult, setImportResult] = useState(null); const [importResult, setImportResult] = useState(null);
function SearchInput(props: any) { function SearchInput(props: any) {
// SEARCH // SEARCH
const searchInput = useRef<HTMLInputElement>(null); const searchInput = useRef<HTMLInputElement>(null);
const [searchText, setSearchText] = useState(""); const [searchText, setSearchText] = useState('');
const handleSearchChange = (event: any) => { const handleSearchChange = (event: any) => {
const newSearchText = event.target.value ?? '' const newSearchText = event.target.value ?? '';
setSearchText(newSearchText); setSearchText(newSearchText);
} };
const handleSearchSubmit = (event: any) => { const handleSearchSubmit = (event: any) => {
event.preventDefault(); event.preventDefault();
props.onSearch(searchText); // Trigger to Parent props.onSearch(searchText); // Trigger to Parent
} };
useEffect(() => { // Trigger First Search useEffect(() => {
// Trigger First Search
setSearchText(searchParams.get('search') ?? ''); setSearchText(searchParams.get('search') ?? '');
}, [searchParams]) }, [searchParams]);
return ( return (
<form onSubmit={handleSearchSubmit} style={{ width: '100%' }}> <form onSubmit={handleSearchSubmit} style={{ width: '100%' }}>
<TextField id="search-input" ref={searchInput} label="Search" variant="outlined" fullWidth onChange={handleSearchChange} value={searchText}/> <TextField
id="search-input"
ref={searchInput}
label="Search"
variant="outlined"
fullWidth
onChange={handleSearchChange}
value={searchText}
/>
</form> </form>
); );
} }
@@ -53,8 +96,8 @@ export default function List() {
// Create Button Menu // Create Button Menu
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const createMenu = Boolean(anchorEl); const createMenu = Boolean(anchorEl);
const importForm = useRef<HTMLInputElement>(null) const importForm = useRef<HTMLInputElement>(null);
const [currentImportFileName, setCurrentImportFileName] = useState(null) const [currentImportFileName, setCurrentImportFileName] = useState(null);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
@@ -69,52 +112,66 @@ export default function List() {
handleClose(); handleClose();
importForm.current ? importForm.current.click() : console.log('No File selected'); importForm.current ? importForm.current.click() : console.log('No File selected');
} else { } else {
alert('No file selected') alert('No file selected');
} }
} };
const handleCancelImportButton = () => { const handleCancelImportButton = () => {
importForm.current.value = ""; importForm.current.value = '';
importForm.current.dispatchEvent(new Event("change", { bubbles: true })); importForm.current.dispatchEvent(new Event('change', { bubbles: true }));
} };
const handleImportChange = (event: any) => { const handleImportChange = (event: any) => {
if (event.target.files[0]) { if (event.target.files[0]) {
setCurrentImportFileName(event.target.files[0].name) setCurrentImportFileName(event.target.files[0].name);
} else { } else {
setCurrentImportFileName(null); setCurrentImportFileName(null);
} }
} };
const handleUpload = () => { const handleUpload = () => {
if (importForm.current?.files.length) { if (importForm.current?.files.length) {
const formData = new FormData(); const formData = new FormData();
formData.append("file", importForm.current?.files[0]) formData.append('file', importForm.current?.files[0]);
axios.post(`corporates/${corporate_id}/diagnosis-exclusions/import`, formData ) axios
.then(response => { .post(`corporates/${corporate_id}/diagnosis-exclusions/import`, formData)
.then((response) => {
handleCancelImportButton(); handleCancelImportButton();
loadDataTableData(); loadDataTableData();
setImportResult(response.data) setImportResult(response.data);
// alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows'); // alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows');
}) })
.catch(response => { .catch((response) => {
enqueueSnackbar('Looks like something went wrong. Please check your data and try again. ' + response.message, { variant: 'error' }) enqueueSnackbar(
}) 'Looks like something went wrong. Please check your data and try again. ' +
response.message,
{ variant: 'error' }
);
});
} else { } else {
enqueueSnackbar('No File Selected', { variant: 'warning' }) enqueueSnackbar('No File Selected', { variant: 'warning' });
} }
} };
return ( return (
<div> <div>
<input type='file' id='file' ref={importForm} style={{ display: 'none' }} onChange={handleImportChange} accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain" /> <input
{( !currentImportFileName && <Stack direction={'row'} spacing={2} sx={{ p: 2 }}> type="file"
<SearchInput onSearch={applyFilter}/> id="file"
{/* <h1>kjasndkjandskjasndkjansdkjansd</h1> */} ref={importForm}
<Button style={{ display: 'none' }}
onChange={handleImportChange}
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain"
/>
{!currentImportFileName && (
<Stack direction={'row'} spacing={2} sx={{ p: 2 }}>
<SearchInput onSearch={applyFilter} />
{/* <h1>kjasndkjandskjasndkjansdkjansd</h1> */}
<Button
id="import-button" id="import-button"
variant='outlined' variant="outlined"
startIcon={<AddIcon />} sx={{ p: 1.8 }} startIcon={<AddIcon />}
sx={{ p: 1.8 }}
aria-controls={createMenu ? 'basic-menu' : undefined} aria-controls={createMenu ? 'basic-menu' : undefined}
aria-haspopup="true" aria-haspopup="true"
aria-expanded={createMenu ? 'true' : undefined} aria-expanded={createMenu ? 'true' : undefined}
@@ -134,55 +191,238 @@ export default function List() {
<MenuItem onClick={handleImportButton}>Import</MenuItem> <MenuItem onClick={handleImportButton}>Import</MenuItem>
<MenuItem onClick={handleClose}>Download Template</MenuItem> <MenuItem onClick={handleClose}>Download Template</MenuItem>
</Menu> </Menu>
</Stack> </Stack>
)} )}
{( currentImportFileName && <Stack direction={'row'} spacing={2} sx={{ p: 2 }}> {currentImportFileName && (
<ButtonGroup variant="outlined" aria-label="outlined button group" fullWidth> <Stack direction={'row'} spacing={2} sx={{ p: 2 }}>
<Button onClick={handleImportButton} fullWidth>{currentImportFileName ?? "No File Selected"}</Button> <ButtonGroup variant="outlined" aria-label="outlined button group" fullWidth>
<Button onClick={handleCancelImportButton} size="small" fullWidth={false} sx={{ p: 1.8 }}><CancelIcon color="error"/></Button> <Button onClick={handleImportButton} fullWidth>
</ButtonGroup> {currentImportFileName ?? 'No File Selected'}
</Button>
<Button
onClick={handleCancelImportButton}
size="small"
fullWidth={false}
sx={{ p: 1.8 }}
>
<CancelIcon color="error" />
</Button>
</ButtonGroup>
<Button <Button
id="upload-button" id="upload-button"
variant='outlined' variant="outlined"
startIcon={<UploadIcon />} sx={{ p: 1.8 }} startIcon={<UploadIcon />}
onClick={handleUpload} sx={{ p: 1.8 }}
> onClick={handleUpload}
Upload >
</Button> Upload
</Stack> </Button>
</Stack>
)} )}
{( importResult && {importResult && (
<Stack direction={'row'} sx={{ px: 2, pb: 2 }}> <Stack direction={'row'} sx={{ px: 2, pb: 2 }}>
<Box sx={{ color: "text.secondary" }}>Last Import Result Report : <a href={importResult.result_file?.url ?? "#"}>{importResult.result_file?.name ?? "-"}</a></Box> <Box sx={{ color: 'text.secondary' }}>
</Stack> Last Import Result Report :{' '}
<a import href={importResult.result_file?.url ?? '#'}>
{importResult.result_file?.name ?? '-'}
</a>
</Box>
</Stack>
)} )}
</div> </div>
); );
} }
// Called on every row to map the data to the columns // Called on every row to map the data to the columns
function createData( icd: Icd ): Icd { function createData(icd: Icd): Icd {
return { return {
...icd, ...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<typeof createData>;
data: any;
index: any;
setExclusions: any;
exclusions: any;
}) {
const { row, index, data } = props;
} }
// Generate the every row of the table function Row(props: {
function Row(props: { row: ReturnType<typeof createData> }) { row: ReturnType<typeof createData>;
const { row } = props; data: any;
index: any;
setExclusions: any;
exclusions: any;
}) {
const { row, index, data } = props;
const [open, setOpen] = React.useState(false); 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<HTMLInputElement>) => {
setMinAge(event.target.value);
};
const handleMaxAge = (event: ChangeEvent<HTMLInputElement>) => {
setMaxAge(event.target.value);
};
const handlePlanChange = (event: ChangeEvent<HTMLInputElement>, 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<HTMLInputElement>,
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 ( return (
<React.Fragment> <React.Fragment>
<TableRow sx={{ '& > *': { borderBottom: 'unset' } }}> <TableRow sx={{ '& > *': { borderBottom: 'unset' } }}>
<TableCell> <TableCell>
<IconButton <IconButton aria-label="expand row" size="small" onClick={() => setOpen(!open)}>
aria-label="expand row"
size="small"
onClick={() => setOpen(!open)}
>
{open ? <KeyboardArrowDownIcon /> : <KeyboardArrowRightIcon />} {open ? <KeyboardArrowDownIcon /> : <KeyboardArrowRightIcon />}
</IconButton> </IconButton>
</TableCell> </TableCell>
@@ -191,38 +431,288 @@ export default function List() {
<TableCell align="left">{row.name}</TableCell> <TableCell align="left">{row.name}</TableCell>
<TableCell align="left">{Object.keys(row.rules).length ? 'With Rules' : 'All'}</TableCell> <TableCell align="left">{Object.keys(row.rules).length ? 'With Rules' : 'All'}</TableCell>
<TableCell align="right"><Button variant="outlined" color="success" size="small">Active</Button></TableCell> <TableCell align="center">
<TableCell align="right"><Button variant="outlined" color="error" size="small">Disable</Button></TableCell> <Button variant="outlined" color="success" size="small">
Active
</Button>
</TableCell>
<TableCell align="center">
{openEdit ? (
<Button
variant="contained"
color="success"
size="small"
sx={{
color: '#fff',
}}
onClick={(event) => {
setOpenEdit(!openEdit);
if (open == false) {
setOpen(true);
}
handleConfigExclusion(event, row, '', 'one_row');
}}
>
Save
</Button>
) : (
<Button
variant="outlined"
color="success"
size="small"
onClick={() => {
setOpenEdit(true);
setOpen(true);
}}
>
Edit
</Button>
)}
{/* <Button
variant="outlined"
color="success"
size="small"
onClick={() => {
setOpenEdit(!openEdit);
if (open == false) {
setOpen(true);
}
}}
// onClick={() => {
// setOpenEdit(true);
// setOpen(true);
// }}
>
{openEdit ? 'Save' : 'Edit'}
</Button> */}
</TableCell>
</TableRow> </TableRow>
{/* COLLAPSIBLE ROW */} {/* COLLAPSIBLE ROW */}
<TableRow> <TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={99}> <TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={99}>
<Collapse in={open} timeout="auto" unmountOnExit> <Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ borderBottom: 1 }}> {open == true ? (
{ Object.keys(row.rules).length ? ( openEdit == false ? (
<div> <Box sx={{ borderBottom: 1 }}>
<Typography variant="body" sx={{ fontWeight: 'bold' }}> {Object.keys(row.rules).length ? (
Excluded Only for : <div>
</Typography> <Typography variant="body" sx={{ fontWeight: 'bold' }}>
{ row.rules.msc && (<Typography variant="body" component="div"> Excluded Only for :
MSC : {row.rules.msc.join(', ') ?? "-"} </Typography>
</Typography> )}
{ row.rules.gender && (<Typography variant="body" component="div"> {row.rules.msc && (
Gender : {row.rules.gender.join(', ') ?? "-"} <Typography variant="body" component="div">
</Typography> )} MSC : {row.rules.msc.join(', ') ?? '-'}
{ (row.rules.min_age || row.rules.max_age) && (<Typography variant="body" component="div"> </Typography>
Age : {row.rules.min_age ?? "-"} - {row.rules.max_age ?? "-"} )}
</Typography> )} {row.rules.gender && (
{ row.rules.plan && (<Typography variant="body" component="div"> <Typography variant="body" component="div">
Plan : {row.rules.plan.join(', ') ?? "-"} Gender : {row.rules.gender.join(', ') ?? '-'}
</Typography> )} </Typography>
</div> )}
{(row.rules.min_age || row.rules.max_age) && (
<Typography variant="body" component="div">
Age : {row.rules.min_age ?? '-'} - {row.rules.max_age ?? '-'}
</Typography>
)}
{row.rules.plan && (
<Typography variant="body" component="div">
Plan : {row.rules.plan.join(', ') ?? '-'}
</Typography>
)}
</div>
) : (
<Typography variant="body2" gutterBottom component="div">
Excluded for All
</Typography>
)}
</Box>
) : ( ) : (
<Typography variant="body2" gutterBottom component="div"> // <CollapseEdit row={row} index={index} plans={plans} />
Excluded for All <Box sx={{ borderBottom: 1, pb: 2 }}>
</Typography> <Typography variant="body2" sx={{ fontWeight: 'bold', mb: 2 }}>
)} Edit Exclusion :
</Box> </Typography>
<Stack direction={'column'} spacing={2}>
<FormControl fullWidth>
<Grid container spacing={2}>
<Grid item xs={2} md={2}>
<Typography id="demo-simple-select-label">MSC</Typography>
</Grid>
<Grid item xs={10} md={10}>
<Stack direction={'row'} spacing={2}>
<Grid item xs={3} md={3}>
<FormControlLabel
control={
<Checkbox
checked={row.value_rules.msc?.m == '1'}
onChange={(event) => {
// handleConfigExclusion(event, row, 'm', 'msc');
handleChange(index, event, 'msc', row.id, 'm');
}}
/>
}
label="Member"
/>
</Grid>
<Grid item xs={3} md={3}>
<FormControlLabel
control={
<Checkbox
checked={row.value_rules.msc?.s == '1'}
onChange={(event) => {
// handleConfigExclusion(event, row, 's', 'msc');
handleChange(index, event, 'msc', row.id, 's');
}}
/>
}
label="Spouse"
/>
</Grid>
<Grid item xs={3} md={3}>
<FormControlLabel
control={
<Checkbox
checked={row.value_rules.msc?.c == '1'}
onChange={(event) => {
// handleConfigExclusion(event, row, 'c', 'msc');
handleChange(index, event, 'msc', row.id, 'c');
}}
/>
}
label="Child"
/>
</Grid>
</Stack>
</Grid>
</Grid>
</FormControl>
<FormControl fullWidth>
<Grid container spacing={2}>
<Grid item xs={2} md={2}>
<Typography id="demo-simple-select-label">Gender</Typography>
</Grid>
<Grid item xs={10} md={10}>
<Stack direction={'row'} spacing={2}>
<Grid item xs={3} md={3}>
<FormControlLabel
control={
<Checkbox
checked={row.value_rules.gender?.male == '1'}
onChange={(event) => {
// handleConfigExclusion(event, row, 'male', 'gender');
handleChange(index, event, 'gender', row.id, 'male');
}}
/>
}
label="Male"
/>
</Grid>
<Grid item xs={3} md={3}>
<FormControlLabel
control={
<Checkbox
checked={row.value_rules.gender?.female == '1'}
onChange={(event) => {
// handleConfigExclusion(event, row, 'female', 'gender');
handleChange(index, event, 'gender', row.id, 'female');
}}
/>
}
label="Female"
/>
</Grid>
</Stack>
</Grid>
</Grid>
</FormControl>
<FormControl fullWidth>
<Grid container spacing={2}>
<Grid item xs={2} md={2}>
<Typography id="demo-simple-select-label">Age</Typography>
</Grid>
<Grid item xs={10} md={10}>
<Stack direction={'row'} spacing={2}>
<Grid item xs={3} md={3}>
<TextField
id="outlined-number"
type="number"
defaultValue={row.value_rules.min_age ?? ''}
onChange={(event) => {
handleMinAge(event);
handleChange(index, event, 'min_age', row.id);
}}
onKeyDown={(event) => {
if (event.key === 'Enter') {
handleConfigExclusion(event, row, minAge, 'min_age');
}
}}
/>
</Grid>
<Grid item xs={3} md={3}>
<TextField
id="outlined-number"
type="number"
defaultValue={row.value_rules.max_age ?? ''}
onChange={(event) => {
handleMaxAge(event);
handleChange(index, event, 'max_age', row.id);
}}
onKeyDown={(event) => {
if (event.key === 'Enter') {
handleConfigExclusion(event, row, maxAge, 'max_age');
}
}}
/>
</Grid>
</Stack>
</Grid>
</Grid>
</FormControl>
<FormControl fullWidth>
<Grid container spacing={2}>
<Grid item xs={2} md={2}>
<Typography id="demo-simple-select-label">Plan</Typography>
</Grid>
<Grid item xs={10} md={10}>
<Stack direction={'row'} spacing={2}>
<Grid item xs={12} md={12}>
<Autocomplete
id="combo-box-demo"
options={plans}
multiple
limitTags={5}
fullWidth
getOptionLabel={(option) => 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) => (
<TextField {...params} label="Plan" variant="outlined" />
)}
/>
</Grid>
</Stack>
</Grid>
</Grid>
</FormControl>
</Stack>
</Box>
)
) : null}
</Collapse> </Collapse>
</TableCell> </TableCell>
</TableRow> </TableRow>
@@ -237,93 +727,118 @@ export default function List() {
const [dataTableData, setDataTableData] = useState<LaravelPaginatedData>({ const [dataTableData, setDataTableData] = useState<LaravelPaginatedData>({
current_page: 1, current_page: 1,
data: [], data: [],
path: "", path: '',
first_page_url: "", first_page_url: '',
last_page: 1, last_page: 1,
last_page_url: "", last_page_url: '',
next_page_url: "", next_page_url: '',
prev_page_url: "", prev_page_url: '',
per_page: 10, per_page: 10,
from: 0, from: 0,
to: 0, to: 0,
total: 0 total: 0,
}); });
const loadDataTableData = async (appliedFilter : any | null = null) => { const loadDataTableData = async (appliedFilter: any | null = null) => {
setDataTableLoading(true); setDataTableLoading(true);
const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]); 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); setDataTableLoading(false);
setDataTableData(response.data); setDataTableData(response.data);
}
var data = response.data.data;
var value_rules = data.map((item: any) => item.value_rules);
setExclusions(value_rules);
};
const headStyle = { const headStyle = {
fontWeight: 'bold', fontWeight: 'bold',
}; };
const applyFilter = async (searchFilter: any) => { const applyFilter = async (searchFilter: any) => {
await loadDataTableData({ "search" : searchFilter }); await loadDataTableData({ search: searchFilter });
setSearchParams({ "search" : searchFilter }); setSearchParams({ search: searchFilter });
} };
const handlePageChange = (event : ChangeEvent, value: number) => { const handlePageChange = (event: ChangeEvent, value: number) => {
const filter = Object.fromEntries([...searchParams.entries(), ["page", value]]); const filter = Object.fromEntries([...searchParams.entries(), ['page', value]]);
loadDataTableData(filter); loadDataTableData(filter);
setSearchParams(filter); setSearchParams(filter);
} };
useEffect(() => { useEffect(() => {
loadDataTableData(); loadDataTableData();
}, []) }, []);
return ( return (
<Stack> <Stack>
<ImportForm /> <ImportForm />
<Card> <Card>
{/* The Main Table */} {/* The Main Table */}
<TableContainer component={Paper}> <TableContainer component={Paper}>
<Table aria-label="collapsible table"> <Table aria-label="collapsible table">
<TableBody> <TableBody>
<TableRow> <TableRow>
<TableCell style={headStyle} align="left" /> <TableCell style={headStyle} align="left" />
<TableCell style={headStyle} align="left">Service</TableCell> <TableCell style={headStyle} align="left">
<TableCell style={headStyle} align="left">Code</TableCell> Service
<TableCell style={headStyle} align="left">Name</TableCell> </TableCell>
<TableCell style={headStyle} align="left">Rules</TableCell> <TableCell style={headStyle} align="left">
<TableCell style={headStyle} align="right">Status</TableCell> Code
<TableCell style={headStyle} align="right">Action</TableCell> </TableCell>
<TableCell style={headStyle} align="left">
Name
</TableCell>
<TableCell style={headStyle} align="left">
Rules
</TableCell>
<TableCell style={headStyle} align="center">
Status
</TableCell>
<TableCell style={headStyle} align="center">
Action
</TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
{dataTableIsLoading ? {dataTableIsLoading ? (
( <TableBody>
<TableBody> <TableRow>
<TableRow> <TableCell colSpan={8} align="center">
<TableCell colSpan={8} align="center">Loading</TableCell> Loading
</TableRow> </TableCell>
</TableBody> </TableRow>
) : ( </TableBody>
dataTableData.data.length == 0 ? ) : dataTableData.data.length == 0 ? (
( <TableBody>
<TableBody> <TableRow>
<TableRow> <TableCell colSpan={8} align="center">
<TableCell colSpan={8} align="center">No Data</TableCell> No Data
</TableRow> </TableCell>
</TableBody> </TableRow>
) : ( </TableBody>
<TableBody> ) : (
{dataTableData.data.map(row => ( <TableBody>
<Row key={row.id} row={row} /> {dataTableData.data.map((row: any, index: any) => (
))} <Row
</TableBody> key={row.id}
) row={row}
data={plans}
index={index}
setExclusions={setExclusions}
/>
))}
</TableBody>
)} )}
</Table> </Table>
</TableContainer> </TableContainer>
<BasePagination paginationData={dataTableData} onPageChange={handlePageChange}/> <BasePagination paginationData={dataTableData} onPageChange={handlePageChange} />
</Card> </Card>
</Stack> </Stack>
); );
} }

View File

@@ -43,7 +43,7 @@ import {
RHFCheckbox, RHFCheckbox,
RHFCustomMultiCheckbox, RHFCustomMultiCheckbox,
} from '../../../components/hook-form'; } from '../../../components/hook-form';
import { useForm } from 'react-hook-form'; import { Controller, useForm } from 'react-hook-form';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import HeaderBreadcrumbs from '../../../components/HeaderBreadcrumbs'; import HeaderBreadcrumbs from '../../../components/HeaderBreadcrumbs';
import Page from '../../../components/Page'; import Page from '../../../components/Page';
@@ -54,7 +54,7 @@ import { ChangeEvent, useEffect, useMemo, useState } from 'react';
import axios from '../../../utils/axios'; import axios from '../../../utils/axios';
import { CorporateService } from '../../../@types/corporates'; import { CorporateService } from '../../../@types/corporates';
import { InfoIcon } from '../../../theme/overrides/CustomIcons'; import { InfoIcon } from '../../../theme/overrides/CustomIcons';
import { includes, set } from 'lodash'; import { includes, min, set } from 'lodash';
import { array } from 'yup/lib/locale'; import { array } from 'yup/lib/locale';
import CancelIcon from '@mui/icons-material/Cancel'; import CancelIcon from '@mui/icons-material/Cancel';
import { enqueueSnackbar, useSnackbar } from 'notistack'; import { enqueueSnackbar, useSnackbar } from 'notistack';
@@ -75,6 +75,7 @@ export default function Divisions() {
const [specialities, setSpecialities] = useState([]); const [specialities, setSpecialities] = useState([]);
const [plans, setPlans] = useState([]); const [plans, setPlans] = useState([]);
// const [dataExclusions, setDataExclusions] = useState([]);
// console.log('specialities', specialities); // console.log('specialities', specialities);
@@ -87,8 +88,39 @@ export default function Divisions() {
label: item.code, label: item.code,
})) }))
); );
setSpecialities(res.data.specialities); 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]); }, [corporate_id, service_code]);
@@ -110,16 +142,17 @@ export default function Divisions() {
}); });
}; };
const [exclusion, setExclusion] = useState([]);
const handleConfigExclusion = ( const handleConfigExclusion = (
event: ChangeEvent<HTMLInputElement>, event: ChangeEvent<HTMLInputElement>,
service: any, service: any,
speciality: any, speciality: any,
value: string, value: any,
type: string type: string
) => { ) => {
console.log(event.target.checked, service, speciality, value, type); console.log(event.target.checked, service, speciality, value, type);
const allData = exclusion.find((item: any) => item.speciality_id === speciality.id);
try { try {
axios axios
.post(`/corporates/${corporate_id}/services/${service_code}/specialities/exclusion`, { .post(`/corporates/${corporate_id}/services/${service_code}/specialities/exclusion`, {
@@ -128,6 +161,7 @@ export default function Divisions() {
checked: event.target.checked ? '1' : '0', checked: event.target.checked ? '1' : '0',
value: value, value: value,
type: type, type: type,
one_row: allData,
}) })
.then((res) => { .then((res) => {
console.log('update', res.data); 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<HTMLInputElement>,
service: any,
speciality: any
) => {};
const specialityModalStyle = { const specialityModalStyle = {
position: 'absolute' as 'absolute', position: 'absolute' as 'absolute',
top: '50%', 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<HTMLInputElement>) => { const handleMinAge = (event: ChangeEvent<HTMLInputElement>) => {
setMinAge(event.target.value); setMinAge(event.target.value);
}; };
@@ -239,12 +342,11 @@ export default function Divisions() {
const handlePlanChange = (event: ChangeEvent<HTMLInputElement>, value: any) => { const handlePlanChange = (event: ChangeEvent<HTMLInputElement>, value: any) => {
setValuePlan(value); setValuePlan(value);
}; };
// const [currentValuePlan, setCurrentValuePlan] = useState([]); // const [currentValuePlan, setCurrentValuePlan] = useState([]);
const converToArray = (value: any) => { const convertToArray = (value: any) => {
console.log('value', value); console.log('value', value);
if (value == null) { if (value == null || value == '') {
return null; return null;
} }
const array = value.split(',') ?? []; const array = value.split(',') ?? [];
@@ -514,10 +616,11 @@ export default function Divisions() {
Max Age Max Age
</TableCell> </TableCell>
<TableCell align="center">Plan</TableCell> <TableCell align="center">Plan</TableCell>
<TableCell />
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{specialities.map((row) => ( {specialities.map((row: any, index: any) => (
<TableRow <TableRow
key={row.id} key={row.id}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
@@ -541,7 +644,7 @@ export default function Divisions() {
control={ control={
<Checkbox <Checkbox
checked={service.exclusions.find( checked={service.exclusions.find(
(item) => (item: { speciality_id: any; msc: { m: string } }) =>
item.speciality_id == row.id && item.msc?.m == '1' item.speciality_id == row.id && item.msc?.m == '1'
)} )}
onChange={(event) => { onChange={(event) => {
@@ -555,7 +658,7 @@ export default function Divisions() {
control={ control={
<Checkbox <Checkbox
checked={service.exclusions.find( checked={service.exclusions.find(
(item) => (item: { speciality_id: any; msc: { s: string } }) =>
item.speciality_id == row.id && item.msc?.s == '1' item.speciality_id == row.id && item.msc?.s == '1'
)} )}
onChange={(event) => { onChange={(event) => {
@@ -569,7 +672,7 @@ export default function Divisions() {
control={ control={
<Checkbox <Checkbox
checked={service.exclusions.find( checked={service.exclusions.find(
(item) => (item: { speciality_id: any; msc: { c: string } }) =>
item.speciality_id == row.id && item.msc?.c == '1' item.speciality_id == row.id && item.msc?.c == '1'
)} )}
onChange={(event) => { onChange={(event) => {
@@ -587,7 +690,10 @@ export default function Divisions() {
control={ control={
<Checkbox <Checkbox
checked={service.exclusions.find( checked={service.exclusions.find(
(item) => (item: {
speciality_id: any;
gender: { male: string };
}) =>
item.speciality_id == row.id && item.speciality_id == row.id &&
item.gender?.male == '1' item.gender?.male == '1'
)} )}
@@ -608,7 +714,10 @@ export default function Divisions() {
control={ control={
<Checkbox <Checkbox
checked={service.exclusions.find( checked={service.exclusions.find(
(item) => (item: {
speciality_id: any;
gender: { female: string };
}) =>
item.speciality_id == row.id && item.speciality_id == row.id &&
item.gender?.female == '1' item.gender?.female == '1'
)} )}
@@ -632,13 +741,16 @@ export default function Divisions() {
<TextField <TextField
id="outlined-number" id="outlined-number"
type="number" type="number"
name="min_age"
defaultValue={ defaultValue={
service.exclusions.find( service.exclusions.find(
(item) => item.speciality_id == row.id (item: { speciality_id: any }) =>
item.speciality_id == row.id
)?.min_age )?.min_age
} }
onChange={(event) => { onChange={(event) => {
handleMinAge(event); handleMinAge(event);
handleChange(index, event, 'min_age', row.id);
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
@@ -657,13 +769,16 @@ export default function Divisions() {
<TextField <TextField
id="outlined-number" id="outlined-number"
type="number" type="number"
name="max_age"
defaultValue={ defaultValue={
service.exclusions.find( service.exclusions.find(
(item) => item.speciality_id == row.id (item: { speciality_id: any }) =>
item.speciality_id == row.id
)?.max_age )?.max_age
} }
onChange={(event) => { onChange={(event) => {
handleMaxAge(event); handleMaxAge(event);
handleChange(index, event, 'max_age', row.id);
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
@@ -687,9 +802,10 @@ export default function Divisions() {
fullWidth fullWidth
getOptionLabel={(option) => option.label} getOptionLabel={(option) => option.label}
defaultValue={ defaultValue={
converToArray( convertToArray(
service.exclusions.find( service.exclusions.find(
(item) => item.speciality_id == row.id (item: { speciality_id: any }) =>
item.speciality_id == row.id
)?.plan )?.plan
) || [] ) || []
} }
@@ -698,6 +814,7 @@ export default function Divisions() {
} }
onChange={(event, value) => { onChange={(event, value) => {
handlePlanChange(event, value); handlePlanChange(event, value);
handleChange(index, event, 'plan', row.id, value);
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
@@ -715,6 +832,17 @@ export default function Divisions() {
)} )}
/> />
</TableCell> </TableCell>
<TableCell align="center">
<Button
variant="outlined"
color="primary"
onClick={(event) => {
handleConfigExclusion(event, service, row, '', 'one_row');
}}
>
Save
</Button>
</TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>