openxtrem/fhir-core


README

About

This library includes a generator for creating PHP classes from the HL7 FHIR specification, together with serializers and parsers for JSON and XML.

The project is under development

Generated classes usage example

$humanName = (new FHIRHumanName())
    ->setFamily('MyFamilyName')
    ->addGiven('MyGiven')
    ->addGiven('MySecondGiven');

$patient = (new FHIRPatient())
    ->setActive(true)
    ->setName($humanName);

Serializer

  • Using Generated classes and structure definition (R4 FHIR version)

Example

PHP Usage

$XMLSerializer = new XMLSerializer();
$JSONSerializer = new JSONSerializer();

$XMLPatientString = $XMLSerializer->serializeResource($patient)

or

$XMLPatientString = (new XMLSerializer())->serializeResource($patient)

Parser

  • Using Generated classes and structure definition (R4 FHIR version)

Example

XML Patient

<?xml version="1.0" encoding="UTF-8"?>
<Patient xmlns="http://hl7.org/fhir">
  <active value="true"/>
  <name>
    <family value="MyFamilyName"/>
    <given value="MyGiven"/>
    <given value="MySecondGiven"/>
  </name>
</Patient>

PHP Usage

$XMLParser = new XMLParser(FHIRVersion::R4);
$JSONParser = new JSONParser(FHIRVersion::R4);

$patient = $XMLParser->parse($XMLPatientString)

or

$patient = Parser::parse($XMLPatientString, FHIRVersion::R4)

Writing values

Initialize fhir_path

$fhir_path = new \Ox\Components\FHIRCore\FHIRPath\FHIRPath();

Place complex values

$patient = new \Ox\Components\FHIRCore\Model\R4\Resources\FHIRPatient();
$new_id = new \Ox\Components\FHIRCore\Model\R4\Datatypes\Complex\FHIRIdentifier();

// Overwrite
$fhir_path->placeValue($patient, 'Patient.identifier', $new_id);

// Without root name
$fhir_path->placeValue($patient, 'identifier', $new_id);

// append at index 1
$fhir_path->placeValue($patient, 'Patient.identifier[1]', $new_id);

// overwrite at index 0
$fhir_path->placeValue($patient, 'Patient.identifier[0]', $new_id);

// Append
$fhir_path->placeValue($patient, 'Patient.identifier[]', $new_id);

// Creates needed datatypes
$fhir_path->placeValue($fhir_patient, 'Patient.name.given', 'Erwan');