From 5f8bc743b903ccf04ae6911284e41e7372f81e0f Mon Sep 17 00:00:00 2001 From: ivanwilliammd Date: Wed, 13 Nov 2024 03:58:08 +0000 Subject: [PATCH] Fix styling --- src/Exception/FHIR/FHIRException.php | 2 +- .../FHIR/FHIRInvalidPropertyValue.php | 2 +- src/Exception/FHIR/FHIRMissingProperty.php | 2 +- .../TerminologyInvalidArgumentException.php | 4 +- .../TerminologyMissingArgumentException.php | 4 +- src/FHIR/Bundle.php | 27 ++--- src/FHIR/Condition.php | 24 ++--- src/FHIR/Encounter.php | 34 +++--- src/FHIR/Location.php | 2 +- src/FHIR/Observation.php | 36 +++---- src/FHIR/Organization.php | 16 +-- src/FHIR/Patient.php | 20 ++-- src/OAuth2Client.php | 100 +++++++++--------- src/SatusehatIntegrationServiceProvider.php | 26 ++--- src/Terminology/Kfa.php | 30 +++--- tests/ExampleTestPhpunit.php | 4 +- 16 files changed, 162 insertions(+), 171 deletions(-) diff --git a/src/Exception/FHIR/FHIRException.php b/src/Exception/FHIR/FHIRException.php index 1f1a154..045a33d 100644 --- a/src/Exception/FHIR/FHIRException.php +++ b/src/Exception/FHIR/FHIRException.php @@ -8,7 +8,7 @@ class FHIRException extends Exception { public function __construct($message, $code = 0, ?Exception $previous = null) { - $message = 'FHIR Exception: ' . $message; + $message = 'FHIR Exception: '.$message; parent::__construct($message, $code, $previous); } diff --git a/src/Exception/FHIR/FHIRInvalidPropertyValue.php b/src/Exception/FHIR/FHIRInvalidPropertyValue.php index f41808b..fa0b7cb 100644 --- a/src/Exception/FHIR/FHIRInvalidPropertyValue.php +++ b/src/Exception/FHIR/FHIRInvalidPropertyValue.php @@ -6,7 +6,7 @@ class FHIRInvalidPropertyValue extends FHIRException { public function __construct($message) { - $message = 'FHIR Invalid Property Value: ' . $message; + $message = 'FHIR Invalid Property Value: '.$message; parent::__construct($message); } diff --git a/src/Exception/FHIR/FHIRMissingProperty.php b/src/Exception/FHIR/FHIRMissingProperty.php index a7406f3..8f8a365 100644 --- a/src/Exception/FHIR/FHIRMissingProperty.php +++ b/src/Exception/FHIR/FHIRMissingProperty.php @@ -6,7 +6,7 @@ class FHIRMissingProperty extends FHIRException { public function __construct($message) { - $message = 'FHIR Missing Property: ' . $message; + $message = 'FHIR Missing Property: '.$message; parent::__construct($message); } diff --git a/src/Exception/Terminology/TerminologyInvalidArgumentException.php b/src/Exception/Terminology/TerminologyInvalidArgumentException.php index e922d6d..84a34aa 100644 --- a/src/Exception/Terminology/TerminologyInvalidArgumentException.php +++ b/src/Exception/Terminology/TerminologyInvalidArgumentException.php @@ -2,6 +2,4 @@ namespace Satusehat\Integration\Exception\Terminology; -class TerminologyInvalidArgumentException extends TerminologyException -{ -} +class TerminologyInvalidArgumentException extends TerminologyException {} diff --git a/src/Exception/Terminology/TerminologyMissingArgumentException.php b/src/Exception/Terminology/TerminologyMissingArgumentException.php index a8d6ee9..2ee18f1 100644 --- a/src/Exception/Terminology/TerminologyMissingArgumentException.php +++ b/src/Exception/Terminology/TerminologyMissingArgumentException.php @@ -2,6 +2,4 @@ namespace Satusehat\Integration\Exception\Terminology; -class TerminologyMissingArgumentException extends TerminologyException -{ -} +class TerminologyMissingArgumentException extends TerminologyException {} diff --git a/src/FHIR/Bundle.php b/src/FHIR/Bundle.php index e84316b..4a4dbce 100644 --- a/src/FHIR/Bundle.php +++ b/src/FHIR/Bundle.php @@ -2,25 +2,26 @@ namespace Satusehat\Integration\FHIR; -use Satusehat\Integration\OAuth2Client; use Satusehat\Integration\Exception\FHIR\FHIRException; +use Satusehat\Integration\OAuth2Client; class Bundle extends OAuth2Client { - public array $bundle = [ 'resourceType' => 'Bundle', 'type' => 'transaction', 'entry' => [], ]; - public $encounter_id, $encounter; + public $encounter_id; + + public $encounter; private function uuidV4() { $data = openssl_random_pseudo_bytes(16); - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + $data[6] = chr(ord($data[6]) & 0x0F | 0x40); + $data[8] = chr(ord($data[8]) & 0x3F | 0x80); $uuid = bin2hex($data); $formatted_uuid = sprintf( '%s-%s-%s-%s-%s', @@ -43,8 +44,8 @@ public function addEncounter(Encounter $encounter) public function addCondition(Condition $condition) { - if (!isset($this->encounter_id)) { - throw new FHIRException("Please call addEncounter method first before addCondition."); + if (! isset($this->encounter_id)) { + throw new FHIRException('Please call addEncounter method first before addCondition.'); } $condition_uuid = $this->uuidV4(); @@ -55,26 +56,26 @@ public function addCondition(Condition $condition) // Membuat referensi condition di encounter $this->encounter->addDiagnosis($condition_uuid, $condition->condition['code']['coding'][0]['code'], '', true); - if (!isset($this->bundle['entry'][0])) { + if (! isset($this->bundle['entry'][0])) { $this->bundle['entry'][0] = [ - 'fullUrl' => 'urn:uuid:' . $this->encounter_id, + 'fullUrl' => 'urn:uuid:'.$this->encounter_id, 'resource' => '', 'request' => [ 'method' => 'POST', - 'url' => 'Encounter' - ] + 'url' => 'Encounter', + ], ]; } $this->bundle['entry'][0]['resource'] = json_decode($this->encounter->json()); $this->bundle['entry'][] = [ - 'fullUrl' => 'urn:uuid:' . $condition_uuid, + 'fullUrl' => 'urn:uuid:'.$condition_uuid, 'resource' => json_decode($condition->json()), 'request' => [ 'method' => 'POST', 'url' => 'Condition', - ] + ], ]; } diff --git a/src/FHIR/Condition.php b/src/FHIR/Condition.php index 6524f7f..58b53c4 100644 --- a/src/FHIR/Condition.php +++ b/src/FHIR/Condition.php @@ -2,9 +2,9 @@ namespace Satusehat\Integration\FHIR; +use Satusehat\Integration\Exception\FHIR\FHIRException; use Satusehat\Integration\OAuth2Client; use Satusehat\Integration\Terminology\Icd10; -use Satusehat\Integration\Exception\FHIR\FHIRException; class Condition extends OAuth2Client { @@ -79,7 +79,7 @@ public function addCode($code = null, $display = null) $code_check = Icd10::where('icd10_code', $code)->first(); // Handling if incomplete code / display - if (!$code_check) { + if (! $code_check) { throw new FHIRException('Kode ICD10 tidak ditemukan'); } @@ -94,14 +94,14 @@ public function addCode($code = null, $display = null) public function setSubject($subjectId, $name) { - $this->condition['subject']['reference'] = 'Patient/' . $subjectId; + $this->condition['subject']['reference'] = 'Patient/'.$subjectId; $this->condition['subject']['display'] = $name; } public function setEncounter($encounterId, $display = null, $bundle = false) { - $this->condition['encounter']['reference'] = ($bundle ? 'urn:uuid:' : 'Encounter/') . $encounterId; - $this->condition['encounter']['display'] = $display ? $display : 'Kunjungan ' . $encounterId; + $this->condition['encounter']['reference'] = ($bundle ? 'urn:uuid:' : 'Encounter/').$encounterId; + $this->condition['encounter']['display'] = $display ? $display : 'Kunjungan '.$encounterId; } public function setOnsetDateTime($onset_date_time = null) @@ -121,37 +121,37 @@ public function setRecordedDate($recorded_date = null) public function json() { // Add default clinical status - if (!array_key_exists('clinicalStatus', $this->condition)) { + if (! array_key_exists('clinicalStatus', $this->condition)) { $this->addClinicalStatus(); } // Add default category - if (!array_key_exists('category', $this->condition)) { + if (! array_key_exists('category', $this->condition)) { $this->addCategory(); } // Add default OnsetDateTime - if (!array_key_exists('onsetDateTime', $this->condition)) { + if (! array_key_exists('onsetDateTime', $this->condition)) { $this->setOnsetDateTime(); } // Add default RecordedDate - if (!array_key_exists('recordedDate', $this->condition)) { + if (! array_key_exists('recordedDate', $this->condition)) { $this->setRecordedDate(); } // Subject is required - if (!array_key_exists('subject', $this->condition)) { + if (! array_key_exists('subject', $this->condition)) { return 'Please use condition->setSubject($subjectId, $name) to pass the data'; } // Encounter is required - if (!array_key_exists('encounter', $this->condition)) { + if (! array_key_exists('encounter', $this->condition)) { return 'Please use condition->setEncounter($encounterId) to pass the data'; } // ICD-10 is required - if (!array_key_exists('code', $this->condition)) { + if (! array_key_exists('code', $this->condition)) { return 'Please use condition->addCode($code, $display) to pass the data'; } diff --git a/src/FHIR/Encounter.php b/src/FHIR/Encounter.php index 6b09768..bb1005b 100644 --- a/src/FHIR/Encounter.php +++ b/src/FHIR/Encounter.php @@ -11,7 +11,7 @@ class Encounter extends OAuth2Client public function addRegistrationId($registration_id) { - $identifier['system'] = 'http://sys-ids.kemkes.go.id/encounter/' . $this->organization_id; + $identifier['system'] = 'http://sys-ids.kemkes.go.id/encounter/'.$this->organization_id; $identifier['value'] = $registration_id; $this->encounter['identifier'][] = $identifier; @@ -32,7 +32,7 @@ private function statusHistoryValidate($arr, $status) public function setArrived($timestamp) { - if (!isset($this->encounter['statusHistory'])) { + if (! isset($this->encounter['statusHistory'])) { $this->encounter['statusHistory'] = []; } @@ -57,7 +57,7 @@ public function setArrived($timestamp) public function setInProgress($timestamp_start, $timestamp_end) { - if (!isset($this->encounter['statusHistory'])) { + if (! isset($this->encounter['statusHistory'])) { return 'Please use $this->setArrived first'; } @@ -89,7 +89,7 @@ public function setInProgress($timestamp_start, $timestamp_end) public function setFinished($timestamp) { - if (!isset($this->encounter['statusHistory'])) { + if (! isset($this->encounter['statusHistory'])) { return 'Please use $this->setArrived first'; } @@ -150,13 +150,13 @@ public function setConsultationMethod($consultation_method) public function setSubject($subjectId, $name) { - $this->encounter['subject']['reference'] = 'Patient/' . $subjectId; + $this->encounter['subject']['reference'] = 'Patient/'.$subjectId; $this->encounter['subject']['display'] = $name; } public function addParticipant($participantId, $name, $type = 'ATND', $display = 'attender') { - $participant['individual']['reference'] = 'Practitioner/' . $participantId; + $participant['individual']['reference'] = 'Practitioner/'.$participantId; $participant['individual']['display'] = $name; $participant['type'][]['coding'][] = [ 'system' => 'http://terminology.hl7.org/CodeSystem/v3-ParticipationType', @@ -169,7 +169,7 @@ public function addParticipant($participantId, $name, $type = 'ATND', $display = public function addLocation($locationId, $name) { - $location['location']['reference'] = 'Location/' . $locationId; + $location['location']['reference'] = 'Location/'.$locationId; $location['location']['display'] = $name; $this->encounter['location'][] = $location; @@ -177,7 +177,7 @@ public function addLocation($locationId, $name) public function setServiceProvider() { - $this->encounter['serviceProvider']['reference'] = 'Organization/' . $this->organization_id; + $this->encounter['serviceProvider']['reference'] = 'Organization/'.$this->organization_id; } public function addDiagnosis($id, $code, $display = null, $bundle = false) @@ -186,14 +186,14 @@ public function addDiagnosis($id, $code, $display = null, $bundle = false) $code_check = Icd10::where('icd10_code', $code)->first(); // Handling if incomplete code / display - if (!$code_check) { + if (! $code_check) { return 'Kode ICD-10 invalid'; } $display = $display ? $display : $code_check->icd10_en; // Create Encounter.diagnosis content - $diagnosis['condition']['reference'] = ($bundle ? 'urn:uuid:' : 'Condition/') . $id; + $diagnosis['condition']['reference'] = ($bundle ? 'urn:uuid:' : 'Condition/').$id; $diagnosis['condition']['display'] = $display; $diagnosis['use']['coding'][] = [ 'system' => 'http://terminology.hl7.org/CodeSystem/diagnosis-role', @@ -202,7 +202,7 @@ public function addDiagnosis($id, $code, $display = null, $bundle = false) ]; // Determine ranking - if (!array_key_exists('diagnosis', $this->encounter)) { + if (! array_key_exists('diagnosis', $this->encounter)) { $rank = 1; } else { $rank = count($this->encounter['diagnosis']) + 1; @@ -215,32 +215,32 @@ public function addDiagnosis($id, $code, $display = null, $bundle = false) public function json() { // Status is required - if (!array_key_exists('status', $this->encounter)) { + if (! array_key_exists('status', $this->encounter)) { return 'Please use encounter->statusHistory([timestamp array]) to add the status'; } // Class is required - if (!array_key_exists('class', $this->encounter)) { + if (! array_key_exists('class', $this->encounter)) { return 'Please use encounter->setConsultationMethod($method) to pass the data'; } // Subject is required - if (!array_key_exists('subject', $this->encounter)) { + if (! array_key_exists('subject', $this->encounter)) { return 'Please use encounter->setSubject($subjectId, $name) to pass the data'; } // Participant is required - if (!array_key_exists('participant', $this->encounter)) { + if (! array_key_exists('participant', $this->encounter)) { return 'Please use encounter->addParticipant($participantId, $name) to pass the data'; } // Location is required - if (!array_key_exists('location', $this->encounter)) { + if (! array_key_exists('location', $this->encounter)) { return 'Please use encounter->addLocation($locationId, $name) to pass the data'; } // Add default ServiceProvider - if (!array_key_exists('serviceProvider', $this->encounter)) { + if (! array_key_exists('serviceProvider', $this->encounter)) { $this->setServiceProvider(); } diff --git a/src/FHIR/Location.php b/src/FHIR/Location.php index 3e8a7e8..83bf570 100644 --- a/src/FHIR/Location.php +++ b/src/FHIR/Location.php @@ -127,7 +127,7 @@ public function addPhysicalType($physical_type = null) 'ca' => 'Cabinet', 'rd' => 'Road', 'area' => 'Area', - 'bd' => 'Bed' + 'bd' => 'Bed', ]; $this->location['physicalType']['coding'][] = [ diff --git a/src/FHIR/Observation.php b/src/FHIR/Observation.php index 4aa0603..22fbd54 100644 --- a/src/FHIR/Observation.php +++ b/src/FHIR/Observation.php @@ -2,8 +2,6 @@ namespace Satusehat\Integration\FHIR; -use Satusehat\Integration\FHIR\Enum\ObservationCategory; -use Satusehat\Integration\FHIR\Enum\ObservationCode; use Satusehat\Integration\Exception\FHIR\FHIRMissingProperty; use Satusehat\Integration\OAuth2Client; @@ -14,7 +12,7 @@ class Observation extends OAuth2Client /** * Sets a status to the observation. * - * @param string $status The status to add. Defaults to "final". + * @param string $status The status to add. Defaults to "final". * @return Observation Returns the current instance of the Observation class. */ public function setStatus($status = 'final'): Observation @@ -56,7 +54,7 @@ public function setStatus($status = 'final'): Observation /** * Adds a category to the observation. * - * @param string $category the code of the category + * @param string $category the code of the category * @return Observation The updated observation object. */ public function addCategory(string $category): Observation @@ -88,7 +86,7 @@ public function addCategory(string $category): Observation * Adds an observation code to the observation. * If more than one code is added, the last one will be used. * - * @param string $code The valid observation code to add. + * @param string $code The valid observation code to add. * @return Observation Returns the updated observation object. */ public function addCode(string $code): Observation @@ -96,7 +94,7 @@ public function addCode(string $code): Observation $code = [ 'system' => 'http://loinc.org', 'code' => '', - 'display' => '' + 'display' => '', ]; $display = ''; @@ -141,8 +139,8 @@ public function addCode(string $code): Observation /** * Sets the subject of the observation. * - * @param string $subjectId The SATUSEHAT ID of the subject. - * @param string $name The name of the subject. + * @param string $subjectId The SATUSEHAT ID of the subject. + * @param string $name The name of the subject. * @return Observation The current observation instance. */ public function setSubject(string $subjectId, string $name): Observation @@ -158,8 +156,8 @@ public function setSubject(string $subjectId, string $name): Observation /** * Sets the performer of the observation. * - * @param string $performerId The SATUSEHAT ID of the performer. - * @param string $name The name of the performer. + * @param string $performerId The SATUSEHAT ID of the performer. + * @param string $name The name of the performer. * @return Observation The current observation instance. */ public function setPerformer(string $performerId, string $name) @@ -175,14 +173,14 @@ public function setPerformer(string $performerId, string $name) /** * Visit data where observation results are obtained * - * @param string $encounterId The SATUSEHAT Encounter ID of the encounter. - * @param string $display The display name of the encounter. + * @param string $encounterId The SATUSEHAT Encounter ID of the encounter. + * @param string $display The display name of the encounter. */ - public function setEncounter(string $encounterId, string $display = null): Observation + public function setEncounter(string $encounterId, ?string $display = null): Observation { $this->observation['encounter'] = [ 'reference' => "Encounter/{$encounterId}", - 'display' => !empty($display) ? $display : "Kunjungan {$encounterId}", + 'display' => ! empty($display) ? $display : "Kunjungan {$encounterId}", ]; return $this; @@ -195,23 +193,23 @@ public function setEncounter(string $encounterId, string $display = null): Obser */ public function json(): string { - if (!array_key_exists('status', $this->observation)) { + if (! array_key_exists('status', $this->observation)) { throw new FHIRMissingProperty('Status is required.'); } - if (!array_key_exists('category', $this->observation)) { + if (! array_key_exists('category', $this->observation)) { throw new FHIRMissingProperty('Category is required.'); } - if (!array_key_exists('code', $this->observation)) { + if (! array_key_exists('code', $this->observation)) { throw new FHIRMissingProperty('Code is required.'); } - if (!array_key_exists('subject', $this->observation)) { + if (! array_key_exists('subject', $this->observation)) { throw new FHIRMissingProperty('Subject is required.'); } - if (!array_key_exists('encounter', $this->observation)) { + if (! array_key_exists('encounter', $this->observation)) { throw new FHIRMissingProperty('Encounter is required.'); } diff --git a/src/FHIR/Organization.php b/src/FHIR/Organization.php index 6c44b98..748f969 100644 --- a/src/FHIR/Organization.php +++ b/src/FHIR/Organization.php @@ -19,7 +19,7 @@ class Organization extends OAuth2Client public function addIdentifier($organization_identifier) { - $identifier['system'] = 'http://sys-ids.kemkes.go.id/organization/' . $this->organization_id; + $identifier['system'] = 'http://sys-ids.kemkes.go.id/organization/'.$this->organization_id; $identifier['value'] = $organization_identifier; $identifier['use'] = 'official'; @@ -48,12 +48,12 @@ public function setOperationalStatus($operational_status = null) public function setPartOf($partOf = null) { - $this->organization['partOf']['reference'] = 'Organization/' . ($partOf ? $partOf : $this->organization_id); + $this->organization['partOf']['reference'] = 'Organization/'.($partOf ? $partOf : $this->organization_id); } public function setType($type = 'dept') { - if (!in_array($type, ['dept', 'prov'])) { + if (! in_array($type, ['dept', 'prov'])) { throw new FHIRException("Types of organizations currently supported : 'prov' | 'dept' "); } @@ -141,7 +141,7 @@ public function addAddress($address_line = null, $postal_code = null, $city_name public function json() { // Add Organization type - if (!array_key_exists('type', $this->organization)) { + if (! array_key_exists('type', $this->organization)) { $this->organization['type'][] = [ 'coding' => [ [ @@ -154,22 +154,22 @@ public function json() } // Identifier is required - if (!array_key_exists('identifier', $this->organization)) { + if (! array_key_exists('identifier', $this->organization)) { return 'Please use organization->addIdentifier($organization_identifier) to pass the data'; } // Name is required - if (!array_key_exists('name', $this->organization)) { + if (! array_key_exists('name', $this->organization)) { return 'Please use organization->setName($organization_name) to pass the data'; } // Set default Organization part.Of - if (!array_key_exists('partOf', $this->organization)) { + if (! array_key_exists('partOf', $this->organization)) { $this->setPartOf(); } // Set default Organization type - if (!array_key_exists('type', $this->organization)) { + if (! array_key_exists('type', $this->organization)) { $this->setType(); } diff --git a/src/FHIR/Patient.php b/src/FHIR/Patient.php index 98244cd..2409651 100644 --- a/src/FHIR/Patient.php +++ b/src/FHIR/Patient.php @@ -2,8 +2,8 @@ namespace Satusehat\Integration\FHIR; -use Satusehat\Integration\OAuth2Client; use Satusehat\Integration\Exception\FHIR\FHIRException; +use Satusehat\Integration\OAuth2Client; class Patient extends OAuth2Client { @@ -24,7 +24,7 @@ public function addIdentifier($identifier_type, $identifier_value) } $identifier['use'] = 'official'; - $identifier['system'] = 'https://fhir.kemkes.go.id/id/' . $identifier_type; + $identifier['system'] = 'https://fhir.kemkes.go.id/id/'.$identifier_type; $identifier['value'] = $identifier_value; $this->patient['identifier'][] = $identifier; @@ -59,7 +59,7 @@ public function setBirthDate($date) $this->patient['birthDate'] = $date; } - public function setDeceased(Bool $bool) + public function setDeceased(bool $bool) { $this->patient['deceasedBoolean'] = $bool; } @@ -140,7 +140,7 @@ public function setMaritalStatus($marital_status, $marital_code = null, $marital $marital_display = 'Widowed'; break; default: - }; + } $marital['coding'] = [ [ @@ -159,7 +159,7 @@ public function setMultipleBirth($value) { if (is_bool($value)) { $this->patient['multipleBirthBoolean'] = $value; - } else if (is_int($value)) { + } elseif (is_int($value)) { $this->patient['multipleBirthInteger'] = $value; } } @@ -231,12 +231,12 @@ public function json() { // identifier is required - if (!array_key_exists('identifier', $this->patient)) { + if (! array_key_exists('identifier', $this->patient)) { throw new FHIRException('Please use patient->addIdentifier($identifier_type, $identifier_value) to pass the data'); } // Name is required - if (!array_key_exists('name', $this->patient)) { + if (! array_key_exists('name', $this->patient)) { throw new FHIRException('Please use patient->setName($organization_name) to pass the data'); } @@ -246,16 +246,15 @@ public function json() // } // Telecom is required - if (!array_key_exists('telecom', $this->patient)) { + if (! array_key_exists('telecom', $this->patient)) { throw new FHIRException('Please use patinet->addTelecom("phone_number") to pass the data'); } // Multiple birth is required - if (!array_key_exists('multipleBirthInteger', $this->patient)) { + if (! array_key_exists('multipleBirthInteger', $this->patient)) { throw new FHIRException('Please use patient->setMultipleBirth({integer/boolean}) to pass the data'); } - return json_encode($this->patient, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); } @@ -263,6 +262,7 @@ public function post() { $payload = $this->json(); [$statusCode, $res] = $this->ss_post('Patient', $payload); + return [$statusCode, $res]; } } diff --git a/src/OAuth2Client.php b/src/OAuth2Client.php index fa7dd08..1c6817d 100644 --- a/src/OAuth2Client.php +++ b/src/OAuth2Client.php @@ -19,11 +19,13 @@ class OAuth2Client public $practitioner_dev = ['10009880728', '10006926841', '10001354453', '10010910332', '10018180913', '10002074224', '10012572188', '10018452434', '10014058550', '10001915884']; public $base_url; + public $auth_url; public $fhir_url; public $client_id; + public $client_secret; public $organization_id; @@ -63,23 +65,23 @@ public function __construct() $this->organization_id = getenv('ORGID_DEV'); } - if (empty($this->satusehat_env) && !$this->override) { + if (empty($this->satusehat_env) && ! $this->override) { throw new OAuth2ClientException('SATUSEHAT environment is missing'); } - if (!in_array($this->satusehat_env, ['DEV', 'STG', 'PROD']) && !$this->override) { - throw new OAuth2ClientException('SATUSEHAT environment invalid, supported (DEV, STG, PROD). ' . $this->satusehat_env . ' given.'); + if (! in_array($this->satusehat_env, ['DEV', 'STG', 'PROD']) && ! $this->override) { + throw new OAuth2ClientException('SATUSEHAT environment invalid, supported (DEV, STG, PROD). '.$this->satusehat_env.' given.'); } - if ($this->satusehat_env == 'DEV' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && !$this->override) { + if ($this->satusehat_env == 'DEV' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && ! $this->override) { throw new OAuth2ClientException('SATUSEHAT environment defined as DEV, but CLIENTID_DEV / CLIENTSECRET_DEV / ORGID_DEV not set'); } - if ($this->satusehat_env == 'STG' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && !$this->override) { + if ($this->satusehat_env == 'STG' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && ! $this->override) { throw new OAuth2ClientException('SATUSEHAT environment defined as STG, but CLIENTID_STG / CLIENTSECRET_STG / ORGID_STG not set'); } - if ($this->satusehat_env == 'PROD' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && !$this->override) { + if ($this->satusehat_env == 'PROD' && (empty($this->client_id) || empty($this->client_secret || empty($this->organization_id))) && ! $this->override) { throw new OAuth2ClientException('SATUSEHAT environment defined as PROD, but CLIENTID_PROD / CLIENTSECRET_PROD / ORGID_PROD not set'); } @@ -88,13 +90,11 @@ public function __construct() $authEndpoint = getenv('SATUSEHAT_AUTH_ENDPOINT') ?: '/oauth2/v1'; $fhirEndpoint = getenv('SATUSEHAT_FHIR_ENDPOINT') ?: '/fhir-r4/v1'; - // // untuk handle versioning endpoint - $this->auth_url = $this->base_url . $authEndpoint; - $this->fhir_url = $this->base_url . $fhirEndpoint; - + $this->auth_url = $this->base_url.$authEndpoint; + $this->fhir_url = $this->base_url.$fhirEndpoint; - if (!$this->override && $this->organization_id == null) { + if (! $this->override && $this->organization_id == null) { return 'Add your organization_id at environment first'; } } @@ -108,7 +108,7 @@ public function token() return $token->token; } - $client = new Client(); + $client = new Client; $headers = [ 'Content-Type' => 'application/x-www-form-urlencoded', @@ -121,7 +121,7 @@ public function token() ]; // Create session - $url = $this->auth_url . '/accesstoken?grant_type=client_credentials'; + $url = $this->auth_url.'/accesstoken?grant_type=client_credentials'; $request = new Request('POST', $url, $headers); try { @@ -152,7 +152,7 @@ public function token() public function log($id, $action, $url, $payload, $response) { - $status = new SatusehatLog(); + $status = new SatusehatLog; $status->response_id = $id; $status->action = $action; $status->url = $url; @@ -174,16 +174,16 @@ public function get_by_id($resource, $id) { $access_token = $this->token(); - if (!isset($access_token)) { + if (! isset($access_token)) { return $this->respondError($this->oauth2_error); } - $client = new Client(); + $client = new Client; $headers = [ - 'Authorization' => 'Bearer ' . $access_token, + 'Authorization' => 'Bearer '.$access_token, ]; - $url = $this->fhir_url . '/' . $resource . '/' . $id; + $url = $this->fhir_url.'/'.$resource.'/'.$id; $request = new Request('GET', $url, $headers); try { @@ -192,7 +192,7 @@ public function get_by_id($resource, $id) $response = json_decode($res->getBody()->getContents()); if ($response->resourceType == 'OperationOutcome' | $response->total == 0) { - $id = 'Error ' . $statusCode; + $id = 'Error '.$statusCode; } $this->log($id, 'GET', $url, null, (array) $response); @@ -201,7 +201,7 @@ public function get_by_id($resource, $id) $statusCode = $e->getResponse()->getStatusCode(); $res = json_decode($e->getResponse()->getBody()->getContents()); - $this->log('Error ' . $statusCode, 'GET', $url, null, (array) $res); + $this->log('Error '.$statusCode, 'GET', $url, null, (array) $res); return [$statusCode, $res]; } @@ -211,16 +211,16 @@ public function get_by_nik($resource, $nik) { $access_token = $this->token(); - if (!isset($access_token)) { + if (! isset($access_token)) { return $this->respondError($this->oauth2_error); } - $client = new Client(); + $client = new Client; $headers = [ - 'Authorization' => 'Bearer ' . $access_token, + 'Authorization' => 'Bearer '.$access_token, ]; - $url = $this->fhir_url . '/' . $resource . '?identifier=https://fhir.kemkes.go.id/id/nik|' . $nik; + $url = $this->fhir_url.'/'.$resource.'?identifier=https://fhir.kemkes.go.id/id/nik|'.$nik; $request = new Request('GET', $url, $headers); try { @@ -240,7 +240,7 @@ public function get_by_nik($resource, $nik) $statusCode = $e->getResponse()->getStatusCode(); $res = json_decode($e->getResponse()->getBody()->getContents()); - $this->log('Error ' . $statusCode, 'GET', $url, null, (array) $res); + $this->log('Error '.$statusCode, 'GET', $url, null, (array) $res); return [$statusCode, $res]; } @@ -258,16 +258,16 @@ public function ss_kfa_get($resource, $queryString) $access_token = $this->token(); - if (!isset($access_token)) { + if (! isset($access_token)) { return $this->respondError($this->oauth2_error); } - $client = new Client(); + $client = new Client; $headers = [ - 'Authorization' => 'Bearer ' . $access_token, + 'Authorization' => 'Bearer '.$access_token, ]; - $url = $this->base_url . '/kfa-v2/' . $resource . $queryString; + $url = $this->base_url.'/kfa-v2/'.$resource.$queryString; $request = new Request('GET', $url, $headers); @@ -277,18 +277,18 @@ public function ss_kfa_get($resource, $queryString) $response = json_decode($res->getBody()->getContents()); if ($resource == 'products/all?') { - if (!empty($response) && empty($response->total)) { + if (! empty($response) && empty($response->total)) { $id = 'Not Found'; } else { - $id = 'Kfa_GET_' . $resource; + $id = 'Kfa_GET_'.$resource; } } if ($resource == 'products?') { - if (!empty($response) && empty($response->result)) { + if (! empty($response) && empty($response->result)) { $id = 'Not Found'; } else { - $id = 'Kfa_GET_' . $resource; + $id = 'Kfa_GET_'.$resource; } } @@ -299,7 +299,7 @@ public function ss_kfa_get($resource, $queryString) $statusCode = $e->getResponse()->getStatusCode(); $res = json_decode($e->getResponse()->getBody()->getContents()); - $this->log('Error ' . $statusCode, 'GET', $url, null, (array) $res); + $this->log('Error '.$statusCode, 'GET', $url, null, (array) $res); return [$statusCode, $res]; } @@ -309,17 +309,17 @@ public function ss_post($resource, $body) { $access_token = $this->token(); - if (!isset($access_token)) { + if (! isset($access_token)) { return $this->respondError($this->oauth2_error); } - $client = new Client(); + $client = new Client; $headers = [ 'Content-Type' => 'application/json', - 'Authorization' => 'Bearer ' . $access_token, + 'Authorization' => 'Bearer '.$access_token, ]; - $url = $this->fhir_url . ($resource == 'Bundle' ? '' : '/' . $resource); + $url = $this->fhir_url.($resource == 'Bundle' ? '' : '/'.$resource); $request = new Request('POST', $url, $headers, $body); try { @@ -339,22 +339,22 @@ public function ss_post($resource, $body) if ($identifier_type === 'nik') { if ($response->success !== true) { - $id = 'Error ' . $statusCode; + $id = 'Error '.$statusCode; } $id = $response->data->patient_id; - } else if ($identifier_type === 'nik-ibu') { + } elseif ($identifier_type === 'nik-ibu') { if ($response->create_patient->success !== true) { - $id = 'Error ' . $statusCode; + $id = 'Error '.$statusCode; } $id = $response->create_patient->data->patient_id; } } else { // Other than patient if ($response->resourceType == 'OperationOutcome' || $statusCode >= 400) { - $id = 'Error ' . $statusCode; + $id = 'Error '.$statusCode; } else { if ($resource == 'Bundle') { - $id = 'Success ' . $statusCode; + $id = 'Success '.$statusCode; } else { $id = $response->id; } @@ -367,7 +367,7 @@ public function ss_post($resource, $body) $statusCode = $e->getResponse()->getStatusCode(); $res = json_decode($e->getResponse()->getBody()->getContents()); - $this->log('Error ' . $statusCode, 'POST', $url, (array) json_decode($body), (array) $res); + $this->log('Error '.$statusCode, 'POST', $url, (array) json_decode($body), (array) $res); return [$statusCode, $res]; } @@ -380,17 +380,17 @@ public function ss_put($resource, $id, $body) { $access_token = $this->token(); - if (!isset($access_token)) { + if (! isset($access_token)) { return $this->respondError($this->oauth2_error); } - $client = new Client(); + $client = new Client; $headers = [ 'Content-Type' => 'application/json', - 'Authorization' => 'Bearer ' . $access_token, + 'Authorization' => 'Bearer '.$access_token, ]; - $url = $this->fhir_url . '/' . $resource . '/' . $id; + $url = $this->fhir_url.'/'.$resource.'/'.$id; $request = new Request('PUT', $url, $headers, $body); try { @@ -399,7 +399,7 @@ public function ss_put($resource, $id, $body) $response = json_decode($res->getBody()->getContents()); if ($response->resourceType == 'OperationOutcome' || $statusCode >= 400) { - $id = 'Error ' . $statusCode; + $id = 'Error '.$statusCode; } else { $id = $response->id; } @@ -410,7 +410,7 @@ public function ss_put($resource, $id, $body) $statusCode = $e->getResponse()->getStatusCode(); $res = json_decode($e->getResponse()->getBody()->getContents()); - $this->log('Error ' . $statusCode, 'PUT', $url, null, (array) $res); + $this->log('Error '.$statusCode, 'PUT', $url, null, (array) $res); return [$statusCode, $res]; } diff --git a/src/SatusehatIntegrationServiceProvider.php b/src/SatusehatIntegrationServiceProvider.php index f9280b3..03b0417 100644 --- a/src/SatusehatIntegrationServiceProvider.php +++ b/src/SatusehatIntegrationServiceProvider.php @@ -10,17 +10,17 @@ public function boot() { // Publish Config $this->publishes([ - __DIR__ . '/../config/satusehatintegration.php' => config_path('satusehatintegration.php'), + __DIR__.'/../config/satusehatintegration.php' => config_path('satusehatintegration.php'), ], 'config'); - $this->mergeConfigFrom(__DIR__ . '/../config/satusehatintegration.php', 'satusehatintegration'); + $this->mergeConfigFrom(__DIR__.'/../config/satusehatintegration.php', 'satusehatintegration'); // Publish Migrations for Token if (! class_exists('CreateSatusehatTokenTable')) { $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../database/migrations/create_satusehat_token_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_token_table.php"), + __DIR__.'/../database/migrations/create_satusehat_token_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_token_table.php"), ], 'migrations'); } @@ -29,7 +29,7 @@ public function boot() $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../database/migrations/create_satusehat_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_log_table.php"), + __DIR__.'/../database/migrations/create_satusehat_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_log_table.php"), ], 'migrations'); } @@ -38,19 +38,19 @@ public function boot() $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../database/migrations/create_satusehat_icd10_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_icd10_table.php"), + __DIR__.'/../database/migrations/create_satusehat_icd10_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_icd10_table.php"), ], 'icd10'); } // Publish ICD 10 csv data $this->publishes([ - __DIR__ . '/../database/seeders/csv/icd10.csv.stub' => database_path('/seeders/csv/icd10.csv'), + __DIR__.'/../database/seeders/csv/icd10.csv.stub' => database_path('/seeders/csv/icd10.csv'), ], 'icd10'); // Publish Seeder for ICD 10 if (! class_exists('Icd10Seeder')) { $this->publishes([ - __DIR__ . '/../database/seeders/Icd10Seeder.php.stub' => database_path('/seeders/Icd10Seeder.php'), + __DIR__.'/../database/seeders/Icd10Seeder.php.stub' => database_path('/seeders/Icd10Seeder.php'), ], 'icd10'); } @@ -59,19 +59,19 @@ public function boot() $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../database/migrations/create_satusehat_icd9cm_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_icd9cm_table.php"), + __DIR__.'/../database/migrations/create_satusehat_icd9cm_table.php.stub' => database_path("/migrations/{$timestamp}_create_satusehat_icd9cm_table.php"), ], 'icd9cm'); } // Publish ICD 9 CM csv data $this->publishes([ - __DIR__ . '/../database/seeders/csv/icd9cm.csv.stub' => database_path('/seeders/csv/icd9cm.csv'), + __DIR__.'/../database/seeders/csv/icd9cm.csv.stub' => database_path('/seeders/csv/icd9cm.csv'), ], 'icd9cm'); // Publish Seeder for ICD 9 CM if (! class_exists('Icd9cmSeeder')) { $this->publishes([ - __DIR__ . '/../database/seeders/Icd9cmSeeder.php.stub' => database_path('/seeders/Icd9cmSeeder.php'), + __DIR__.'/../database/seeders/Icd9cmSeeder.php.stub' => database_path('/seeders/Icd9cmSeeder.php'), ], 'icd9cm'); } @@ -80,19 +80,19 @@ public function boot() $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../database/migrations/create_kode_wilayah_indonesia_table.php.stub' => database_path("/migrations/{$timestamp}_create_kode_wilayah_indonesia_table.php"), + __DIR__.'/../database/migrations/create_kode_wilayah_indonesia_table.php.stub' => database_path("/migrations/{$timestamp}_create_kode_wilayah_indonesia_table.php"), ], 'kodewilayahindonesia'); } // Publish Kode Wilayah Indonesia csv data $this->publishes([ - __DIR__ . '/../database/seeders/csv/kode_wilayah_indonesia.csv.stub' => database_path('/seeders/csv/kode_wilayah_indonesia.csv'), + __DIR__.'/../database/seeders/csv/kode_wilayah_indonesia.csv.stub' => database_path('/seeders/csv/kode_wilayah_indonesia.csv'), ], 'kodewilayahindonesia'); // Publish Seeder for Kode Wilayah Indonesia if (! class_exists('KodeWilayahIndonesiaSeeder')) { $this->publishes([ - __DIR__ . '/../database/seeders/KodeWilayahIndonesiaSeeder.php.stub' => database_path('/seeders/KodeWilayahIndonesiaSeeder.php'), + __DIR__.'/../database/seeders/KodeWilayahIndonesiaSeeder.php.stub' => database_path('/seeders/KodeWilayahIndonesiaSeeder.php'), ], 'kodewilayahindonesia'); } } diff --git a/src/Terminology/Kfa.php b/src/Terminology/Kfa.php index 6c0d1e9..56ef14e 100644 --- a/src/Terminology/Kfa.php +++ b/src/Terminology/Kfa.php @@ -4,7 +4,6 @@ use Satusehat\Integration\Exception\Terminology\TerminologyException; use Satusehat\Integration\Exception\Terminology\TerminologyInvalidArgumentException; -use Satusehat\Integration\Exception\Terminology\TerminologyMissingArgumentException; use Satusehat\Integration\OAuth2Client; class Kfa extends OAuth2Client @@ -14,37 +13,36 @@ class Kfa extends OAuth2Client /** * Get Detail Kfa Product * - * @param string $identifier currently available stroed in : $identifier - * @param string $code + * @param string $identifier currently available stroed in : $identifier * @return void */ public function getProduct(string $identifier, string $code) { - if (!in_array($identifier, $this->identifier)) { - throw new TerminologyInvalidArgumentException("Identifier currently available (" . implode(", ", $this->identifier) . "), $identifier given"); + if (! in_array($identifier, $this->identifier)) { + throw new TerminologyInvalidArgumentException('Identifier currently available ('.implode(', ', $this->identifier)."), $identifier given"); } $queryStringBuilder = [ 'identifier' => $identifier, - 'code' => $code + 'code' => $code, ]; $queryString = http_build_query($queryStringBuilder); - return $this->ss_kfa_get("products?", $queryString); + return $this->ss_kfa_get('products?', $queryString); } + /** * Get paginated Kfa Products * - * @param string $productType currently available : 'alkes' | 'farmasi' - * @param integer $page min 1 no max - * @param integer $size min 1 max 1000 - * @param string|null $keyword + * @param string $productType currently available : 'alkes' | 'farmasi' + * @param int $page min 1 no max + * @param int $size min 1 max 1000 * @return void */ - public function getProducts(string $productType, string $keyword = null, int $page = 1, int $size = 100) + public function getProducts(string $productType, ?string $keyword = null, int $page = 1, int $size = 100) { - if (!in_array($productType, ['alkes', 'farmasi'])) { + if (! in_array($productType, ['alkes', 'farmasi'])) { throw new TerminologyInvalidArgumentException("\$productType currently available (alkes | farmasi), $productType given."); } @@ -53,16 +51,16 @@ public function getProducts(string $productType, string $keyword = null, int $pa } if ($page < 1 || $size < 1) { - throw new TerminologyInvalidArgumentException("Page / Size cant be blank."); + throw new TerminologyInvalidArgumentException('Page / Size cant be blank.'); } $queryStringBuilder = [ 'product_type' => $productType, 'page' => $page, - 'size' => $size + 'size' => $size, ]; - if (!empty($keyword)) { + if (! empty($keyword)) { $queryStringBuilder['keyword'] = $keyword; } diff --git a/tests/ExampleTestPhpunit.php b/tests/ExampleTestPhpunit.php index fa301e0..30853f0 100644 --- a/tests/ExampleTestPhpunit.php +++ b/tests/ExampleTestPhpunit.php @@ -4,6 +4,4 @@ use PHPUnit\Framework\TestCase; -class ExampleTest extends TestCase -{ -} +class ExampleTest extends TestCase {}