Skip to content

Commit

Permalink
Merge pull request #14 from yudistirasd/main
Browse files Browse the repository at this point in the history
feat: setType organization
  • Loading branch information
ivanwilliammd authored Mar 17, 2024
2 parents 5e581de + 2988922 commit 0d5fe21
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/FHIR/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

namespace Satusehat\Integration\FHIR;

use Satusehat\Integration\FHIR\Exception\FHIRException;
use Satusehat\Integration\OAuth2Client;

class Organization extends OAuth2Client
{

private $orgType = [
['code' => 'dept', 'display' => 'Hospital Department'],
['code' => 'prov', 'display' => 'Healthcare Provider']
];

public $organization = [
'resourceType' => 'Organization',
'active' => true,
Expand Down Expand Up @@ -41,6 +48,29 @@ public function setPartOf($partOf = null)
$this->organization['partOf']['reference'] = 'Organization/' . ($partOf ? $partOf : $this->organization_id);
}

public function setType($type)
{
if (!in_array($type, ['dept', 'prov'])) {
throw new FHIRException("Types of organizations currently supported : 'prov' | 'dept' ");
}

$organizationTypeIndex = array_search('prov', array_column($this->orgType, 'code'));

$display = $this->orgType[$organizationTypeIndex]['display'];

$this->organization['type'] = [
[
'coding' => [
[
'system' => 'http://terminology.hl7.org/CodeSystem/organization-type',
'code' => $type,
'display' => $display,
],
]
],
];
}

public function addPhone($phone_number = null)
{
$this->organization['telecom'][] = [
Expand Down Expand Up @@ -127,6 +157,7 @@ public function json()
$this->setPartOf();
}

$this->setType($this->organization_type);
return json_encode($this->organization, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
}

Expand Down
4 changes: 4 additions & 0 deletions src/OAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class OAuth2Client

public string $organization_id;

public string $organization_type;

public function __construct()
{
$dotenv = Dotenv::createUnsafeImmutable(getcwd());
Expand All @@ -52,6 +54,8 @@ public function __construct()
$this->organization_id = getenv('ORGID_DEV');
}

$this->organization_type = getenv('ORG_TYPE') ?: 'dept';

if ($this->organization_id == null) {
return 'Add your organization_id at environment first';
}
Expand Down

0 comments on commit 0d5fe21

Please sign in to comment.