PHP code example of romeldev / php-fhir-r5

1. Go to this page and download the library: Download romeldev/php-fhir-r5 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

romeldev / php-fhir-r5 example snippets


use Romeldev\Fhir\Versions\R5\Version;
use Romeldev\Fhir\Versions\R5\Types\FHIRBase\FHIRResource\FHIRDomainResource\FHIRPatient;

$version = new Version();
$json = file_get_contents('/path/to/patient.json');
$decoded = json_decode($json);

$patient = FHIRPatient::jsonUnserialize(
    $decoded,
    $version->getConfig()->getUnserializeConfig()
);

foreach ($patient->getName() as $name) {
    echo $name->getFamily()->getValue() . "\n";
}

$encoded = json_encode($patient);

$xml = simplexml_load_file('/path/to/patient.xml');
$patient = FHIRPatient::xmlUnserialize(
    $xml,
    $version->getConfig()->getUnserializeConfig()
);

use Romeldev\Fhir\Versions\R5\VersionClient;
use Romeldev\Fhir\Client\Client;
use Romeldev\Fhir\Encoding\SerializeFormatEnum;
use Romeldev\Fhir\Versions\R5\VersionResourceTypeEnum;

$client = new VersionClient(
    new Client('https://my-fhir-server.example.com/fhir'),
    $version
);

$response = $client->read(
    VersionResourceTypeEnum::PATIENT,
    'example-patient-id',
    SerializeFormatEnum::JSON
);

if ($response->getCode() === 200) {
    $patient = FHIRPatient::jsonUnserialize(
        json_decode($response->getResp()),
        $version->getConfig()->getUnserializeConfig()
    );
}
bash
composer