minor bug fix
[openemr.git] / library / freeb / Diagnosis.class.php
blob0c14e067743edd0b6ee42663a95ef5eb3859b35e
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Diagnosis Extends DataObjectBase {
7 function Diagnosis() {
8 $this->_addFunc("relatedtohcfa", array( "name" => "FreeB.FBDiagnosis.RelatedToHCFA",
9 "sig" => array(XMLRPCSTRING,XMLRPCINT),
10 "doc" => ""));
11 $this->_addFunc("isrelatedtootheraccident", array( "name" => "FreeB.FBDiagnosis.isRelatedToOtherAccident",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("dateofencounter", array("name" => "FreeB.FBDiagnosis.DateOfEncounter",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("dateofonset", array( "name" => "FreeB.FBDiagnosis.DateOfOnset",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("dateoffirstsymptom", array( "name" => "FreeB.FBDiagnosis.DateOfFirstSymptom",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("isfirstoccurence", array( "name" => "FreeB.FBDiagnosis.isFirstOccurrence",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("dateoffirstoccurence", array( "name" => "FreeB.FBDiagnosis.DateOfFirstOccurrence",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("iscantwork", array( "name" => "FreeB.FBDiagnosis.isCantWork",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("dateofcantworkstart", array( "name" => "FreeB.FBDiagnosis.DateOfCantWorkStart",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("dateofcantworkend", array( "name" => "FreeB.FBDiagnosis.DateOfCantWorkEnd",
36 "sig" => array(XMLRPCSTRING,XMLRPCINT),
37 "doc" => ""));
38 $this->_addFunc("isrelatedtoemployment", array( "name" => "FreeB.FBDiagnosis.isRelatedToEmployment",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT),
40 "doc" => ""));
41 $this->_addFunc("isrelatedtoautoaccident", array( "name" => "FreeB.FBDiagnosis.isRelatedToAutoAccident",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("autoaccidentstate", array( "name" => "FreeB.FBDiagnosis.AutoAccidentState",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT),
46 "doc" => ""));
47 $this->_addFunc("icd10code", array( "name" => "FreeB.FBDiagnosis.ICD10Code",
48 "sig" => array(XMLRPCSTRING,XMLRPCINT),
49 "doc" => ""));
50 $this->_addFunc("icd9code", array( "name" => "FreeB.FBDiagnosis.ICD9Code",
51 "sig" => array(XMLRPCSTRING,XMLRPCINT),
52 "doc" => ""));
53 $this->_addFunc("dateoflastvisit", array( "name" => "FreeB.FBDiagnosis.DateOfLastVisit",
54 "sig" => array(XMLRPCSTRING,XMLRPCINT),
55 "doc" => ""));
56 $this->_addFunc("comment", array( "name" => "FreeB.FBDiagnosis.Comment",
57 "sig" => array(XMLRPCSTRING,XMLRPCINT),
58 "doc" => ""));
61 function relatedtohcfa($m) {
63 $err="";
65 //unimplemented by OpenEMR
66 $retval = "";
68 // if we generated an error, create an error return response
69 if ($err) {
70 return $this->_handleError($err);
72 else {
73 // otherwise, we create the right response
74 // with the state name
75 return new xmlrpcresp(new xmlrpcval($retval,"string"));
79 function isrelatedtootheraccident($m) {
80 $err="";
81 //Now implemented by OpenEMR with Form: Misc Billing Options
82 $pkey = false;
83 $retval = "";
84 $obj= $m->getparam(0);
85 $key = $obj->getval();
87 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
88 //echo $sql;
89 $db = $GLOBALS['adodb']['db'];
90 $results = $db->Execute($sql);
92 if (!$results) {
93 $err = $db->ErrorMsg();
95 else {
96 if (!$results->EOF) {
97 $retval = $results->fields['other_accident'];
98 if ($retval == "1") {$pkey = true;};
101 // if we generated an error, create an error return response
102 if ($err) {
103 return $this->_handleError($err);
105 else {
106 // otherwise, we create the right response
107 // with the state name
108 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
112 function dateofencounter($m) {
113 $err="";
114 $retval ="";
115 $obj= $m->getparam(0);
116 $key = $obj->getval();
118 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] .
119 "' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
120 $db = $GLOBALS['adodb']['db'];
121 $results = $db->Execute($sql);
123 if (!$results) {
124 $err = $db->ErrorMsg();
126 else {
127 if (!$results->EOF) {
128 $retval = $results->fields['date'];
131 $retval = date("Y-m-d",strtotime($retval));
132 $retval = $this->_isodate($retval);
134 // if we generated an error, create an error return response
135 if ($err) {
136 return $this->_handleError($err);
138 else {
139 // otherwise, we create the right response
140 // with the state name
141 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
145 function dateofonset($m) {
147 $err="";
149 $retval ="";
150 $obj= $m->getparam(0);
151 $key = $obj->getval();
153 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
154 //echo $sql;
155 $db = $GLOBALS['adodb']['db'];
156 $results = $db->Execute($sql);
158 if (!$results) {
159 $err = $db->ErrorMsg();
161 else {
162 if (!$results->EOF) {
163 $retval = $results->fields['onset_date'];
166 $retval = date("Y-m-d",strtotime($retval));
167 $retval = $this->_isodate($retval);
169 // if we generated an error, create an error return response
170 if ($err) {
171 return $this->_handleError($err);
173 else {
174 // otherwise, we create the right response
175 // with the state name
176 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
180 function dateoffirstsymptom($m) {
182 $err="";
184 $retval ="";
185 $obj= $m->getparam(0);
186 $key = $obj->getval();
188 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
189 //echo $sql;
190 $db = $GLOBALS['adodb']['db'];
191 $results = $db->Execute($sql);
193 if (!$results) {
194 $err = $db->ErrorMsg();
196 else {
197 if (!$results->EOF) {
198 $retval = $results->fields['onset_date'];
201 $retval = date("Y-m-d",strtotime($retval));
202 $retval = $this->_isodate($retval);
204 // if we generated an error, create an error return response
205 if ($err) {
206 return $this->_handleError($err);
208 else {
209 // otherwise, we create the right response
210 // with the state name
211 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
215 function isfirstoccurence($m) {
217 $err="";
219 //unimplemented by OpenEMR
220 $pkey = false;
222 // if we generated an error, create an error return response
223 if ($err) {
224 return $this->_handleError($err);
226 else {
227 // otherwise, we create the right response
228 // with the state name
229 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
233 function dateoffirstoccurence($m) {
235 $err="";
237 $retval ="";
238 $obj= $m->getparam(0);
239 $key = $obj->getval();
241 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
242 //echo $sql;
243 $db = $GLOBALS['adodb']['db'];
244 $results = $db->Execute($sql);
246 if (!$results) {
247 $err = $db->ErrorMsg();
249 else {
250 if (!$results->EOF) {
251 $retval = $results->fields['onset_date'];
254 $retval = date("Y-m-d",strtotime($retval));
255 $retval = $this->_isodate($retval);
257 // if we generated an error, create an error return response
258 if ($err) {
259 return $this->_handleError($err);
261 else {
262 // otherwise, we create the right response
263 // with the state name
264 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
268 function iscantwork($m) {
269 $err="";
270 //Now implemented by OpenEMR with Form: Misc Billing Options
271 $pkey = false;
272 $retval = "";
273 $obj= $m->getparam(0);
274 $key = $obj->getval();
276 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
277 //echo $sql;
278 $db = $GLOBALS['adodb']['db'];
279 $results = $db->Execute($sql);
281 if (!$results) {
282 $err = $db->ErrorMsg();
284 else {
285 if (!$results->EOF) {
286 $retval = $results->fields['is_unable_to_work'];
287 if ($retval == "1") {$pkey = true;};
290 // if we generated an error, create an error return response
291 if ($err) {
292 return $this->_handleError($err);
294 else {
295 // otherwise, we create the right response
296 // with the state name
297 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
301 function dateofcantworkstart($m) {
302 $err="";
303 //Now implemented by OpenEMR with Form: Misc Billing Options
304 $retval = "";
305 $obj= $m->getparam(0);
306 $key = $obj->getval();
308 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
309 //echo $sql;
310 $db = $GLOBALS['adodb']['db'];
311 $results = $db->Execute($sql);
313 if (!$results) {
314 $err = $db->ErrorMsg();
316 else {
317 if (!$results->EOF) {
318 $retval = $results->fields['off_work_from'];
321 $retval = date("Y-m-d",strtotime($retval));
322 $retval = $this->_isodate($retval);
323 // if we generated an error, create an error return response
324 if ($err) {
325 return $this->_handleError($err);
327 else {
328 // otherwise, we create the right response
329 // with the state name
330 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
335 function dateofcantworkend($m) {
336 $err="";
337 //Now implemented by OpenEMR with Form: Misc Billing Options
338 $retval = "";
339 $obj= $m->getparam(0);
340 $key = $obj->getval();
342 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
343 //echo $sql;
344 $db = $GLOBALS['adodb']['db'];
345 $results = $db->Execute($sql);
347 if (!$results) {
348 $err = $db->ErrorMsg();
350 else {
351 if (!$results->EOF) {
352 $retval = $results->fields['off_work_to'];
355 $retval = date("Y-m-d",strtotime($retval));
356 $retval = $this->_isodate($retval);
357 // if we generated an error, create an error return response
358 if ($err) {
359 return $this->_handleError($err);
361 else {
362 // otherwise, we create the right response
363 // with the state name
364 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
368 function isrelatedtoemployment($m) {
369 $err="";
370 //Now implemented by OpenEMR with Form: Misc Billing Options
371 $pkey = false;
372 $retval = "";
373 $obj= $m->getparam(0);
374 $key = $obj->getval();
376 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
377 //echo $sql;
378 $db = $GLOBALS['adodb']['db'];
379 $results = $db->Execute($sql);
381 if (!$results) {
382 $err = $db->ErrorMsg();
384 else {
385 if (!$results->EOF) {
386 $retval = $results->fields['employment_related'];
387 if ($retval == "1") {$pkey = true;};
390 // if we generated an error, create an error return response
391 if ($err) {
392 return $this->_handleError($err);
394 else {
395 // otherwise, we create the right response
396 // with the state name
397 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
401 function isrelatedtoautoaccident($m) {
402 $err="";
403 //Now implemented by OpenEMR with Form: Misc Billing Options
404 $pkey = false;
405 $retval = "";
406 $obj= $m->getparam(0);
407 $key = $obj->getval();
409 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
410 //echo $sql;
411 $db = $GLOBALS['adodb']['db'];
412 $results = $db->Execute($sql);
414 if (!$results) {
415 $err = $db->ErrorMsg();
417 else {
418 if (!$results->EOF) {
419 $retval = $results->fields['auto_accident'];
420 if ($retval == "1") {$pkey = true;};
423 // if we generated an error, create an error return response
424 if ($err) {
425 return $this->_handleError($err);
427 else {
428 // otherwise, we create the right response
429 // with the state name
430 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
434 function autoaccidentstate($m) {
436 $err="";
437 $retval = "";
438 $obj= $m->getparam(0);
439 $key = $obj->getval();
440 //Now implemented by OpenEMR with Form: Misc_billing_options
441 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
442 //echo $sql;
443 $db = $GLOBALS['adodb']['db'];
444 $results = $db->Execute($sql);
446 if (!$results) {
447 $err = $db->ErrorMsg();
449 else {
450 if (!$results->EOF) {
451 $retval = $results->fields['accident_state'];
454 // if we generated an error, create an error return response
455 if ($err) {
456 return $this->_handleError($err);
458 else {
459 // otherwise, we create the right response
460 // with the state name
461 return new xmlrpcresp(new xmlrpcval($retval,"string"));
466 function icd10code($m) {
468 $err="";
469 //unimplemented by OpenEMR
470 $pkey = "";
472 // if we generated an error, create an error return response
473 if ($err) {
474 return $this->_handleError($err);
476 else {
477 // otherwise, we create the right response
478 // with the state name
479 return new xmlrpcresp(new xmlrpcval($pkey));
482 function icd9code($m) {
484 $err="";
486 $obj= $m->getparam(0);
487 $key = $obj->getval();
489 $sql = "SELECT * FROM billing where id = '" . $key . "'";
490 //echo $sql;
491 $db = $GLOBALS['adodb']['db'];
492 $results = $db->Execute($sql);
494 if (!$results) {
495 $err = $db->ErrorMsg();
497 else {
498 if (!$results->EOF) {
499 $retval = $results->fields['code'];
502 $retval = str_replace("."," ", $retval);
504 // if we generated an error, create an error return response
505 if ($err) {
506 return $this->_handleError($err);
508 else {
509 // otherwise, we create the right response
510 // with the state name
511 return new xmlrpcresp(new xmlrpcval($retval,"string"));
514 function dateoflastvisit($m){
515 $err="";
517 $retval ="";
518 $obj= $m->getparam(0);
519 $key = $obj->getval();
521 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
522 //echo $sql;
523 $db = $GLOBALS['adodb']['db'];
524 $results = $db->Execute($sql);
526 if (!$results) {
527 $err = $db->ErrorMsg();
529 else {
530 if (!$results->EOF) {
531 $retval = $results->fields['date'];
534 $retval = date("Y-m-d",strtotime($retval));
535 $retval = $this->_isodate($retval);
537 // if we generated an error, create an error return response
538 if ($err) {
539 return $this->_handleError($err);
541 else {
542 // otherwise, we create the right response
543 // with the state name
544 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
547 function comment($m){
548 $err="";
550 $retval ="";
551 $obj= $m->getparam(0);
552 $key = $obj->getval();
554 $sql = "SELECT reason FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."'";
555 //echo $sql;
556 $db = $GLOBALS['adodb']['db'];
557 $results = $db->Execute($sql);
559 if (!$results) {
560 $err = $db->ErrorMsg();
562 else {
563 if (!$results->EOF) {
564 $retval = $results->fields['reason'];
568 // if we generated an error, create an error return response
569 if ($err) {
570 return $this->_handleError($err);
572 else {
573 // otherwise, we create the right response
574 // with the state name
575 return new xmlrpcresp(new xmlrpcval($retval,"string"));
579 //'FreeB.FBDiagnosis.RelatedToHCFA' => \&FreeB_FBDiagnosis_RelatedToHCFA,
580 //'FreeB.FBDiagnosis.isRelatedToOtherAccident' => \&FreeB_FBDiagnosis_isRelatedToOtherAccident,
581 //'FreeB.FBDiagnosis.DateOfOnset' => \&FreeB_FBDiagnosis_DateOfOnset,
582 //'FreeB.FBDiagnosis.DateOfFirstSymptom' => \&FreeB_FBDiagnosis_DateOfFirstSymptom,
583 //'FreeB.FBDiagnosis.isFirstOccurrence' => \&FreeB_FBDiagnosis_isFirstOccurence,
584 //'FreeB.FBDiagnosis.DateOfFirstOccurrence' => \&FreeB_FBDiagnosis_DateOfFirstOccurence,
585 //'FreeB.FBDiagnosis.isCantWork' => \&FreeB_FBDiagnosis_isCantWork,
586 //'FreeB.FBDiagnosis.DateOfCantWorkStart' => \&FreeB_FBDiagnosis_DateOfCantWorkStart,
587 //'FreeB.FBDiagnosis.DateOfCantWorkEnd' => \&FreeB_FBDiagnosis_DateOfCantWorkEnd,
588 //'FreeB.FBDiagnosis.isRelatedToEmployment' => \&FreeB_FBDiagnosis_isRelatedToEmployment,
589 //'FreeB.FBDiagnosis.isRelatedToAutoAccident' => \&FreeB_FBDiagnosis_isRelatedToAutoAccident,
590 //'FreeB.FBDiagnosis.AutoAccidentState' => \&FreeB_FBDiagnosis_AutoAccidentState,
591 //'FreeB.FBDiagnosis.ICD10Code' => \&FreeB_FBDiagnosis_ICD9Code,
592 //'FreeB.FBDiagnosis.ICD9Code' => \&FreeB_FBDiagnosis_ICD9Code,?>