PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/custom/import_xml.php

https://github.com/bigwillystyle/openemr
PHP | 213 lines | 178 code | 23 blank | 12 comment | 46 complexity | 88daa9b5979c126321c99a3146b5e463 MD5 | raw file
  1. <?php
  2. // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. /////////////////////////////////////////////////////////////////////
  9. // This imports patient demographics from our custom XML format.
  10. /////////////////////////////////////////////////////////////////////
  11. include_once("../interface/globals.php");
  12. include_once("$srcdir/patient.inc");
  13. include_once("$srcdir/acl.inc");
  14. function setInsurance($pid, $ainsurance, $asubscriber, $seq) {
  15. $iwhich = $seq == '2' ? "secondary" : ($seq == '3' ? "tertiary" : "primary");
  16. newInsuranceData(
  17. $pid,
  18. $iwhich,
  19. $ainsurance["provider$seq"],
  20. $ainsurance["policy$seq"],
  21. $ainsurance["group$seq"],
  22. $ainsurance["name$seq"],
  23. $asubscriber["lname$seq"],
  24. $asubscriber["mname$seq"],
  25. $asubscriber["fname$seq"],
  26. $asubscriber["relationship$seq"],
  27. $asubscriber["ss$seq"],
  28. fixDate($asubscriber["dob$seq"]),
  29. $asubscriber["street$seq"],
  30. $asubscriber["zip$seq"],
  31. $asubscriber["city$seq"],
  32. $asubscriber["state$seq"],
  33. $asubscriber["country$seq"],
  34. $asubscriber["phone$seq"],
  35. $asubscriber["employer$seq"],
  36. $asubscriber["employer_street$seq"],
  37. $asubscriber["employer_city$seq"],
  38. $asubscriber["employer_zip$seq"],
  39. $asubscriber["employer_state$seq"],
  40. $asubscriber["employer_country$seq"],
  41. $ainsurance["copay$seq"],
  42. $asubscriber["sex$seq"]
  43. );
  44. }
  45. // Check authorization.
  46. $thisauth = acl_check('patients', 'demo');
  47. if ($thisauth != 'write')
  48. die("Updating demographics is not authorized.");
  49. if ($_POST['form_import']) {
  50. $apatient = array();
  51. $apcp = array();
  52. $aemployer = array();
  53. $ainsurance = array();
  54. $asubscriber = array();
  55. // $probearr is an array of tag names corresponding to the current
  56. // container in the tree structure. $probeix is the current level.
  57. $probearr = array('');
  58. $probeix = 0;
  59. $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
  60. $parser = xml_parser_create();
  61. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  62. $xml = array();
  63. if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
  64. foreach ($xml as $taginfo) {
  65. $tag = strtolower($taginfo['tag']);
  66. $tagtype = $taginfo['type'];
  67. $tagval = addslashes($taginfo['value']);
  68. if ($tagtype == 'open') {
  69. ++$probeix;
  70. $probearr[$probeix] = $tag;
  71. continue;
  72. }
  73. if ($tagtype == 'close') {
  74. --$probeix;
  75. continue;
  76. }
  77. if ($tagtype != 'complete') {
  78. die("Invalid tag type '$tagtype'");
  79. }
  80. if ($probeix == 1 && $probearr[$probeix] == 'patient') {
  81. $apatient[$tag] = $tagval;
  82. }
  83. else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
  84. $apcp[$tag] = $tagval;
  85. }
  86. else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
  87. $aemployer[$tag] = $tagval;
  88. }
  89. else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
  90. if ($tag == 'priority') {
  91. $inspriority = $tagval;
  92. } else {
  93. $ainsurance["$tag$inspriority"] = $tagval;
  94. }
  95. }
  96. else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
  97. $asubscriber["$tag$inspriority"] = $tagval;
  98. }
  99. else {
  100. $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
  101. }
  102. }
  103. } else {
  104. $alertmsg = "Invalid import data!";
  105. }
  106. xml_parser_free($parser);
  107. $olddata = getPatientData($pid);
  108. if ($olddata['squad'] && ! acl_check('squads', $olddata['squad']))
  109. die("You are not authorized to access this squad.");
  110. newPatientData(
  111. $olddata['id'],
  112. $apatient['title'],
  113. $apatient['fname'],
  114. $apatient['lname'],
  115. $apatient['mname'],
  116. $apatient['sex'],
  117. $apatient['dob'],
  118. $apatient['street'],
  119. $apatient['zip'],
  120. $apatient['city'],
  121. $apatient['state'],
  122. $apatient['country'],
  123. $apatient['ss'],
  124. $apatient['occupation'],
  125. $apatient['phone_home'],
  126. $apatient['phone_biz'],
  127. $apatient['phone_contact'],
  128. $apatient['status'],
  129. $apatient['contact_relationship'],
  130. $apatient['referrer'],
  131. $apatient['referrerID'],
  132. $apatient['email'],
  133. $apatient['language'],
  134. $apatient['ethnoracial'],
  135. $apatient['interpreter'],
  136. $apatient['migrantseasonal'],
  137. $apatient['family_size'],
  138. $apatient['monthly_income'],
  139. $apatient['homeless'],
  140. fixDate($apatient['financial_review']),
  141. $apatient['pubpid'],
  142. $pid,
  143. $olddata['providerID'],
  144. $apatient['genericname1'],
  145. $apatient['genericval1'],
  146. $apatient['genericname2'],
  147. $apatient['genericval2'],
  148. $apatient['phone_cell'],
  149. $apatient['hipaa_mail'],
  150. $apatient['hipaa_voice'],
  151. $olddata['squad']
  152. );
  153. newEmployerData(
  154. $pid,
  155. $aemployer['name'],
  156. $aemployer['street'],
  157. $aemployer['zip'],
  158. $aemployer['city'],
  159. $aemployer['state'],
  160. $aemployer['country']
  161. );
  162. setInsurance($pid, $ainsurance, $asubscriber, '1');
  163. setInsurance($pid, $ainsurance, $asubscriber, '2');
  164. setInsurance($pid, $ainsurance, $asubscriber, '3');
  165. echo "<html>\n<body>\n<script language='JavaScript'>\n";
  166. if ($alertmsg) echo " alert('$alertmsg');\n";
  167. echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
  168. echo " window.close();\n";
  169. echo "</script>\n</body>\n</html>\n";
  170. exit();
  171. }
  172. ?>
  173. <html>
  174. <head>
  175. <?php html_header_show();?>
  176. <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
  177. <title><?php xl('Import Patient Demographics','e'); ?></title>
  178. </head>
  179. <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
  180. <p><?php xl('Paste the data to import into the text area below:','e'); ?></p>
  181. <center>
  182. <form method='post' action="import_xml.php">
  183. <textarea name='form_import_data' rows='10' cols='50' style='width:95%'></textarea>
  184. <p>
  185. <input type='submit' name='form_import' value=<?php xl('Import Patient','e','\'','\''); ?> /> &nbsp;
  186. <input type='button' value=<?php xl('Cancel','e','\'','\''); ?> onclick='window.close()' /></p>
  187. </form>
  188. </center>
  189. </body>
  190. </html>