bug fix for developer demos
[openemr.git] / myportal / soap_service / server_med_rec.php
blob7680bb4b05bf908a645c5fefa7758a0a6b54f2c3
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
26 // +------------------------------------------------------------------------------+
28 //SANITIZE ALL ESCAPES
29 $sanitize_all_escapes=true;
32 //STOP FAKE REGISTER GLOBALS
33 $fake_register_globals=false;
36 require_once("server_audit.php");
37 class Userforms extends UserAudit{
41 public function issue_type($data){
42 if(UserService::valid($data[0])=='existingpatient'){
43 global $ISSUE_TYPES;
44 require_once("../../library/lists.inc");
45 return $ISSUE_TYPES;
47 else{
48 throw new SoapFault("Server", "credentials failed");
54 public function print_report($data){
55 global $pid;
56 if(UserService::valid($data[0])=='existingpatient'){
57 $repArr = $data[1];
58 $type = $data[3];
59 global $ISSUE_TYPES;
60 require_once("../../library/forms.inc");
61 require_once("../../library/billing.inc");
62 require_once("../../library/pnotes.inc");
63 require_once("../../library/patient.inc");
64 require_once("../../library/options.inc.php");
65 require_once("../../library/acl.inc");
66 require_once("../../library/lists.inc");
67 require_once("../../library/report.inc");
68 require_once("../../library/classes/Document.class.php");
69 require_once("../../library/classes/Note.class.php");
70 require_once("../../library/formatting.inc.php");
71 require_once("../../custom/code_types.inc.php");
72 foreach($repArr as $value){
73 ob_start();
74 if($type=="profile"){
75 $this->getIncudes($value);
76 $out .= ob_get_clean();
78 else{
79 if($type=='issue')
80 $this->getIid($value);
81 if($type=='forms')
82 $this->getforms($value);
83 $out .= ob_get_clean();
87 return $out;
89 else{
90 throw new SoapFault("Server", "credentials failed");
97 public function print_ccr_report($data){
98 if(UserService::valid($data[0])=='existingpatient'){
99 $ccraction = $data[1];
100 $raw = $data[2];
101 require_once("../../ccr/createCCR.php");
102 ob_start();
103 createCCR($ccraction,$raw);
104 $html = ob_get_clean();
105 if($ccraction=='viewccd')
108 $html = preg_replace('/<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD HTML 4.01\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/strict.dtd">/','',$html);
109 $pos1 = strpos($html,'body {');
110 $pos2 = strpos($html,'.h1center');
111 $tes = substr("$html",$pos1,($pos2-$pos1));
112 $html = str_replace($tes,'',$html);
113 $html = str_replace('h3>','h2>',$html);
114 $html = base64_encode($html);
116 else{
117 $pos1 = strpos($html,'*{');
118 $pos2 = strpos($html,'h1');
119 $tes = substr("$html",$pos1,($pos2-$pos1));
120 $html = str_replace($tes,'',$html);
122 return $html;
124 else{
125 throw new SoapFault("Server", "credentials failed");
129 //Return the forms requested from Portal.
131 private function getforms($fId){
132 global $pid;
133 $GLOBALS['pid'] = $pid;
134 $inclookupres = sqlStatement("SELECT DISTINCT formdir FROM forms WHERE pid = ? AND deleted=0",array($pid));
135 while($result = sqlFetchArray($inclookupres)) {
136 $formdir = $result['formdir'];
137 if (substr($formdir,0,3) == 'LBF')
138 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
139 else
140 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
142 $N = 6;
143 $inclookupres = sqlStatement("SELECT encounter,form_id,formdir,id FROM forms WHERE pid = ? AND deleted=0
144 AND id =? ",array($pid,$fId));
145 while($result = sqlFetchArray($inclookupres)) {
146 $form_encounter=$result['encounter'];
147 $form_id=$result['form_id'];
148 $formdir = $result['formdir'];
149 $id=$result['id'];
150 ob_start();
151 if (substr($formdir,0,3) == 'LBF')
152 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $formdir);
153 else
154 call_user_func($formdir . "_report", $pid, $form_encounter, $N, $form_id);
155 $out=ob_get_clean();
156 ?> <table>
157 <tr class=text>
158 <th><?php echo htmlspecialchars($formdir,ENT_QUOTES);?></th>
159 </tr>
160 </table>
161 <?php echo $out;?>
162 <?php
168 private function getIid($val){
169 global $pid;
170 global $ISSUE_TYPES;
171 $inclookupres = sqlStatement("SELECT DISTINCT formdir FROM forms WHERE pid = ? AND deleted=?",array($pid,0));
172 while($result = sqlFetchArray($inclookupres)) {
173 $formdir = $result['formdir'];
174 if (substr($formdir,0,3) == 'LBF')
175 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
176 else
177 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
180 <tr class=text>
181 <td></td>
182 <td>
183 <?php
184 $irow = sqlQuery("SELECT type, title, comments, diagnosis FROM lists WHERE id =? ",array($val));
185 $diagnosis = $irow['diagnosis'];
187 if ($prevIssueType != $irow['type'])
189 $disptype = $ISSUE_TYPES[$irow['type']][0];
191 <div class='issue_type' style='font-weight: bold;'><?php echo htmlspecialchars($disptype,ENT_QUOTES);?>:</div>
192 <?php
193 $prevIssueType = $irow['type'];
196 <div class='text issue'>
197 <span class='issue_title'><?php echo htmlspecialchars($irow['title'],ENT_QUOTES);?>:</span>
198 <span class='issue_comments'><?php echo htmlspecialchars($irow['comments'],ENT_QUOTES);?></span>
199 <?php
200 if ($diagnosis)
203 <div class='text issue_diag'>
204 <span class='bold'>[<?php echo htmlspecialchars(xl('Diagnosis'),ENT_QUOTES);?>]</span><br>
205 <?php
206 $dcodes = explode(";", $diagnosis);
207 foreach ($dcodes as $dcode)
210 <span class='italic'><?php echo htmlspecialchars($dcode,ENT_QUOTES);?></span>:
211 <?php
212 echo htmlspecialchars(lookup_code_descriptions($dcode),ENT_QUOTES);
214 <br>
215 <?php
218 </div>
219 <?php
221 if ($irow['type'] == 'ippf_gcac')
224 <table>
225 <?php
226 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = ?",array($rowid)));
229 </table>
230 <?php
232 else if ($irow['type'] == 'contraceptive')
235 <table>
236 <?php
237 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = ?",array($rowid)));
239 </table>
240 <?php
243 </div>
244 <?php
246 </td>
247 <?php
253 private function getIncudes($val){
254 global $pid;
255 if ($val == "demographics")
258 <hr />
259 <div class='text demographics' id='DEM'>
260 <?php
261 // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
262 $result1 = getPatientData($pid);
263 $result2 = getEmployerData($pid);
265 <table>
266 <tr><td><h6><?php echo htmlspecialchars(xl('Patient Data').":",ENT_QUOTES);?></h6></td></tr>
267 <?php
268 display_layout_rows('DEM', $result1, $result2);
270 </table>
271 </div>
272 <?php
274 elseif ($val == "history")
277 <hr />
278 <div class='text history' id='HIS'>
279 <?php
280 $result1 = getHistoryData($pid);
282 <table>
283 <tr><td><h6><?php echo htmlspecialchars(xl('History Data').":",ENT_QUOTES);?></h6></td></tr>
284 <?php
285 display_layout_rows('HIS', $result1);
287 </table>
288 </div>
289 <?php
291 elseif ($val == "insurance")
294 <hr />
295 <div class='text insurance'>";
296 <h6><?php echo htmlspecialchars(xl('Insurance Data').":",ENT_QUOTES);?></h6>
297 <br><span class=bold><?php echo htmlspecialchars(xl('Primary Insurance Data').":",ENT_QUOTES);?></span><br>
298 <?php
299 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
301 <span class=bold><?php echo htmlspecialchars(xl('Secondary Insurance Data').":",ENT_QUOTES);?></span><br>
302 <?php
303 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
305 <span class=bold><?php echo htmlspecialchars(xl('Tertiary Insurance Data').":",ENT_QUOTES);?></span><br>
306 <?php
307 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
309 </div>
310 <?php
312 elseif ($val == "billing")
315 <hr />
316 <div class='text billing'>
317 <h6><?php echo htmlspecialchars(xl('Billing Information').":",ENT_QUOTES);?></h6>
318 <?php
319 if (count($ar['newpatient']) > 0) {
320 $billings = array();
322 <table>
323 <tr><td width='400' class='bold'><?php echo htmlspecialchars(xl('Code'),ENT_QUOTES);?></td><td class='bold'><?php echo htmlspecialchars(xl('Fee'),ENT_QUOTES);?></td></tr>
324 <?php
325 $total = 0.00;
326 $copays = 0.00;
327 foreach ($ar['newpatient'] as $be) {
328 $ta = split(":",$be);
329 $billing = getPatientBillingEncounter($pid,$ta[1]);
330 $billings[] = $billing;
331 foreach ($billing as $b) {
333 <tr>
334 <td class=text>
335 <?php
336 echo htmlspecialchars($b['code_type'],ENT_QUOTES) . ":\t" .htmlspecialchars( $b['code'],ENT_QUOTES) . "&nbsp;". htmlspecialchars($b['modifier'],ENT_QUOTES) . "&nbsp;&nbsp;&nbsp;" . htmlspecialchars($b['code_text'],ENT_QUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
338 </td>
339 <td class=text>
340 <?php
341 echo htmlspecialchars(oeFormatMoney($b['fee']),ENT_QUOTES);
343 </td>
344 </tr>
345 <?php
346 $total += $b['fee'];
347 if ($b['code_type'] == "COPAY") {
348 $copays += $b['fee'];
352 echo "<tr><td>&nbsp;</td></tr>";
353 echo "<tr><td class=bold>".htmlspecialchars(xl('Sub-Total'),ENT_QUOTES)."</td><td class=text>" . htmlspecialchars(oeFormatMoney($total + abs($copays)),ENT_QUOTES) . "</td></tr>";
354 echo "<tr><td class=bold>".htmlspecialchars(xl('Paid'),ENT_QUOTES)."</td><td class=text>" . htmlspecialchars(oeFormatMoney(abs($copays)),ENT_QUOTES) . "</td></tr>";
355 echo "<tr><td class=bold>".htmlspecialchars(xl('Total'),ENT_QUOTES)."</td><td class=text>" .htmlspecialchars(oeFormatMoney($total),ENT_QUOTES) . "</td></tr>";
356 echo "</table>";
357 echo "<pre>";
358 //print_r($billings);
359 echo "</pre>";
360 } else {
361 printPatientBilling($pid);
363 echo "</div>\n"; // end of billing DIV
365 elseif ($val == "immunizations")
369 <hr />
370 <div class='text immunizations'>
371 <h6><?php echo htmlspecialchars(xl('Patient Immunization').":",ENT_QUOTES);?></h6>
372 <?php
373 $sql = "select i1.immunization_id as immunization_id, if(i1.administered_date,concat(i1.administered_date,' - ') ,substring(i1.note,1,20) ) as immunization_data from immunizations i1 where i1.patient_id = ? order by administered_date desc";
374 $result = sqlStatement($sql,array($pid));
375 while ($row=sqlFetchArray($result)) {
376 echo htmlspecialchars($row{'immunization_data'},ENT_QUOTES);
377 echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
379 <br>
380 <?php
383 </div>
384 <?php
387 elseif ($val == "batchcom")
390 <hr />
391 <div class='text transactions'>
392 <h6><?php htmlspecialchars(xl('Patient Communication sent').":",ENT_QUOTES);?></h6>
393 <?php
394 $sql="SELECT concat( 'Messsage Type: ', batchcom.msg_type, ', Message Subject: ', batchcom.msg_subject, ', Sent on:', batchcom.msg_date_sent ) AS batchcom_data, batchcom.msg_text, concat( users.fname, users.lname ) AS user_name FROM `batchcom` JOIN `users` ON users.id = batchcom.sent_by WHERE batchcom.patient_id=?";
395 $result = sqlStatement($sql,array($pid));
396 while ($row=sqlFetchArray($result)) {
397 echo htmlspecialchars($row{'batchcom_data'}.", ".xl('By').": ".$row{'user_name'},ENT_QUOTES);
399 <br><?php echo htmlspecialchars(xl('Text'),ENT_QUOTES);?>:<br><?php echo htmlspecialchars($row{'msg_txt'},ENT_QUOTES);?><br>
400 <?php
403 </div>
404 <?php
406 elseif ($val == "notes")
409 <hr />
410 <div class='text notes'>
411 <h6><?php echo htmlspecialchars(xl('Patient Notes').":",ENT_QUOTES);?></h6>
412 <?php
413 printPatientNotes($pid);
415 </div>
416 <?php
418 elseif ($val == "transactions")
421 <hr />
422 <div class='text transactions'>
423 <h6><?php echo htmlspecialchars(xl('Patient Transactions').":",ENT_QUOTES);?></h6>
424 <?php
425 printPatientTransactions($pid);
427 </div>
428 <?php