PHP code example of dcarbone / php-fhir

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


// first, build new configuration class
$config = new \DCarbone\PHPFHIR\Config(onfig->getVersions() as $versionConfig) {
    $versionConfig->getDefinition()->getBuilder()->render();
}



// build config
$config = new \YourConfiguredNamespace\PHPFHIRConfig([
    'registerAutoloader' => true, // use if you are not using Composer
    'libxmlOpts' => LIBXML_NONET | LIBXML_BIGLINES | LIBXML_PARSEHUGE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOXMLDECL // choose different libxml arguments if you want, ymmv.
    'rootXmlns' => 'https://hl7.org/fhir', // a specific root xmlns to use, if the source does not return one
    'overrideSourceXmlns' => true, // set this to true if you want the 'rootXmlns' value you defined to override any value seen from source 
]);

// build parser
$parser = new \YourConfiguredNamespace\PHPFHIRResponseParser($config);

// provide input, receive output.
$object = $parser->parse($yourResponseData);


$json = json_encode($object);

// To get an instance of \XMLWriter...
$xw = $object->xmlSerialize(null, $yourConfigInstance);

// to get as XML string...
$xml = $xw->outputMemory(true);

// you can alternatively have the output written directly to a file:
$xw = new \YourConfiguredNamespace\PHPFHIRXmlWriter();
$xw->openUri('file:///some/directory/fhir-resource.xml');
$object->xmlSerialize($xw, $yourConfigInstance);
shell
composer