list dokter, list RS
This commit is contained in:
@@ -27,7 +27,17 @@ class Address extends Model
|
||||
'period_start',
|
||||
'period_end',
|
||||
];
|
||||
|
||||
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function addressable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
|
||||
@@ -24,9 +24,18 @@ class Organization extends Model
|
||||
// 'metas'
|
||||
// ];
|
||||
|
||||
// public $appends = [
|
||||
// 'meta'
|
||||
// ];
|
||||
public $appends = [
|
||||
'meta'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope a query to only include active data.
|
||||
|
||||
@@ -19,6 +19,21 @@ class PractitionerRole extends Model
|
||||
'active',
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'meta'
|
||||
];
|
||||
|
||||
public function getMetaAttribute()
|
||||
{
|
||||
$orgMeta = [];
|
||||
foreach ($this->metas as $meta) {
|
||||
$orgMeta[$meta->type] = $meta->value;
|
||||
}
|
||||
|
||||
return (object) $orgMeta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scope a query to only include active data.
|
||||
*
|
||||
|
||||
222
app/Services/DoctorService.php
Normal file
222
app/Services/DoctorService.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Person;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\Speciality;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
|
||||
class DoctorService
|
||||
{
|
||||
public function getData()
|
||||
{
|
||||
$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');
|
||||
})
|
||||
->with('metas')
|
||||
->get();
|
||||
$specialities = Speciality::pluck('id', 'name')->toArray();
|
||||
foreach ($organizations as $organization) {
|
||||
|
||||
$hisOrganizationCode = $organization->meta->KodeRS ?? null;
|
||||
|
||||
if (empty($hisOrganizationCode)) {
|
||||
$this->command->warn('NO ORGANIZATION CODE' . $organization->name);
|
||||
continue;
|
||||
}
|
||||
$primayaApiService = new PrimayaApi($hisOrganizationCode);
|
||||
|
||||
$this->command->info('Getting RS ' . $hisOrganizationCode . '-' . $organization->name . ' PractitionerRole');
|
||||
|
||||
try {
|
||||
$doctors = $primayaApiService->doctors();
|
||||
$this->processDoctors($doctors, $mapSpecialities, $organization, $specialities);
|
||||
} catch (Exception $e) {
|
||||
$this->command->warn('Something Went Wrong :' . $hisOrganizationCode . ' - ' . $organization->name . ' - ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function processDoctors($doctors, $mapSpecialities, $organization, $specialities)
|
||||
{
|
||||
// foreach ($doctors['data'] as $doctor) {
|
||||
|
||||
// }
|
||||
|
||||
$organizations = Organization::query()
|
||||
->whereHas('metas', function ($meta) {
|
||||
$meta->where('type', 'KodeRS');
|
||||
})
|
||||
->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);
|
||||
|
||||
foreach ($response->json()['practitioners'] as $practitioner) {
|
||||
$practitioner = json_decode(json_encode($practitioner));
|
||||
|
||||
dd($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,
|
||||
]);
|
||||
|
||||
$newPractitioner = Practitioner::updateOrCreate([
|
||||
'person_id' => $newPerson->id
|
||||
], [
|
||||
'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,
|
||||
]);
|
||||
$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',
|
||||
], [
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
'value' => $practitioner->meta->DokterID ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
123
app/Services/PrimayaApi.php
Normal file
123
app/Services/PrimayaApi.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Mockery\Generator\Parameter;
|
||||
use Psy\CodeCleaner\FunctionContextPass;
|
||||
use Termwind\Components\Dd;
|
||||
|
||||
class PrimayaApi
|
||||
{
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @param string $KodeRS C,DE,...
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $KodeRS)
|
||||
{
|
||||
// TODO Feels Wrong
|
||||
$endpointMaps = [
|
||||
"C" => [
|
||||
"base_url" => "http://tgr.primaya.id:1234",
|
||||
"token" => "1|QGYpSbyi9snAj1bHl1lP6apLJxbl20gsAoPmu1oh",
|
||||
],
|
||||
"D" => [
|
||||
"base_url" => "http://primaya-hospital.com:38588",
|
||||
"token" => "1|nbVbBmNmm967qYs9dNA0JvFNGvArGFGwFHJ8C9nK",
|
||||
],
|
||||
"E" => [
|
||||
"base_url" => "http://evasari.fortiddns.com:9280",
|
||||
"token" => "1|qb17AM6BB5sw1a3vZ2BTfIHXbPisqLSBdhwZKGJv",
|
||||
],
|
||||
"F" => [
|
||||
"base_url" => "http://mks.primaya.id:2588",
|
||||
"token" => null,
|
||||
],
|
||||
"M" => [ // Bektim
|
||||
"base_url" => 'http://101.255.124.84',
|
||||
"token" => null,
|
||||
],
|
||||
"O" => [
|
||||
"base_url" => "http://rsinco.fortiddns.com:88",
|
||||
"token" => "1|7e64N6gfSxsBic7DgwVec6EKQAIAx9Dd7is7K5Db",
|
||||
],
|
||||
"P" => [
|
||||
"base_url" => "http://bekut.primaya.id:88",
|
||||
"token" => "1|N5s4oKJNRnrpA2lneFI5LBhGNq6xwioY6PKDIA10",
|
||||
],
|
||||
"Q" => [
|
||||
"base_url" => "http://krw.primaya.id:4040",
|
||||
"token" => "1|zyS7AbeqzwKavfXFu0ReQOn5npIjdzVqA0pMqaMt",
|
||||
],
|
||||
"N" => [
|
||||
"base_url" => "http://pky.primaya.id:88",
|
||||
"token" => "1|yiajZEyu7pBkJNacv60tmb6McimbakG5lGzhm1Oy",
|
||||
],
|
||||
"SG" => [
|
||||
"base_url" => "http://smg.primaya.id:4040",
|
||||
"token" => "1|2lXZqpzhofXA2IjPdL7z52iBRiqrK5Eio924hMxi",
|
||||
],
|
||||
"BW" => [
|
||||
"base_url" => "http://bwp.primaya.id:4040",
|
||||
"token" => "1|8I6mdDxSUO0019GbbVx6olcACjaklxLUgmg0zUKh",
|
||||
],
|
||||
"SK" => [
|
||||
"base_url" => "http://skb.primaya.id:4040",
|
||||
"token" => "1|nYXzAvDbTceumUIDCr9sqXzj2Hq1kvfjYWeVg60P",
|
||||
],
|
||||
"PK" => [
|
||||
"base_url" => "http://pkt.primaya.id:4040",
|
||||
"token" => "2|nvIdQ7gzJnB7xQhfdjxlkr3oRSqBIvBOunjj72QO",
|
||||
],
|
||||
"CK" => [
|
||||
"base_url" => "http://103.154.92.150:4040",
|
||||
"token" => "1|BEKJwPhrmyjGwYVbl6xARV2auLSMtgYJyP4E3Kgd",
|
||||
],
|
||||
"DE" => [
|
||||
"base_url" => "http://202.148.23.68:38807",
|
||||
"token" => "1|DgEL6wte9vmg5X74AUBPVlbMtTIbDqrrp990Kqrt",
|
||||
],
|
||||
];
|
||||
|
||||
$config = $endpointMaps[$KodeRS];
|
||||
$this->base_url = !empty($config['base_url']) ? ($config['base_url'] . '/api') : null;
|
||||
|
||||
$this->headers = [
|
||||
'Authorization' => 'Bearer ' . ($config['token'] ?? null)
|
||||
];
|
||||
}
|
||||
|
||||
public static function getBaseUrl()
|
||||
{
|
||||
return config('lms-api.base_url');
|
||||
}
|
||||
|
||||
public static function getDefaultHeaders()
|
||||
{
|
||||
return ['id' => config('lms-api.auth_id')];
|
||||
}
|
||||
|
||||
public function consultationPrice($LayananKodes = [], $timeout = 30)
|
||||
{
|
||||
$response = Http::timeout($timeout)
|
||||
->withHeaders($this->headers)
|
||||
->post(
|
||||
$this->base_url . '/consultation-price',
|
||||
empty($LayananKodes) ? null : $LayananKodes
|
||||
)->json();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function doctors($page = 1)
|
||||
{
|
||||
$response = Http::withHeaders($this->headers)
|
||||
->get($this->base_url . '/doctors' . '?page=' . $page)
|
||||
->json();
|
||||
|
||||
return $response;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user