list dokter, list RS
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -2,14 +2,20 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\Meta;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Person;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\Speciality;
|
||||
use App\Services\DoctorService;
|
||||
use App\Services\PrimayaApi;
|
||||
use Exception;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Termwind\Components\Dd;
|
||||
|
||||
class PractitionerSeeder extends Seeder
|
||||
{
|
||||
@@ -20,127 +26,222 @@ class PractitionerSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Person::truncate();
|
||||
// Practitioner::truncate();
|
||||
// PractitionerRole::truncate();
|
||||
// Meta::query()->where('metaable_type', Practitioner::class)->forceDelete();
|
||||
// Meta::query()->where('metaable_type', PractitionerRole::class)->forceDelete();
|
||||
// Address::query()->where('addressable_type', Person::class)->forceDelete();
|
||||
|
||||
|
||||
|
||||
$mapSpecialities = [
|
||||
'Akupunktur' => 'SP027',
|
||||
'Anak' => 'SP001',
|
||||
'Andrologi' => 'SP029',
|
||||
'Anastesia' => 'SP015',
|
||||
'Bedah Anak' => '',
|
||||
'Bedah Digestif' => '',
|
||||
'Bedah Mulut' => '',
|
||||
'Bedah Onkologi' => '',
|
||||
'Bedah Orthopedi' => 'SP007',
|
||||
'Bedah Plastik & Rekonstruksi' => 'SP005',
|
||||
'Bedah Saraf' => '',
|
||||
'Bedah Thorak & Kardiovaskuler' => '',
|
||||
'Bedah Umum' => 'SP004',
|
||||
'Bedah Vaskuler' => '',
|
||||
'Dokter Gigi' => 'SP026',
|
||||
'Fisik & Rehabilitasi' => 'SP014',
|
||||
'Gastroenterologi Hepatologi' => '',
|
||||
'Ginjal Hipertensi' => '',
|
||||
'Gizi Klinik' => 'SP019',
|
||||
'Hematologi Onkologi' => '',
|
||||
'Jantung & Pembuluh Darah' => 'SP008',
|
||||
'Kardio Vaskuler' => '',
|
||||
'Kebidanan & Kandungan' => 'SP003',
|
||||
'Kesehatan Jiwa' => 'SP018',
|
||||
'Kulit & Kelamin' => 'SP013',
|
||||
'Laboratorium' => '',
|
||||
'Mata' => 'SP011',
|
||||
'Okupasi' => 'SP016',
|
||||
'Paru' => 'SP009',
|
||||
'Patologi Klinik' => 'SP021',
|
||||
'Penyakit Dalam' => 'SP002',
|
||||
'Psikologi' => 'SP042',
|
||||
'Radiologi' => 'SP020',
|
||||
'Rehabilitasi Medik' => 'SP039',
|
||||
'Rheumatologi' => '',
|
||||
'Saraf' => 'SP012',
|
||||
'THT' => 'SP010',
|
||||
'Umum' => 'SP025',
|
||||
'Urologi' => 'SP006',
|
||||
'Lain-Lain' => '',
|
||||
];
|
||||
|
||||
$organizations = Organization::query()
|
||||
->whereHas('metas', function ($meta) {
|
||||
$meta->where('type', 'KodeRS');
|
||||
})
|
||||
->where('type', 'hospital')
|
||||
->with('metas')
|
||||
->get();
|
||||
$specialities = Speciality::pluck('id', 'name')->toArray();
|
||||
|
||||
foreach ($organizations as $organization) {
|
||||
$response = Http::get('https://app.primaya.id/temp/practitioners?code=' . $organization->meta->KodeRS);
|
||||
$hisOrganizationCode = $organization->meta->KodeRS ?? null;
|
||||
|
||||
foreach ($response->json()['practitioners'] as $practitioner) {
|
||||
$practitioner = json_decode(json_encode($practitioner));
|
||||
if (!empty($practitioner->meta->NIK)) {
|
||||
$newPerson = Person::updateOrCreate([
|
||||
'nik' => $practitioner->meta->NIK
|
||||
], [
|
||||
'nik' => $practitioner->meta->NIK,
|
||||
'name' => $practitioner->doctor->name,
|
||||
'gender' => $practitioner->doctor->gender,
|
||||
'birth_date' => !empty($practitioner->meta->TanggalLahir) && $practitioner->meta->TanggalLahir != '0000-00-00' ? $practitioner->meta->TanggalLahir : null,
|
||||
]);
|
||||
} else {
|
||||
$newPerson = Person::create([
|
||||
'name' => $practitioner->doctor->name,
|
||||
'gender' => $practitioner->doctor->gender,
|
||||
'birth_date' => !empty($practitioner->meta->TanggalLahir) && $practitioner->meta->TanggalLahir != '0000-00-00' ? $practitioner->meta->TanggalLahir : null,
|
||||
]);
|
||||
}
|
||||
$newPerson->addresses()->create([
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $practitioner->doctor->address,
|
||||
]);
|
||||
if (empty($hisOrganizationCode)) {
|
||||
$this->command->warn('NO ORGANIZATION CODE' . $organization->name);
|
||||
continue;
|
||||
}
|
||||
$primayaApiService = new PrimayaApi($hisOrganizationCode);
|
||||
|
||||
$newPractitioner = Practitioner::updateOrCreate([
|
||||
'person_id' => $newPerson->id
|
||||
$this->command->info('Getting RS ' . $hisOrganizationCode . '-' . $organization->name . ' PractitionerRole');
|
||||
|
||||
try {
|
||||
$doctors = $primayaApiService->doctors();
|
||||
$this->processDoctors($doctors, $mapSpecialities, $organization);
|
||||
} catch (Exception $e) {
|
||||
$this->command->warn('Something Went Wrong :' . $hisOrganizationCode . ' - ' . $organization->name . ' - ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function processDoctors($doctors, $mapSpecialities, $organization)
|
||||
{
|
||||
foreach ($doctors['data'] as $doctor) {
|
||||
|
||||
$DokterID = $doctor['DokterID'];
|
||||
|
||||
// $practitionerRole = PractitionerRole::whereHas('metas', function ($meta) use ($DokterID) {
|
||||
// $meta->where('type', 'DokterID')->where('value', $DokterID);
|
||||
// })->first();
|
||||
|
||||
$SpesialisasiID = optional($doctor['spesialisasi'])['KodeSpesialisasiID'] ?? null;
|
||||
$mapping = array_search($SpesialisasiID, $mapSpecialities);
|
||||
if ($mapping == false) {
|
||||
$this->command->warn('Skip Doctor : ' . $DokterID . '-' . $doctor['Nama'] . ' (Tidak Punya Spesialisasi)');
|
||||
continue;
|
||||
}
|
||||
$findSpecialityId = Speciality::where('name', $mapping)->first()->id;
|
||||
|
||||
$newPerson = Person::updateOrCreate([
|
||||
'nik' => $doctor['NIK']
|
||||
], [
|
||||
'nik' => (!empty($doctor['NIK'])) ? $doctor['NIK'] : null,
|
||||
'name' => $doctor['Nama'],
|
||||
'birth_date' => (!empty($doctor['TanggalLahir']) && $doctor['TanggalLahir'] != '0000-00-00') ? $doctor['TanggalLahir'] : null,
|
||||
'gender' => !empty($doctor['Kelamin']) ? $doctor['Kelamin'] : null,
|
||||
'phone' => (!empty($doctor['Ponsel']) && $doctor['Ponsel'] != '-') ? $doctor['Ponsel'] : null,
|
||||
'email' => (!empty($doctor['Email']) && $doctor['Email'] != '-') ? $doctor['Email'] : null,
|
||||
'birth_place' => (!empty($doctor['TempatLahir']) && $doctor['TempatLahir'] != '-') ? $doctor['TempatLahir'] : null,
|
||||
]);
|
||||
|
||||
// $newPerson = Person::create([
|
||||
// 'name' => $doctor['Nama'],
|
||||
// 'birth_date' => (!empty($doctor['TanggalLahir']) && $doctor['TanggalLahir'] != '0000-00-00') ? $doctor['TanggalLahir'] : null,
|
||||
// 'gender' => !empty($doctor['Kelamin']) ? $doctor['Kelamin'] : null,
|
||||
// ]);
|
||||
|
||||
$newAddress = $newPerson->addresses()->updateOrCreate([
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => (!empty($doctor['Alamat']) && $doctor['Alamat'] != '-') ? $doctor['Alamat'] : null,
|
||||
]);
|
||||
|
||||
$newPerson->main_address_id = $newAddress->id;
|
||||
$newPerson->save();
|
||||
|
||||
$newPractitioner = Practitioner::updateOrCreate([
|
||||
'person_id' => $newPerson->id
|
||||
], [
|
||||
'person_id' => $newPerson->id
|
||||
]);
|
||||
|
||||
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'education',
|
||||
'value' => (!empty($doctor['ProfilePendidikan']) && $doctor['ProfilePendidikan'] != '-') ? $doctor['ProfilePendidikan'] : null
|
||||
]);
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'award',
|
||||
'value' => (!empty($doctor['ProfileAward']) && $doctor['ProfileAward'] != '-') ? $doctor['ProfileAward'] : null
|
||||
]);
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'work_experience',
|
||||
'value' => (!empty($doctor['ProfilePengalamanKerja']) && $doctor['ProfilePengalamanKerja'] != '-') ? $doctor['ProfilePengalamanKerja'] : null
|
||||
]);
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'alias',
|
||||
'value' => (!empty($doctor['Sapaan']) && $doctor['Sapaan'] != '-') ? $doctor['Sapaan'] : null
|
||||
]);
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'Keilmuan',
|
||||
'value' => (!empty($doctor['Keilmuan']) && $doctor['Keilmuan'] != '-') ? $doctor['Keilmuan'] : null
|
||||
]);
|
||||
|
||||
$newPractitioner->metas()->updateOrCreate([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'tipeDokter',
|
||||
'value' => (!empty($doctor['Tipe']) && $doctor['Tipe'] != '-') ? $doctor['Tipe'] : null
|
||||
]);
|
||||
// $newPractitioner->metas()->create([
|
||||
// 'system' => 'primaya-his',
|
||||
// 'type' => 'description',
|
||||
// 'value' => $doctor['Description']
|
||||
// ]);
|
||||
|
||||
$newPractitionerRole = PractitionerRole::updateOrCreate([
|
||||
'practitioner_id' => $newPractitioner->id,
|
||||
'organization_id' => $organization->id,
|
||||
'speciality_id' => $findSpecialityId,
|
||||
'active' => 1,
|
||||
]);
|
||||
|
||||
$this->command->info('Doctor : ' . $DokterID . '-' . $doctor['Nama'] . ' (Spesialisasi : ' . $mapping . ')');
|
||||
|
||||
if (empty($newPractitionerRole->speciality_id)) {
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality_code',
|
||||
], [
|
||||
'person_id' => $newPerson->id
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'medical_treatment',
|
||||
'value' => $practitioner->doctor->meta->MedicalTreatment ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'education',
|
||||
'value' => $practitioner->doctor->meta->Education ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'award',
|
||||
'value' => $practitioner->doctor->meta->Award ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'work_experience',
|
||||
'value' => $practitioner->doctor->meta->WorkExperience ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'alias',
|
||||
'value' => $practitioner->meta->Sapaan ?? null,
|
||||
'type' => 'speciality_code',
|
||||
'value' => (!empty($doctor['KodeSpesialisasiID']) && $doctor['KodeSpesialisasiID'] != '-') ? $doctor['KodeSpesialisasiID'] : null
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'Keilmuan',
|
||||
'value' => $practitioner->meta->Keilmuan ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'description',
|
||||
'value' => $practitioner->doctor->description ?? null,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
$newPractitionerRole = PractitionerRole::create([
|
||||
'practitioner_id' => $newPractitioner->id,
|
||||
'organization_id' => $organization->id,
|
||||
'speciality_id' => $practitioner->speciality ? ($specialities[$practitioner->speciality->name] ?? null) : null,
|
||||
'active' => 1,
|
||||
]);
|
||||
|
||||
if (empty($newPractitionerRole->speciality_id)) {
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality_code',
|
||||
], [
|
||||
'system' => 'default',
|
||||
'type' => 'speciality_code',
|
||||
'value' => $practitioner->speciality->code ?? null,
|
||||
]);
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality',
|
||||
], [
|
||||
'system' => 'default',
|
||||
'type' => 'speciality',
|
||||
'value' => $practitioner->speciality->name ?? null,
|
||||
]);
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality_image',
|
||||
], [
|
||||
'system' => 'default',
|
||||
'type' => 'speciality_image',
|
||||
'value' => $practitioner->speciality->name ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
'type' => 'speciality',
|
||||
], [
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
'value' => $practitioner->meta->DokterID ?? null,
|
||||
'type' => 'speciality',
|
||||
'value' => (!empty($doctor['spesialisasi']['Nama']) && $doctor['spesialisasi']['Nama'] != '-') ? $doctor['spesialisasi']['Nama'] : null
|
||||
]);
|
||||
}
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
], [
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
'value' => $DokterID
|
||||
]);
|
||||
}
|
||||
|
||||
$hisOrganizationCode = $organization->meta->KodeRS ?? null;
|
||||
// Recursive
|
||||
if ($doctors['current_page'] < $doctors['last_page']) {
|
||||
try {
|
||||
$primayaApiService = new PrimayaApi($hisOrganizationCode);
|
||||
|
||||
$this->processDoctors($primayaApiService->doctors($doctors['current_page'] + 1), $mapSpecialities, $organization);
|
||||
} catch (Exception $e) {
|
||||
$this->command->info('Something Went Wrong :' . $hisOrganizationCode . ' - ' . $organization->name . ' - ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class SpecialitiesSeeder extends Seeder
|
||||
),
|
||||
array(
|
||||
'code' => '4',
|
||||
'name' => 'Anestesi',
|
||||
'name' => 'Anastesia',
|
||||
'image' => 'image/specialities/anestesi.png',
|
||||
),
|
||||
array(
|
||||
@@ -173,12 +173,12 @@ class SpecialitiesSeeder extends Seeder
|
||||
),
|
||||
array(
|
||||
'code' => '32',
|
||||
'name' => 'Psikolog',
|
||||
'name' => 'Psikologi',
|
||||
'image' => 'image/specialities/psikolog.png',
|
||||
),
|
||||
array(
|
||||
'code' => '33',
|
||||
'name' => 'Radiolog',
|
||||
'name' => 'Radiologi',
|
||||
'image' => 'image/specialities/radiolog.png',
|
||||
),
|
||||
array(
|
||||
@@ -221,7 +221,7 @@ class SpecialitiesSeeder extends Seeder
|
||||
// Speciality::truncate();
|
||||
|
||||
foreach ($specialities as $speciality) {
|
||||
$speciality['code'] = "SP".str_pad($speciality['code'], 4, 0, STR_PAD_LEFT);
|
||||
$speciality['code'] = "SP" . str_pad($speciality['code'], 4, 0, STR_PAD_LEFT);
|
||||
unset($speciality['image']);
|
||||
Speciality::updateOrCreate(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user