function setDocument($xml) { $this->document = $this->XmlToArray($xml); unset($this->document['ClinicalDocument']['@attributes']); Array2XML::init('1.0', 'UTF-8', true, ['xml-stylesheet' => 'type="text/xsl" href="' . URL . '/lib/CCRCDA/schema/cda2.xsl"']); $data = ['@attributes' => ['xmlns' => 'urn:hl7-org:v3', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:hl7-org:v3 CDA.xsd']]; foreach ($this->document['ClinicalDocument'] as $i => $com) { $data[$i] = $com; } // Building the document $this->styledXml = Array2XML::createXML('ClinicalDocument', $data)->saveXML(); unset($data); $this->index = []; foreach ($this->document['ClinicalDocument']['component']['structuredBody']['component'] as $index => $component) { $code = isset($component['section']['code']['@attributes']['code']) ? $component['section']['code']['@attributes']['code'] : ''; //Advance Directives ??? switch ($code) { case '48765-2': $this->index['allergies'] = $index; break; case '10160-0': $this->index['medications'] = $index; break; case '11450-4': $this->index['problems'] = $index; break; case '47519-4': $this->index['procedures'] = $index; break; case '30954-2': $this->index['results'] = $index; break; case '46240-8': $this->index['encounters'] = $index; break; case '51847-2': $this->index['assessments'] = $index; break; case '46239-0': $this->index['chiefcomplaint'] = $index; break; default: $tplId = isset($component['section']['templateId']['@attributes']['root']) ? $component['section']['templateId']['@attributes']['root'] : ''; if ($tplId == '2.16.840.1.113883.10.20.22.2.21.1') { $this->index['advancedirectives'] = $index; } break; } } }
function getXMLDocument() { try { $filePointer = "../reports/{$this->reportDir}/reportStatement.sql"; if (file_exists($filePointer) && is_readable($filePointer)) { // Important connection parameter, this will allow multiple // prepare tags with the same name. $this->conn = Matcha::getConn(); $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // Get the report SQL statement content $fileContent = file_get_contents($filePointer); // Copy all the request variables into the Prepared Values, // also check if it came from the grid form and normal form. // This because we need to do a POST-PREPARE the SQL statement foreach ($this->request as $field) { $PrepareField[':' . $field['name']]['operator'] = isset($field['operator']) ? $field['operator'] : '='; $PrepareField[':' . $field['name']]['value'] = $field['value']; } // Copy all the request filter variables to the XML, // also check if it came from the grid form and normal form. // This because we need to do a POST-PREPARE the SQL statement foreach ($this->request as $field) { $ReturnFilter[$field['name']]['operator'] = isset($field['operator']) ? $field['operator'] : '='; $ReturnFilter[$field['name']]['value'] = $field['value']; } // Prepare all the variable fields in the SQL Statement $PreparedSQL = $this->PostPrepare($fileContent, $PrepareField); $Queries = explode(';', $PreparedSQL); // Run all the SQL Statement separated by `;` in the file foreach ($Queries as $Query) { if (strlen(trim($Query)) > 0) { $SQL = $this->conn->prepare($Query); $SQL->execute(); $records[] = $SQL->fetchAll(PDO::FETCH_ASSOC); } } $ExtraAttributes['xml-stylesheet'] = 'type="text/xsl" href="report.xsl"'; Array2XML::init('1.0', 'UTF-8', true, $ExtraAttributes); $xml = Array2XML::createXML('records', array('filters' => $ReturnFilter, 'record' => $records[count($records) - 1])); return $xml->saveXML(); } else { throw new Exception('Error: Not SQL Statement file was found or readable.'); } } catch (Exception $Error) { error_log(print_r($Error, true)); return $Error; } }
function translateOneNode($currentNodeID, $to_languages, $content_type) { global $db, $XMLarray, $error_log; $separator = "7543545165934149"; // Fetch a node from Drupal if a copy does not already exist in sources dir. // $xml_MASTER is the original English-language version // $xml is the copy that will be translated $fn = getcwd() . "/sources/SOURCE_" . $currentNodeID . ".XML"; if (file_exists($fn)) { $xml_MASTER = file_get_contents($fn); if ($content_type == "page") { // Remove <teaser> from "page". The "teaser" is created by truncating the <body>, resulting in invalid XML $xml_MASTER = preg_replace("|<teaser>.*?</teaser>|us", "<teaser></teaser>", $xml_MASTER); } } else { $xml_MASTER = fetchOneNode($currentNodeID); if ($content_type == "page") { $xml_MASTER = preg_replace("|<teaser>.*?</teaser>|us", "<teaser></teaser>", $xml_MASTER); } $fh = fopen($fn, "w"); fwrite($fh, $xml_MASTER); fclose($fh); } foreach ($to_languages as $to_language) { $query = "select drupal_code from sovee.languages where sovee_code = '" . $to_language . "'"; $result = mysql_query($query, $db); while ($row = mysql_fetch_assoc($result)) { $drupalLanguageCode = $row['drupal_code']; } mysql_free_result($result); echo "\n=====================================================================================\n========== ==========\n. . . Translating node {$currentNodeID} ({$content_type}) into {$to_language} . . . \n"; $error_IncompleteNodeFlag = 0; $xml = $xml_MASTER; // Create a copy of the master, to be translated // Convert XML to array $XMLarray = XML2Array::createArray($xml); // Get info about the node // Requested info is placed in the $requestedTags array // and returned in the assoc. array info() $requestedTags = array("type", "tnid"); $info = getXMLinfo($xml, $requestedTags); $derivedContentType = $info['type']; // Build list of containers to parse for the given content_type. $query = "select DISTINCT sovee.node_fields.name from sovee.content_type \nLEFT JOIN sovee.field_map ON sovee.content_type.id = sovee.field_map.content_id\nLEFT JOIN sovee.node_fields ON sovee.node_fields.id = sovee.field_map.field_id\nWHERE sovee.content_type.name = '" . $derivedContentType . "'"; $result = mysql_query($query, $db); while ($row = mysql_fetch_assoc($result)) { $containerArrayTemplate[] = $row['name']; } mysql_free_result($result); // Walk throught the array, extract the specified containers, translate // and replace in the array // All array elements are assumed to be in the [node_export][node] array // $containerArrayTemplate = array("body", "title", "teaser", "field_product_subtitle|n*|value", "field_warranty|n*|value", "field_product_education|n*|value", // "field_prod_man_docs_link|n*|title", // "field_did_you_know|n*|value", "field_product_benefits|n*|value", "nodewords|copyright|value", "nodewords|dcterms.contributor|value", // "nodewords|dcterms.title|value", "nodewords|description|value", "nodewords|keywords|value" ); $containerArray = expandTemplate($containerArrayTemplate); $allContainers = "<div>{$separator}"; foreach ($containerArray as $oneContainer) { echo "\nProcessing container {$oneContainer}\n"; $parents = explode("|", $oneContainer); array_unshift($parents, "node_export", "node"); #echo "Parents: "; #print_r($parents); $XMLfragment = drupal_array_get_nested_value($XMLarray, $parents); if (is_array($XMLfragment)) { $XMLfragment = ""; } $translatedFragment = ""; $patterns = array("|^<div>|us", "|</div>\$|us"); // The "|u" flag enables multibyte support $replacements = array("", ""); if (strlen(trim($XMLfragment)) > 0 and !is_array($XMLfragment)) { $XMLfragment = "<div>" . $XMLfragment . "</div>"; // Encapsulate in dummy <div> to satisfy Sovee translator // echo "ORIGINAL Fragment = |$XMLfragment|\n"; } else { echo "Original Fragment |{$XMLfragment}| is empty -- skipping.\n"; } $allContainers .= $XMLfragment . $separator; // Add at the end of each container to faciliate preg_split } // ------- End of foreach($containerArray as $oneContainer) $allContainers .= "</div>"; // Translate the entire node if target language is not English echo "TO_LANGUAGE = {$to_language}\n"; $xxx = substr($to_language, 0, 2); echo "SUBSTR = |{$xxx}|\n"; $sovee_to_language = $to_language; if (substr($to_language, 0, 2) != "en") { if ($to_language == "es-419") { $sovee_to_language = "es-es"; } // Use standard Spanish for Latin America echo "Sending strings to Sovee . . . \n"; $translatedFragmentAry = translateFrag($allContainers, $currentNodeID, "FULL NODE", $to_language); // Perform the translation $translatedFragment = $translatedFragmentAry['content']; $translatedFragmentError = $translatedFragmentAry['error_count']; // Count of translation errors. 0 = success $error_IncompleteNodeFlag += $translatedFragmentError; } else { echo "English-to-English: No translation needed.\n"; $translatedFragment = $allContainers; $translatedFragmentError = 0; } // print_r($translatedFragmentAry); $separatorPattern = "/{$separator}/u"; $translatedNodeAry = preg_split($separatorPattern, $translatedFragment); // print_r($translatedNodeAry); $translatedContentPointer = 1; reset($containerArray); foreach ($containerArray as $oneContainer) { $parents = explode("|", $oneContainer); array_unshift($parents, "node_export", "node"); $stripped = trim(preg_replace($patterns, $replacements, $translatedNodeAry[$translatedContentPointer])); // Remove the leading and trailing <div>s from the node fragments // Special handling for page_title, which can be a string or an array if ($oneContainer == "page_title" and $stripped == "Array") { $pageTitleParents1 = array('node_export', 'node', 'page_title', 'value'); $pageTitleParents2 = array('node_export', 'node', 'page_title', 'attributes', 'type'); drupal_array_set_nested_value($XMLarray, $pageTitleParents1, "FALSE"); drupal_array_set_nested_value($XMLarray, $pageTitleParents2, "boolean"); } else { if (strlen($stripped) > 0) { drupal_array_set_nested_value($XMLarray, $parents, $stripped); } } $translatedContentPointer++; } // HTML-Encode any info in the <data> container // $dataParents = array('node_export', 'node', 'data'); // $dataFragment = htmlentities(drupal_array_get_nested_value($XMLarray, $dataParents)); // drupal_array_set_nested_value($XMLarray, $dataParents, $dataFragment); #echo "TRANSLATED XML ARRAY:"; #print_r($XMLarray); // Does an older version of this translated node exist? // If yes, return the node# and alias in an array // otherwise, $oldNodeID_ary['number'] == '' $oldNodeID_ary = findOldTranslation($currentNodeID, $to_language); $oldNodeID = $oldNodeID_ary['number']; $oldNodeIDalias = $oldNodeID_ary['url_alias']; if ($oldNodeID != "") { echo "\nFound old node number -- old={$oldNodeID}\n"; } if ($oldNodeIDalias != "") { echo "\nFound old node number alias -- old={$oldNodeIDalias}\n"; } // Update the nid and tnid fields // For new nodes, nid='' // and tnid = the current nid value $XMLarray['node_export']['node']['tnid'] = $currentNodeID; $XMLarray['node_export']['node']['nid'] = $oldNodeID; // $XMLarray['node_export']['node']['language'] = $oldNodeID['drupal_lang_code']; $XMLarray['node_export']['node']['language'] = $drupalLanguageCode; // // // $XMLarray['node_export']['node']['path'] = $oldNodeID['url_alias']; if (isset($XMLarray['node_export']['node']['xmlsitemap']['language'])) { // $XMLarray['node_export']['node']['xmlsitemap']['language'] = $oldNodeID['drupal_lang_code']; $XMLarray['node_export']['node']['xmlsitemap']['language'] = $drupalLanguageCode; } //echo "XMLARRAY = \n"; //print_r($XMLarray); $FOO = $XMLarray['node_export']['node']['nodewords']['location']['latitude']; $BAR = $XMLarray['node_export']['node']['nodewords']['location']['longitude']; echo "FOO = {$FOO}\nBAR = {$BAR}\n"; // If lat or long > 8 chars, set to zero, otherwise node will not import if (isset($XMLarray['node_export']['node']['nodewords']['location']['latitude'])) { if (strlen($XMLarray['node_export']['node']['nodewords']['location']['latitude']) > 8) { $XMLarray['node_export']['node']['nodewords']['location']['latitude'] = 0; } } if (isset($XMLarray['node_export']['node']['nodewords']['location']['longitude'])) { if (strlen($XMLarray['node_export']['node']['nodewords']['location']['longitude']) > 8) { $XMLarray['node_export']['node']['nodewords']['location']['longitude'] = 0; } } // Adjust the menu references $this_plid = $XMLarray['node_export']['node']['menu']['plid']; $this_menu_name = $XMLarray['node_export']['node']['menu']['menu_name']; if ($this_menu_name == "primary-links") { $mquery = "SELECT t_menuid from sovee.menus LEFT JOIN sovee.languages on sovee.menus.language_code = sovee.languages.id WHERE drupal_code = \"" . $drupalLanguageCode . "\" and Eng_menuid = \"" . $this_plid . "\""; echo "MQ = {$mquery}\n"; $rmquery = mysql_query($mquery, $db); $err_msg = trim(mysql_error($db)); if (strlen($err_msg) > 0) { echo "{$mquery}\n{$err_msg}\n\n\n"; } while ($m1 = mysql_fetch_assoc($rmquery)) { $newPlid = $m1['t_menuid']; $XMLarray['node_export']['node']['menu']['plid'] = $newPlid; } mysql_free_result($rmquery); } // Convert array back to XML $encoding = "UTF-8"; $xmlVersion = "1.0"; Array2XML::init($xmlVersion, $encoding); $xmlobj = Array2XML::createXML('DELETE_ME', $XMLarray); // Convert a PHP array to XML, using 'DELETE_ME' as the root_node_name $translated_xml = $xmlobj->saveXML(); // Returned object is of type DOMDocument $translated_xml = preg_replace("/<[\\/]?DELETE_ME>[\n]/u", "", $translated_xml); $fn = getcwd() . "/TRANSLATED_" . $drupalLanguageCode . "_" . $currentNodeID . ".XML"; echo "WRITING {$fn}\n"; $fh = fopen($fn, "w"); fwrite($fh, $translated_xml); fclose($fh); // If node translation was successful, // import the translated node back into Drupal if ($error_IncompleteNodeFlag == 0) { $cmd = "/usr/bin/drush --root=/var/www/pressflow node-export-import --file={$fn}"; echo "COMMAND = {$cmd}\n"; $success = `{$cmd}`; $error = "DRUSH IMPORT RESULTS: {$success}\n"; echo $error; fwrite($error_log, $error); $cmd = "/bin/rm {$fn}"; #$success = `$cmd`; $q1 = "INSERT INTO sovee.progress (node, status, type, language) VALUES(\"" . $currentNodeID . "\", \"1\", \"" . $derivedContentType . "\", \"" . $to_language . "\") ON DUPLICATE KEY UPDATE status=VALUES(status)"; echo "Q1={$q1}\n"; $r1 = mysql_query($q1, $db); } else { $error = "Node {$currentNodeID} ({$content_type}) not completely translated. Not importing into Drupal.\n"; echo $error; $q1 = "INSERT INTO sovee.progress (node, status, type, language) VALUES(\"" . $currentNodeID . "\", \"0\", \"" . $derivedContentType . "\", \"" . $to_language . "\") ON DUPLICATE KEY UPDATE status=VALUES(status)"; $r1 = mysql_query($q1, $db); $err_msg = trim(mysql_error($db)); if (strlen($err_msg) > 0) { echo "{$q1}\n{$err_msg}\n\n\n"; } fwrite($error_log, $error); } echo "========== ==========\n=====================================================================================\n"; } $translated_xml_array = array('status' => $error_IncompleteNodeFlag, 'translated_xml' => $translated_xml); return $translated_xml_array; }
$nodo = array(); foreach ($campos as $x => $val) { $nodo[$val] = $_POST[$val][$i]; if (!$nodo[$val] || empty($nodo[$val])) { $errores[] = "No value for " . $val . " " . $i; } } $nodo["@attributes"] = array("id" => $_POST['id'][$i]); $TelevisionArrForm[] = $nodo; //krumo($nodo); } //krumo($TelevisionArrForm); $Television = array("Televisions" => array("Television" => $TelevisionArrForm, "@attributes" => array("noNamespaceSchemaLocation" => "Televisions.xsd"))); //krumo($Televisions); if (empty($errores)) { $Array2XML = Array2XML::init('1.0', 'iso-8859-1'); $outputDestXML = Array2XML::createXML('Televisions', $Television); $xmlString = $outputDestXML->saveXML(); $xmlString = utf8_encode($xmlString); $xmlDestinoFile = $_SESSION['workfolder_webdir'] . "Television.xml"; $fp = fopen($xmlDestinoFile, 'w'); fwrite($fp, $xmlString); fclose($fp); } else { $message = "<h3>Errores al parsear </h3>" . implode("<br>", $errores); } } /*$xml = simplexml_load_file($xmlDestino, 'SimpleXMLElement',LIBXML_NOCDATA); $json = json_encode($xml); $XMLarray = json_decode($json,TRUE); krumo($XMLarray);*/
/** * Method buildCCD() */ public function createCCD() { try { if (!isset($this->pid)) { throw new Exception('PID variable not set'); } $this->xmlData = ['@attributes' => ['xmlns' => 'urn:hl7-org:v3', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:hl7-org:v3 CDA.xsd']]; if (isset($this->eid)) { $this->encounter = $this->Encounter->getEncounter((int) $this->eid, false, false); $this->encounter = isset($this->encounter['encounter']) ? $this->encounter['encounter'] : $this->encounter; $this->encounterProvider = $this->User->getUserByUid($this->encounter['provider_uid']); $this->encounterFacility = $this->Facilities->getFacility($this->encounter['facility']); } $this->setRequirements(); $this->setHeader(); /** * Array of sections to include in CCD */ $sections = ['ReasonOfVisit', 'Instructions', 'ReasonForReferral', 'Procedures', 'Vitals', 'Immunizations', 'Medications', 'MedicationsAdministered', 'PlanOfCare', 'CareOfPlan', 'Problems', 'Allergies', 'SocialHistory', 'Results', 'FunctionalStatus']; /** * Run Section method for each section */ foreach ($sections as $Section) { call_user_func([$this, "set{$Section}Section"]); } /** * Build the CCR XML Object */ Array2XML::init('1.0', 'UTF-8', true, ['xml-stylesheet' => 'type="text/xsl" href="' . URL . '/lib/CCRCDA/schema/cda2.xsl"']); $this->xml = Array2XML::createXML('ClinicalDocument', $this->xmlData); } catch (Exception $e) { print $e->getMessage(); } }
function getXMLDocument() { try { $this->conn = Matcha::getConn(); $filePointer = "../reports/{$this->reportDir}/reportStatement.sql"; // Important connection parameter, this will allow multiple // prepare tags with the same name. $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); if (file_exists($filePointer) && is_readable($filePointer)) { // Get the SQL content $fileContent = file_get_contents($filePointer); $RunSQL = $this->conn->prepare($fileContent); // Copy all the request variables into the ExecuteValues foreach ($this->request as $field) { $PrepareField[':' . $field['name']] = $field['value']; } // Also copy all the request variables to Return variable to XML foreach ($this->request as $field) { $ReturnFilter[$field['name']] = $field['value']; } $RunSQL->execute($PrepareField); $records = $RunSQL->fetchAll(PDO::FETCH_ASSOC); $ExtraAttributes['xml-stylesheet'] = 'type="text/xsl" href="report.xsl"'; Array2XML::init('1.0', 'UTF-8', true, $ExtraAttributes); $xml = Array2XML::createXML('records', array('filters' => $ReturnFilter, 'record' => $records)); return $xml->saveXML(); } else { throw new Exception('Error: Not SQL Statement file was found or is readable.'); } } catch (Exception $Error) { error_log(print_r($Error, true)); return $Error; } }
/** * Build the CCR XML Object */ Array2XML::init('1.0', 'UTF-8', true, array('xml-stylesheet' => 'type="text/xsl" href="' . $_SESSION['url'] . 'lib/CCRCDA/schema/ccr.xsl"')); $xml = Array2XML::createXML('ContinuityOfCareRecord', $ccrArray); /** * Show the document inline */ header('Content-type: application/xml'); echo $xml->saveXML(); } if ($_REQUEST['action'] == 'ccrexport') { /** * Build the CCR XML Object */ Array2XML::init('1.0', 'UTF-8', true, array('xml-stylesheet' => 'type="text/xsl" href="ccr.xsl"')); $xml = Array2XML::createXML('ContinuityOfCareRecord', $ccrArray); /** * Create a ZIP archive for delivery */ $zip = new ZipArchive(); $tempDirectory = $_SESSION['site']['temp']['path'] . '/'; $filename = $pid . "-" . $patientData['fname'] . $patientData['lname']; if ($zip->open($tempDirectory . $filename . ".zip", ZipArchive::CREATE) !== TRUE) { exit("cannot open <{$filename}.zip>\n"); } $zip->addFromString($filename . ".xml", $xml->saveXML()); $zip->addFromString("ccr.xsl", file_get_contents(ROOT . '/lib/CCRCDA/schema/ccr.xsl')); $zip->close(); /** * Stream the file to the client