function getAllProcedures($xml, $patient_id)
{
    global $encCheckUniqId, $from_date, $to_date;
    $procArr = allProcPat("Procedure", $patient_id, $from_date, $to_date);
    foreach ($procArr as $procRow) {
        //Entry open
        $xml->open_entry();
        //procedure Open
        $xml->open_customTag('procedure', array('classCode' => 'PROC', 'moodCode' => 'EVN'));
        $tempID = "2.16.840.1.113883.10.20.24.3.64";
        $xml->self_templateid($tempID);
        $tempID = "2.16.840.1.113883.10.20.22.4.14";
        $xml->self_templateid($tempID);
        //$refID = getUuid();
        $refID = $encCheckUniqId[$procRow['encounter']];
        $xml->self_customId($refID);
        $arr = array('code' => $procRow['procedure_code'], 'codeSystem' => '2.16.840.1.113883.6.96');
        //code Open
        $xml->open_customTag('code', $arr);
        $xml->element('originalText', $procRow['procedure_name']);
        //code Close
        $xml->close_customTag();
        $xml->element('text', $procRow['procedure_name']);
        $arr = array('code' => 'completed');
        $xml->self_customTag('statusCode', $arr);
        $timeArr = array('low' => date('Ymdhis', strtotime($procRow['date_ordered'])), 'high' => date('Ymdhis', strtotime($procRow['date_ordered'])));
        $xml->add_entryEffectTimeQRDA($timeArr);
        //procedure Close
        $xml->close_customTag();
        //Entry close
        $xml->close_entry();
    }
}
function getAllPatientEncounters($xml, $patient_id)
{
    global $encCheckUniqId, $from_date, $to_date, $EncounterCptCodes;
    $encArr = allEncPat($patient_id, $from_date, $to_date);
    foreach ($encArr as $encRow) {
        $encRow['encounter'];
        $cpt_code = $EncounterCptCodes[str_replace(' ', '_', strtolower($encRow['pc_catname']))];
        $cpt_code = empty($cpt_code) ? '99201' : $cpt_code;
        $vset = sqlStatement("select * from valueset where code = ? and nqf_code = ?", array('99201', $xml->nqf_code));
        foreach ($vset as $v) {
            //Entry open
            $xml->open_entry();
            //Encounter Open
            $xml->open_customTag('encounter', array('classCode' => 'ENC', 'moodCode' => 'EVN'));
            $tempID = "2.16.840.1.113883.10.20.22.4.49";
            $xml->self_templateid($tempID);
            $tempID = "2.16.840.1.113883.10.20.24.3.23";
            $xml->self_templateid($tempID);
            $refID = getUuid();
            $xml->self_customId($refID);
            $encCheckUniqId[$encRow['encounter']] = $refID;
            $arr = array('code' => $cpt_code, 'codeSystem' => $v['code_system'], 'sdtc:valueSet' => $v['valueset']);
            $xml->self_codeCustom($arr);
            $arr = array('code' => 'completed');
            $xml->self_customTag('statusCode', $arr);
            $timeArr = array('low' => date('Ymdhis', strtotime($encRow['date'])), 'high' => date('Ymdhis', strtotime($encRow['date'])));
            $xml->add_entryEffectTime($timeArr);
            //Encounter Close
            $xml->close_customTag();
            //Entry close
            $xml->close_entry();
        }
    }
    $encArr = allProcPat("enc_checkup_procedure", $patient_id, $from_date, $to_date);
    foreach ($encArr as $encRow) {
        $encRow['encounter'];
        $vset = sqlStatement("select * from valueset where code = ? and nqf_code = ?", array($encRow['procedure_code'], $xml->nqf_code));
        foreach ($vset as $v) {
            //Entry open
            $xml->open_entry();
            //Encounter Open
            $xml->open_customTag('encounter', array('classCode' => 'ENC', 'moodCode' => 'EVN'));
            $tempID = "2.16.840.1.113883.10.20.22.4.49";
            $xml->self_templateid($tempID);
            $tempID = "2.16.840.1.113883.10.20.24.3.23";
            $xml->self_templateid($tempID);
            $refID = getUuid();
            $xml->self_customId($refID);
            $encCheckUniqId[$encRow['encounter']] = $refID;
            $arr = array('code' => $v['code'], 'codeSystem' => $v['code_system'], 'sdtc:valueSet' => $v['valueset']);
            $xml->self_codeCustom($arr);
            $arr = array('code' => 'completed');
            $xml->self_customTag('statusCode', $arr);
            $timeArr = array('low' => date('Ymdhis', strtotime($encRow['date'])), 'high' => date('Ymdhis', strtotime($encRow['date'])));
            $xml->add_entryEffectTime($timeArr);
            //Encounter Close
            $xml->close_customTag();
            //Entry close
            $xml->close_entry();
        }
    }
}