function getAllPhysicalExams($xml, $patient_id)
{
    global $encCheckUniqId, $from_date, $to_date;
    $vitArr = allVitalsPat($patient_id, $from_date, $to_date);
    foreach ($vitArr as $vitRow) {
        //Entry open
        $xml->open_entry();
        //observation Open
        $xml->open_customTag('observation', array('classCode' => 'OBS', 'moodCode' => 'EVN'));
        $tempID = "2.16.840.1.113883.10.20.22.4.2";
        $xml->self_templateid($tempID);
        $tempID = "2.16.840.1.113883.10.20.24.3.57";
        $xml->self_templateid($tempID);
        //$refID = getUuid();
        $refID = $encCheckUniqId[$vitRow['encounter']];
        $xml->self_customId($refID);
        $arr = array('code' => '8480-6', 'codeSystem' => '2.16.840.1.113883.6.1');
        //code Open
        $xml->open_customTag('code', $arr);
        $xml->element('originalText', "Physical Exam(BPS)");
        //code Close
        $xml->close_customTag();
        $xml->element('text', "Physical Exam(BPS)");
        $arr = array('code' => 'completed');
        $xml->self_customTag('statusCode', $arr);
        $timeArr = array('low' => date('Ymdhis', strtotime($vitRow['date'])), 'high' => date('Ymdhis', strtotime($vitRow['date'])));
        $xml->add_entryEffectTimeQRDA($timeArr);
        $xml->self_customTag('value', array('xsi:type' => 'PQ', 'value' => $vitRow['bps'], 'unit' => 'mmHg'));
        //observation Close
        $xml->close_customTag();
        //Entry close
        $xml->close_entry();
    }
}
function getAllPhysicalExams($xml, $patient_id)
{
    global $encCheckUniqId, $from_date, $to_date;
    $vitArr = allVitalsPat($patient_id, $from_date, $to_date);
    $measures = array('bps' => array('name' => 'Blood Pressure Systolic', 'category' => 'Blood Pressure', 'unit' => 'mmHg', 'code' => '8480-6'), 'bpd' => array('name' => 'Blood Pressure Diastolic', 'category' => 'Blood Pressure', 'unit' => 'mmHg', 'code' => '8462-4'), 'bmi' => array('name' => 'Body Mass Index', 'category' => 'Body Mass Index', 'unit' => 'kg/m2', 'code' => '39156-5'));
    foreach ($vitArr as $vitRow) {
        //Entry open
        foreach ($measures as $measure_key => $measure) {
            $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ?", array($measure['code'], $xml->nqf_code));
            if (!empty($vset['valueset'])) {
                $xml->open_entry();
                //observation Open
                $xml->open_customTag('observation', array('classCode' => 'OBS', 'moodCode' => 'EVN'));
                $tempID = "2.16.840.1.113883.10.20.22.4.2";
                $xml->self_templateid($tempID);
                $tempID = "2.16.840.1.113883.10.20.24.3.57";
                $xml->self_templateid($tempID);
                //$refID = getUuid();
                $refID = $encCheckUniqId[$vitRow['encounter']];
                $xml->self_customId($refID);
                $arr = array('code' => $measure['code'], 'codeSystem' => $vset['code_system'], 'sdtc:valueSet' => $vset['valueset']);
                //code Open
                $xml->open_customTag('code', $arr);
                $xml->element('originalText', "Physical Exam, Finding: " . $measure['measure']);
                //code Close
                $xml->close_customTag();
                $xml->element('text', "Physical Exam, Finding: " . $measure['category']);
                $arr = array('code' => 'completed');
                $xml->self_customTag('statusCode', $arr);
                $timeArr = array('low' => date('Ymdhis', strtotime($vitRow['date'])), 'high' => date('Ymdhis', strtotime($vitRow['date'])));
                $xml->add_entryEffectTimeQRDA($timeArr);
                $xml->self_customTag('value', array('xsi:type' => 'PQ', 'value' => $vitRow[$measure_key], 'unit' => $measure['unit']));
                //observation Close
                $xml->close_customTag();
                //Entry close
                $xml->close_entry();
            }
        }
    }
}