PHP code example of dcarbone / php-fhir-generated

1. Go to this page and download the library: Download dcarbone/php-fhir-generated 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/ */

    

dcarbone / php-fhir-generated example snippets






use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRElement\FHIRHumanName;
use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRResource\FHIRDomainResource\FHIRPatient;

$patient = new FHIRPatient(
    id: 'patient-1',
    language: 'en-us',
    name: [
        new FHIRHumanName(given: ['Real'], family: 'Human'),
    ],
);

echo json_encode($patient, JSON_PRETTY_PRINT);

$patient = FHIRPatient::jsonUnserialize('{"resourceType":"Patient","id":"patient-1"}');



use DCarbone\PHPFHIRGenerated\Client\Client;
use DCarbone\PHPFHIRGenerated\Client\Config;
use DCarbone\PHPFHIRGenerated\Encoding\SerializeFormatEnum;
use DCarbone\PHPFHIRGenerated\Versions\R4\Version;
use DCarbone\PHPFHIRGenerated\Versions\R4\VersionClient;

$config = new Config(
    address: 'https://hapi.fhir.org/baseR4',
    defaultFormat: SerializeFormatEnum::JSON,
);

$client = new VersionClient(new Client($config), new Version());
$patient = $client->readOnePatient(resourceID: 'example');

$errors = $patient->_getValidationErrors();

if ([] === $errors) {
    echo "Resource is valid!\n";
} else {
    foreach ($errors as $path => $fieldErrors) {
        foreach ($fieldErrors as $rule => $message) {
            echo "{$path}: {$message}\n";
        }
    }
}
shell
composer