PHP code example of roundingwell / hl7

1. Go to this page and download the library: Download roundingwell/hl7 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/ */

    

roundingwell / hl7 example snippets


use RoundingWell\HL7\MessageFactory;

$factory = new MessageFactory();

// Parse from a string...
$message = $factory->parse($rawHl7);

// ...or straight from a file.
$message = $factory->parseFile('/path/to/message.hl7');

$msh = $message->getMSH();
echo $msh->getMessageControlId()->getValue(); // "599102"
echo $msh->getMessageType()->getTriggerEvent()->getValue(); // "A01"

// Assuming the message is an A01
$pid = $message->getPID();

echo $pid->getDateOfBirth()->getValue();

// Repeating fields return a list of data-type instances.
foreach ($pid->getPatientName() as $name) {
    echo $name->getGivenName()->getValue();               // "DONALD"
    echo $name->getFamilyName()->getSurname()->getValue(); // "DUCK"
}

// Multiple occurrences of the same segment (e.g. DG1) are available too.
$diagnoses = $message->listDG1();

foreach ($message->getAll('PROCEDURE') as $procedure) {
    $pr1 = $procedure->get('PR1');
    $roles = $procedure->getAll('ROL');
}

foreach ($pid->getIdentifierList() as $cx) {
    echo $cx->getId()->getValue();                              // "10006579"
    echo $cx->getAssigningAuthority()->getNamespaceId()->getValue(); // "1"
    echo $cx->getIdentifierTypeCode()->getValue();              // "MRN"
}

use RoundingWell\HL7\AcknowledgmentCode;
use RoundingWell\HL7\SymfonyUidGenerator;
use Symfony\Component\Clock\NativeClock;

$ack = $message->generateACK(
    AcknowledgmentCode::AA,
    new NativeClock(),
    new SymfonyUidGenerator(),
);

$wire = $message->serialize($encoding);

echo $message->debug();
// ADT_A01
//   MSH
//     MSH.1 (Field Separator): |
//     MSH.2 (Encoding Characters): ^~\&
//     MSH.9 (Message Type)
//       MSH.9.1 (Message Type): ADT
//       MSH.9.2 (Trigger Event): A01
//   PID
//     PID.1 (Set ID): 1
//     PID.5 (Patient Name)
//       PID.5.1 (Family Name)
//         PID.5.1.1 (Surname): SMITH
//       PID.5.2 (Given Name): JOHN

echo $message->debug();
// ADT_A01
//   MSH
//     MSH.1 (Field Separator): |
//     MSH.2 (Encoding Characters): ^~\&
//   ZPD
//     ZPD.1: foo
//     ZPD.2
//       ZPD.2.1: bar
//       ZPD.2.2: baz

$gt1 = $message->get('GT1');

$field = $gt1->getFieldRepetition(2, 0);                        // a GenericComposite
echo $field->getExtraComponents()->getComponent(0)->getData()->getValue(); // "8291"

$zds = $message->get('ZDS'); // a GenericSegment, readable like any untyped segment