Skip to content

Commit

Permalink
Merge pull request #26 from SyaefulKai/feat/bundle
Browse files Browse the repository at this point in the history
feat: Encounter & Condition bundle
  • Loading branch information
ivanwilliammd authored Mar 30, 2024
2 parents 9757850 + bab927f commit 545e942
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
67 changes: 67 additions & 0 deletions src/FHIR/Bundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Satusehat\Integration\FHIR;

use Satusehat\Integration\OAuth2Client;

class Bundle extends OAuth2Client {

public array $bundle = [
'resourceType' => 'Bundle',
'type' => 'transaction',
'entry' => []
];

public $encounter_id;

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);
$uuid = bin2hex($data);
$formatted_uuid = sprintf('%s-%s-%s-%s-%s',
substr($uuid, 0, 8),
substr($uuid, 8, 4),
substr($uuid, 12, 4),
substr($uuid, 16, 4),
substr($uuid, 20, 12)
);

return $formatted_uuid;
}

public function addEncounter(Encounter $encounter){
$this->encounter_id = $this->uuidV4();
$encounter_bundle = [
'fullUrl' => 'urn:uuid:' . $this->encounter_id,
'resource' => json_decode($encounter->json()),
'request' => [
'method' => 'POST',
'url' => 'Encounter',
]
];

$this->bundle['entry'][] = $encounter_bundle;
}

public function addCondition(Condition $condition){
$condition->setEncounter($this->encounter_id);
$condition_bundle = [
'fullUrl' => 'urn:uuid:' . $this->uuidV4(),
'resource' => json_decode($condition->json()),
'request' => [
'method' => 'POST',
'url' => 'Condition'
],
];
$this->bundle['entry'][] = $condition_bundle;
}

public function post()
{
$payload = $this->bundle;
[$statusCode, $res] = $this->ss_post('Bundle', $payload);

return [$statusCode, $res];
}
}
4 changes: 2 additions & 2 deletions src/FHIR/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public function addIdentifier($location_identifier)
$this->location['identifier'][] = $identifier;
}

public function setName($location_name)
public function setName($location_name, $location_description = null)
{
$this->location['name'] = $location_name;
$this->location['description'] = $location_name;
$this->location['description'] = ($location_description == null ? $location_name : $location_description);
}

public function setStatus($status = 'active')
Expand Down

0 comments on commit 545e942

Please sign in to comment.