add config msc (belum kelar)
This commit is contained in:
@@ -74,6 +74,7 @@ class CorporateServiceController extends Controller
|
||||
public function update(Request $request, $corporate_id)
|
||||
{
|
||||
$corporateService = CorporateService::where('corporate_id', $corporate_id)->where('service_code', $request->service_code)->first();
|
||||
|
||||
$corporateServiceConfig = $corporateService->configs()->updateOrCreate([
|
||||
'corporate_service_id' => $corporateService->id,
|
||||
'name' => $request->config_name
|
||||
@@ -99,17 +100,21 @@ class CorporateServiceController extends Controller
|
||||
{
|
||||
$corporate = Corporate::findOrFail($corporate_id);
|
||||
$corporateService = CorporateService::query()
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
->with(['configs', 'service',
|
||||
'specialities' => function($speciality) {
|
||||
$speciality->where('status', 'active');
|
||||
},
|
||||
'specialities.speciality'])
|
||||
->first();
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
->with([
|
||||
'configs', 'service',
|
||||
'specialities' => function ($speciality) {
|
||||
$speciality->where('active', true);
|
||||
},
|
||||
'specialities.speciality',
|
||||
'specialities.exclusions.rules'
|
||||
])
|
||||
->first();
|
||||
|
||||
// $service = CorporateServiceConfigResource::make($corporateService);
|
||||
$specialities = Speciality::get();
|
||||
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'corporate' => $corporate,
|
||||
@@ -123,10 +128,10 @@ class CorporateServiceController extends Controller
|
||||
{
|
||||
// $corporate = Corporate::findOrFail($corporate_id);
|
||||
$corporateService = CorporateService::query()
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
// ->with('configs', 'service')
|
||||
->first();
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
// ->with('configs', 'service')
|
||||
->first();
|
||||
$corporateService->fill([
|
||||
'status' => $request->status == 'active' ? 'active' : 'inactive'
|
||||
]);
|
||||
@@ -137,25 +142,108 @@ class CorporateServiceController extends Controller
|
||||
|
||||
public function corporateServiceSpecialityUpdate(Request $request, $corporate_id, $service_code)
|
||||
{
|
||||
|
||||
|
||||
// return response()->json([$request->msc, $request->name, $request->speciality_id]);
|
||||
|
||||
$corporateService = CorporateService::query()
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
->first();
|
||||
CorporateServiceSpeciality::updateOrCreate([
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
->first();
|
||||
|
||||
|
||||
$corporateServiceSpeciality = CorporateServiceSpeciality::updateOrCreate([
|
||||
'corporate_service_id' => $corporateService->id,
|
||||
'speciality_id' => $request->speciality_id,
|
||||
], [
|
||||
'corporate_service_id' => $corporateService->id,
|
||||
'speciality_id' => $request->speciality_id,
|
||||
'status' => $request->status
|
||||
'active' => $request->active
|
||||
]);
|
||||
|
||||
$exclusion = $corporateServiceSpeciality->exclusions()->updateOrCreate([
|
||||
'corporate_id' => $corporate_id,
|
||||
'service_code' => $service_code,
|
||||
], [
|
||||
'corporate_id' => $corporate_id,
|
||||
'service_code' => $service_code,
|
||||
'type' => 'speciality',
|
||||
]);
|
||||
|
||||
|
||||
$selected_specialities = CorporateServiceSpeciality::query()
|
||||
->where('corporate_service_id', $corporateService->id)
|
||||
->where('status', 'active')
|
||||
->with('speciality')
|
||||
->get()
|
||||
->pluck('speciality.name', 'speciality.id');
|
||||
->where('corporate_service_id', $corporateService->id)
|
||||
->where('active', true)
|
||||
->with('speciality')
|
||||
->get()
|
||||
->pluck('speciality.name', 'speciality.id');
|
||||
|
||||
return response()->json($selected_specialities);
|
||||
}
|
||||
|
||||
public function storeExclusion(Request $request, $corporate_id, $service_code)
|
||||
{
|
||||
|
||||
$corporateService = CorporateService::query()
|
||||
->where('corporate_id', $corporate_id)
|
||||
->where('service_code', $service_code)
|
||||
->first();
|
||||
|
||||
$corporateServiceSpeciality = CorporateServiceSpeciality::where('corporate_service_id', $corporateService->id)
|
||||
->where('speciality_id', $request->speciality_id)
|
||||
->first();
|
||||
|
||||
// return ([$corporateServiceSpeciality, $request->msc, $request->name, $request->speciality_id, $request->type]);
|
||||
|
||||
$exclusion = $corporateServiceSpeciality->exclusions()->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->name == 'member' && $request->msc == "1") {
|
||||
$m = "m";
|
||||
} else {
|
||||
$m = "";
|
||||
}
|
||||
|
||||
if ($request->name == 'spouse' && $request->msc == "1") {
|
||||
$s = "s";
|
||||
} else {
|
||||
$s = "";
|
||||
}
|
||||
|
||||
if ($request->name == 'child' && $request->msc == "1") {
|
||||
$c = "c";
|
||||
} else {
|
||||
$c = "";
|
||||
}
|
||||
|
||||
$values = $m . $s . $c;
|
||||
|
||||
|
||||
|
||||
|
||||
$exclusion_rule = $exclusion->rules()->updateOrCreate([
|
||||
'exclusion_id' => $exclusion->id,
|
||||
'name' => 'msc',
|
||||
], [
|
||||
'name' => 'msc',
|
||||
'values' => $values,
|
||||
]);
|
||||
}
|
||||
|
||||
$selected_specialities = CorporateServiceSpeciality::query()
|
||||
->where('corporate_service_id', $corporateService->id)
|
||||
->where('active', true)
|
||||
->with('speciality')
|
||||
->get()
|
||||
->pluck('speciality.name', 'speciality.id');
|
||||
|
||||
return response()->json($selected_specialities);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ Route::prefix('internal')->group(function () {
|
||||
Route::get('corporates/{corporate_id}/services/{service_code}', [CorporateServiceController::class, 'corporateServiceIndex']);
|
||||
Route::put('corporates/{corporate_id}/services/{service_code}', [CorporateServiceController::class, 'corporateServiceUpdate']);
|
||||
Route::post('corporates/{corporate_id}/services/{service_code}/specialities', [CorporateServiceController::class, 'corporateServiceSpecialityUpdate']);
|
||||
Route::post('corporates/{corporate_id}/services/{service_code}/specialities/exclusion', [CorporateServiceController::class, 'storeExclusion']);
|
||||
|
||||
Route::get('corporates/{corporate_id}/formulariums', [CorporateFormulariumController::class, 'index']);
|
||||
Route::put('corporates/{corporate_id}/formulariums/{formularium_id}/{action}', [CorporateFormulariumController::class, 'updateStatus']);
|
||||
|
||||
@@ -15,7 +15,7 @@ class CorporateServiceConfigResource extends JsonResource
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
return [
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'corporate_id' => $this->corporate_id,
|
||||
'service_code' => $this->service_code,
|
||||
@@ -23,7 +23,49 @@ 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->pluck('speciality.name', 'speciality_id'),
|
||||
'exclusions' => $this->specialities->map(function ($speciality) {
|
||||
return [
|
||||
'speciality_id' => $speciality->speciality_id,
|
||||
'rules' => $speciality->exclusions->first()->rules->map(
|
||||
function ($rule) {
|
||||
return [
|
||||
'name' => $rule->name,
|
||||
'value' => explode(',', $rule->values)
|
||||
];
|
||||
}
|
||||
),
|
||||
|
||||
];
|
||||
}),
|
||||
];
|
||||
|
||||
$list_msc = $this->specialities->map(function ($speciality) {
|
||||
return explode(',', $speciality->exclusions->first()->rules->where('name', 'msc')->first()->values);
|
||||
})->map(function ($item) {
|
||||
return [
|
||||
'm' => in_array('m', $item),
|
||||
's' => in_array('s', $item),
|
||||
'c' => in_array('c', $item),
|
||||
];
|
||||
});
|
||||
// $msc = $cek->map(function ($item) {
|
||||
// return [
|
||||
// 'name' => $item,
|
||||
// 'value' => true
|
||||
// ];
|
||||
// });
|
||||
|
||||
$data['exclusions'] = $data['exclusions']->map(function ($item, $key) use ($list_msc) {
|
||||
|
||||
$item['msc'] = $list_msc[$key];
|
||||
return $item;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user