DBC Dutch System
[openemr.git] / library / DBC_Vektis.php
blob3648f4bc935640ff60756401289bcd5f10cd19fd
1 <?php
2 /**
3 * DBC DUTCH SYSTEM
4 * VEKTIS SYSTEM
5 *
6 * @author Cristian NAVALICI
7 * @version 1.0 feb 2008
9 * CAN BE RUN ONLY FROM THE INTERFACE
10 * NEEDS GLOBALS.PHP BEFORE
13 require_once('patient.inc');
14 require_once('DBC_Vektis_constants.php');
16 $dbcidglobal = 0;
17 $patientglobal = 0;
18 $_407global = 1;
19 $filepointer = NULL;
20 $lines2 = 0; // total records for part 2
21 $lines3 = 0; // total records for part 3
22 $lines4 = 0; // total records for part 4
23 $totalclaim = 0; // total insurance claim
24 $uniqueid = 0; // the id for lines 202,402,etc
25 $arr_database = array(); // array with all the values which will be saved into a table
26 $filename = ''; // filename used to write/read vektis stuff (with full path)
28 //-----------------------------------------------------------------------------
29 /**
30 * MAIN FUNCTION
32 * generates the lines for every DBC
34 * @param int $dbcid
35 * @return
37 function vk_main($dbcid) {
38 // set some global variables first
39 global $dbcidglobal;
40 $dbcidglobal = (int)$dbcid;
42 global $patientglobal;
43 $patientglobal = what_patient($dbcid);
45 $lines = array();
46 $lines[] = vk_generate_insurer();
47 //$lines[] = vk_generate_debtor();
48 $lines[] = vk_generate_service();
50 //$line6 = vk_generate_closing() . VK_EOF;
52 foreach ( $lines as $ln ) {
53 $line = $ln."\r\n";
54 vk_write_file($line);
59 //-----------------------------------------------------------------------------
60 /**
61 * INITIALIZATION FUNCTION
63 * must be called BEFORE any other function around here
65 * @param none
66 * @return void
68 function vk_init() {
69 $working_dir = TMPDIR_DBC . '/vektis';
71 // if it's not there, we'll create it
72 if ( !file_exists($working_dir) ) {
73 mkdir($working_dir);
76 // generate the filename and attempt to create it
77 global $filename;
78 $filen = C112.date('dmY').'.txt';
79 $filename = TMPDIR_DBC .'/vektis/'. $filen;
80 $fp = fopen($filename, "wb");
82 global $filepointer, $lines2, $lines3, $lines4, $totalclaim, $uniqueid, $arr_database;
83 $filepointer = $fp;
84 $lines2 = 0; $lines3 = 0; $lines4 = 0; $totalclaim = 0; $uniqueid = 0;
85 $arr_database = array();
87 // generate an unique ID for this vektis session
88 $arr_database['cvd_session'] = vk_vektis_session();
92 //-----------------------------------------------------------------------------
93 /**
94 * FINALIZATION FUNCTION
96 * must be called AFTER any other function around here
98 * @param none
99 * @return void
101 function vk_last() {
102 global $filepointer;
103 if ( $filepointer ) fclose($filepointer);
105 global $arr_database;
106 if ( $arr_database ) $_SESSION['arrdb'] = $arr_database;
109 //-----------------------------------------------------------------------------
111 * GENERATE PREAMBLE
113 * line 01
114 * this appears only one time / generated file (the same as closing line)
116 * @param none
117 * @return string
119 function vk_generate_preamble() {
120 // 0101 ATTRIBUTE RECORD
121 $_101 = '01';
123 // 0102 CODE EXTERNAL INTEGRATION MESSAGE
124 $_102 = C102;
126 // 0103 VERSION NUMBER MESSAGE STANDARD
127 $_103 = C103;
129 // 0104 SUB-VERSION NUMBER MESSAGE STANDARD
130 $_104 = C104;
132 // 0105 MESSAGE TYPE
133 $_105 = C105;
135 // 0106 CODE INFORMATION SYSTEM SOFTWARE VENDOR
136 $_106 = C106;
138 // 0107 VERSION INDICATION INFORMATION SYSTEM SOFTWARE VENDOR
139 $_107 = str_pad(C107, 10, ' ', STR_PAD_LEFT);
141 // 0108 UZOVI-NUMBER
142 $_108 = str_repeat('0', 4); // 4 chars empty string
144 // 0109 CODE SERVICE OFFICE
145 $_109 = C109;
147 // 0110 HEALTHCARE PROVIDER CODE
148 $_110 = str_repeat('0', 8); // 8 chars empty string
150 // 0111 PRAKTIJKCODE
151 $_111 = str_repeat('0', 8); // 8 chars empty string
153 // 0112 Instititution code
154 $_112 = C112;
156 // 0113 IDENTIFYING CODE PAYMENT TO
157 $_113 = C113;
159 // 0114 START DATE CLAIM PERIOD
160 $_114 = date('Ymd', strtotime(date('Ymd')) - (24 * 3600)); // one day before today
162 // 0115 END DATE CLAIM PERIOD
163 $_115 = date('Ymd'); // today
165 // 0116 INVOICE NUMBER PARTICIPANT
166 $_116 = vk_invoice_number();
167 global $arr_database;
168 $arr_database['cvd_116'] = $_116;
170 // 0117 INVOICE DATE
171 $_117 = date('Ymd'); // today
172 $arr_database['cvd_date'] = $_117;
175 // 0118 VAT-IDENTIFICATION NUMBER
176 $_118 = str_repeat(' ', 14); // 14 chars empty string
178 // 0119 CURRENCY CODE
179 $_119 = C119;
181 // 0180 RESERVE
182 $_180 = str_repeat(' ', 193); // 193 chars empty string
184 // concatenate the big string
185 $bigline = '';
186 for ( $i = 1 ; $i <= 19 ; $i++ ) {
187 $avar = sprintf('_1%02s', $i);
188 $bigline .= ${$avar};
191 $bigline .= $_180 . "\r\n";
193 vk_write_file($bigline); // this is written just once per file
197 //-----------------------------------------------------------------------------
199 * GENERATE INSURER RECORD
201 * line 02
203 * @param none
204 * @return void
206 function vk_generate_insurer() {
207 // 0201 ATTRIBUTE RECORD
208 $_201 = '02';
210 // 0202 IDENTIFICATION DETAIL RECORD
211 $_202 = vk_unique_line_record();
213 // 0203 CIVILIAN SERVICE NUMBER (BSN) INSURED
214 $_203 = vk_patientdata('ssn');
216 // 0204 UZOVI-NUMBER
217 $_204 = vk_whatinsurance(1);
218 global $arr_database;
219 $arr_database['cvd_uzovi'][] = $_204;
221 // 0205 INSURED NUMBER (REGISTRATION NUMBER, RELATION NUMBER)
222 $_205 = vk_whatinsurance(2);
224 // 0206 PATIENT (IDENTIFICATION) NUMBER
225 $_206 = vk_patientdata('pid');
226 $arr_database['cvd_pid'][] = $_206;
228 // 0207 DATE OF BIRTH INSURED
229 $_207 = vk_patientdata('dob');
231 // 0208 GENDER CODE INSURED
232 $_208 = vk_patientdata('sex');
234 // 0209 NAME CODE/NAME USAGE (01)
235 $_209 = vk_patientdata('namecode_patient');
237 // 0210 NAME INSURED (01)
238 $_210 = vk_patientdata('namepat');
240 // 0211 PREFIX INSURED (01)
241 $_211 = vk_patientdata('pxnamepat');
243 // 0212 NAME CODE/NAME USAGE (02)
244 $_212 = vk_patientdata('namecode_partner');
246 // 0213 NAME INSURED (02)
247 $_213 = vk_patientdata('namepar');
249 // 0214 PREFIX INSURED (02)
250 $_214 = vk_patientdata('pxnamepar');
252 // 0215 INITIALS INSURED
253 $_215 = vk_patientdata('initials');
255 // 0216 NAME CODE/NAME USAGE (03)
256 $_216 = vk_patientdata('nameusage');
258 //0217 POSTAL CODE (HOME ADDRESS) INSURED
259 $_217 = vk_patientdata('postalcode');
261 //0218 FOREIGN POSTAL CODE
262 $_218 = vk_patientdata('foreignpostalcode');
264 // 0219 STREET NUMBER (HOME ADDRESS) INSURED
265 $_219 = vk_patientdata('stnumber');
267 // 0220 STREET NUMBER AFFIX (HOME ADDRESS) INSURED
268 $_220 = vk_patientdata('stnumberaffix');
270 // 0221 COUNTRY CODE INSURED
271 $_221 = vk_patientdata('countrycode');
273 // 0222 DEBTOR NUMBER
274 $_222 = str_pad(C222, 11, ' ', STR_PAD_LEFT);
276 // 0223 INDICATION CUSTOMER DECEASED
277 $_223 = '2';
279 // 0280 RESERVE
280 $_280 = str_repeat(' ', 129); // 129 chars empty string
282 // concatenate the big string
283 $bigline = '';
284 for ( $i = 1 ; $i <= 23 ; $i++ ) {
285 $avar = sprintf('_2%02s', $i);
286 $bigline .= ${$avar};
287 //echo "LEN $avar " .mb_strlen(${$avar},'UTF-8') . '<br />';
290 $bigline .= $_280;
292 // count the total lines
293 global $lines2;
294 $lines2++;
296 return $bigline;
300 //-----------------------------------------------------------------------------
302 * GENERATE DEBTOR RECORD
304 * line 03
305 * NOTE: we don't use it yet!
307 * @param none
308 * @return string
310 function vk_generate_debtor() {
311 //0301 ATTRIBUTE RECORD
312 $_301 = '03';
314 // the total lenght for this line is 310
315 $line = str_repeat(' ', 308);
317 // count the total lines
318 global $lines3;
319 $lines3++;
321 $bigline = $_301 . $line;
323 return $bigline;
327 //-----------------------------------------------------------------------------
329 * GENERATE SERVICE RECORD
331 * line 04
333 * @param none
334 * @return string
336 function vk_generate_service() {
337 // 0401 ATTRIBUTE RECORD
338 $_401 = '04';
340 // 0402 IDENTIFICATION DETAIL RECORD
341 $_402 = vk_unique_line_record();
343 // 0403 CIVILIAN SERVICE NUMBER (BSN) INSURED
344 $_403 = vk_patientdata('ssn');
346 // 0404 UZOVI-NUMBER
347 $_404 = vk_whatinsurance(1);
349 // 0405 INSURED NUMBER (REGISTRATION NUMBER, RELATION NUMBER)
350 $_405 = vk_whatinsurance(2);
352 // 0406 AUTOMATIC PAYMENT NUMBER
353 $_406 = str_repeat(' ', 15);
355 // 0407 FORWARDING ALLOWED
356 $_407 = C407;
358 // 0408 INDICATION SERVICE CODE LIST
359 $_408 = C408;
361 // 0409 CLAIM CODE
362 $_409 = vk_claimcode('declaratie');
364 // 0410 START DATE
365 $_410 = vk_dbcdates(1);
367 // 0411 END DATE
368 $_411 = vk_dbcdates(2);
370 // 0412 DBC SERVICE CODE
371 $_412 = vk_claimcode('prestatie');
373 // 0413 NUMBER OF SERVICES PERFORMED
374 $_413 = C413;
376 // 0414 HEALTHCARE TRAJECTORY NUMBER
377 $_414 = vk_dbcinfo('ztn');
378 global $arr_database, $dbcidglobal;
379 $arr_database['cvd_ztn'][] = $_414;
380 $arr_database['cvd_dbcid'][] = $dbcidglobal; // we save also dbc id for db
382 // 0415 TYPE OF SPECIALIST
383 $_415 = C415;
385 // 0416 HEALTHCARE PROVIDER CODE
386 $_416 = C112; // agb code
388 // 0417 CALCULATION PERCENTAGE
389 $_417 = C417;
391 // 0418 TARIFF DBC/SERVICE (VAT INCL.)
392 $_418 = vk_dbcinfo('tariff');
394 if ( vk_is_overloop_dbc($dbcidglobal) ) {
395 // 0419 DEDUCTION TYPE
396 $_419 = '04';
398 // 0420 DEDUCTION AMOUNT
399 $dedamo = vk_deduction($dbcidglobal);
400 $_420 = str_pad($dedamo, 8, '0', STR_PAD_LEFT);
401 } else {
402 // 0419 DEDUCTION TYPE
403 $_419 = C419;
405 // 0420 DEDUCTION AMOUNT
406 $_420 = str_pad(C420, 8, '0', STR_PAD_LEFT);
410 // 0421 AMOUNT CHARGED (VAT INCL.)
411 $_421i = round (((int)$_418 * $_417) / 10000);
412 $_421 = str_pad($_421i, 8, '0', STR_PAD_LEFT);
414 // 0422 INDICATION DEBIT/CREDIT (01)
415 $_422 = C422;
417 // 0423 VAT-PERCENTAGE CLAIM AMOUNT
418 $_423 = str_pad(C423, 4, '0', STR_PAD_LEFT);
420 // 0424 CLAIM AMOUNT (VAT INCL.)
421 $_424i = $_421i - $dedamo;
422 if ( $_424i < 0 ) $_424i = 0;
423 $arr_database['cvd_tariff'][] = $_424i;
424 $_424 = str_pad($_424i, 8, '0', STR_PAD_LEFT);
426 // 0425 INDICATION DEBIT/CREDIT (02)
427 $_425 = C422;
429 // 0426 REFERENCE NUMBER THIS SERVICE RECORD
430 $_426 = vk_invoice_service();
431 $arr_database['cvd_426'][] = $_426;
433 // 0427 REFERENCE NUMBER PRECEDING RELATED SERVICE RECORD
434 $_427 = str_pad(C427, 20, ' ', STR_PAD_LEFT);
436 // 0480 RESERVE
437 $_480 = str_repeat(' ', 94); // 94 chars empty string
439 // concatenate the big string
440 $bigline = '';
441 for ( $i = 1 ; $i <= 27 ; $i++ ) {
442 $avar = sprintf('_4%02s', $i);
443 $bigline .= ${$avar};
446 $bigline .= $_480;
448 // count the total lines
449 global $lines4, $totalclaim;
450 $lines4++;
451 $totalclaim += $_424i;
453 return $bigline;
457 //-----------------------------------------------------------------------------
459 * GENERATE COMMENT
461 * line 05
462 * NOTE: we don't use it yet!
464 * @param none
465 * @return string
467 function vk_generate_comment() {
468 //9801 ATTRIBUTE RECORD
469 $_9801 = '98';
471 // the total lenght for this line is 310
472 $line = str_repeat(' ', 308);
474 $bigline = $_9801 . $line;
476 return $bigline;
480 //-----------------------------------------------------------------------------
482 * GENERATE CLOSING RECORD
484 * line 06
486 * @param none
487 * @return string
489 function vk_generate_closing() {
490 global $lines2, $lines3, $lines4, $totalclaim;
492 //9901 ATTRIBUTE RECORD
493 $_9901 = '99';
495 //9902 NUMBER OF INSURED RECORDS
496 $_9902 = str_pad($lines2, 6, '0', STR_PAD_LEFT);
498 //9903 NUMBER OF DEBTOR RECORDS
499 $_9903 = str_pad($lines3, 6, '0', STR_PAD_LEFT);
501 //9904 NUMBER OF SERVICE RECORDS
502 $_9904 = str_pad($lines4, 6, '0', STR_PAD_LEFT);
504 //9905 NUMBER OF COMMENT RECORDS
505 $_9905 = '000000';
507 //9906 TOTAL NUMBER OF DETAIL RECORDS
508 $sumrow = (int)($_9902 + $_9903 + $_9904 + $_9905);
509 $_9906 = str_pad($sumrow, 7, '0', STR_PAD_LEFT);
511 //9907 TOTAL CLAIM AMOUNT
512 $_9907 = str_pad($totalclaim, 11, '0', STR_PAD_LEFT);
514 //9908 INDICATION DEBIT/CREDIT
515 $_9908 = 'D';
517 // 9980 RESERVE
518 $_9980 = str_repeat(' ', 265); // 265 chars empty string
520 // concatenate the big string
521 $bigline = '';
522 for ( $i = 1 ; $i <= 8 ; $i++ ) {
523 $avar = sprintf('_99%02s', $i);
524 $bigline .= ${$avar};
527 $bigline .= $_9980. "\r\n";
528 vk_write_file($bigline); // this is written just once per file
534 //-----------------------------------------------------------------------------
535 //-----------------------------------------------------------------------------
536 //-----------------------------------------------------------------------------
538 * FIND UZOVI CODE / POLICY NUMBER FOR THIS DBC
540 * @param int $uzflag = 1 returns uzovi code; $uzflag != 1 returns policy code
541 * @return string
543 function vk_whatinsurance($uzflag = 1) {
544 global $patientglobal;
545 $insurer = get_insurers_nl($patientglobal, 1);
546 $uzovi = $insurer['pin_provider'];
547 $policy = $insurer['pin_policy'];
549 if ( !$uzovi ) {
550 global $_407global;
551 $_407global = 2;
552 $policy = '';
555 $retval = ( $uzflag == 1 ) ? str_pad($uzovi, 4, '0', STR_PAD_LEFT) : str_pad($policy, 15, ' ', STR_PAD_LEFT);
556 return $retval;
560 //-----------------------------------------------------------------------------
562 * GENERATE INVOICE NUMBER
564 * unique invoice number format YYYYMMDD0001
565 * It permits max 9999 invoice / day !
567 * @param none
568 * @return string
570 function vk_invoice_number() {
571 $date = date('Ymd');
573 // retrieve auxiliary values
574 $rd = mysql_query("SELECT * FROM cl_aux WHERE aux_id = 'vk_0116_invoice'") or die(mysql_error());
575 $rez = mysql_fetch_array($rd);
577 // if date strings are NOT equal, then we must update the date field with today value
578 // and reset the counter (aux_varn) to 0
579 if ( $date !== trim($rez['aux_varc']) ) {
580 $current_number = 1;
581 } else {
582 // we are in the same day, so we'll use the value from aux_varn (numeric)
583 $current_number = $rez['aux_varn'] + 1;
584 } // if else
586 // update the auxiliary tables with the new values
587 $qu = sprintf("UPDATE cl_aux SET aux_varc = '%s', aux_varn = %d WHERE aux_id = 'vk_0116_invoice'", $date, $current_number);
588 mysql_query($qu) or die(mysql_error());
590 $uniqID = $date . str_pad($current_number, 4, '0', STR_PAD_LEFT);
591 return $uniqID;
594 //-----------------------------------------------------------------------------
596 * GENERATE INVOICE NUMBER FOR EVERY DBC (SERVICE)
598 * unique invoice number format 253-0001 (patient id from openemr + unique number)
599 * the last number is kept into auxiliary table
601 * @param none
602 * @return string
604 function vk_invoice_service() {
605 global $patientglobal;
607 // retrieve auxiliary values
608 $rd = mysql_query("SELECT * FROM cl_aux WHERE aux_id = 'vk_0426_invoice'") or die(mysql_error());
609 $rez = mysql_fetch_array($rd);
611 $uninum = $rez['aux_varn'] + 1;
613 // update the auxiliary tables with the new values
614 $qu = sprintf("UPDATE cl_aux SET aux_varn = %d WHERE aux_id = 'vk_0426_invoice'", $uninum);
615 mysql_query($qu) or die(mysql_error());
617 $invoice_service = sprintf("%s-%04s", $patientglobal, $uninum);
619 // padding as required
620 return str_pad($invoice_service, 20, ' ', STR_PAD_LEFT);
623 //-----------------------------------------------------------------------------
625 * GENERATE LINE IDENTIFICATION RECORD
627 * unique number for every generated line
628 * begins with 1 and the add 1 unit at a time
630 * @param none
631 * @return string
633 function vk_unique_line_record() {
634 global $uniqueid;
636 // add one unit to the global var
637 $uninum = $uniqueid + 1;
639 // update the global var with the new value
640 $uniqueid = $uninum;
642 // padding as required
643 $id = str_pad($uninum, 12, '0', STR_PAD_LEFT);
645 return $id;
649 //-----------------------------------------------------------------------------
651 * GET PATIENT DATA
653 * returns different informations about patient
654 * it works with multibyte strings, so mb extension must be enabled!
656 * @param string $param
657 * @return string
659 function vk_patientdata($param = 'pid') {
660 mb_internal_encoding('UTF-8');
662 global $patientglobal;
663 $pat = getPatientData($patientglobal);
664 $patnl = getPatientDataNL($patientglobal);
666 switch ( $param ) {
667 case 'pid': $retval = str_pad($patientglobal, 11, ' ', STR_PAD_RIGHT); break;
668 case 'ssn': $retval = ( $pat['ss'] ) ? str_pad($pat['ss'], 9, '0', STR_PAD_LEFT) : '999999999'; break;
669 case 'dob': $retval = str_replace('-', '', $pat['DOB']); break;
671 case 'sex': if ( $pat['sex'] == 'Male' ) $retval = 1; else if ( $pat['sex'] == 'Female' ) $retval = 2;
672 else $retval = 1; break;
674 case 'namecode_patient':
675 // there are four codes but we use only 1-3. no 4
676 /*$pname = $patnl['pdn_pxlast'] .' '. $pat['lname']; // patient's name
677 $parname = $patnl['pdn_pxlastpar'] .' '. $patnl['pdn_lastpar']; // partner's name
678 $pname = trim($pname); $parname = trim($parname);
680 if ( $pname && $parname) $code = 3;
681 else if ( $pname && !$parname) $code = 1;
682 else if ( !$pname && $parname ) $code = 2;
683 $retval = $code;*/
684 $retval = 1;
685 break;
687 case 'namepat':
688 $inival = mb_strpad($pat['lname'], 25, ' ', STR_PAD_RIGHT);
689 $retval = mb_strtoupper($inival, 'UTF-8');
690 break;
691 case 'pxnamepat':
692 $inival = str_pad($patnl['pdn_pxlast'], 10, ' ', STR_PAD_RIGHT);
693 $retval = mb_strtoupper($inival, 'UTF-8');
694 break;
696 case 'namecode_partner':
697 $par = trim($patnl['pdn_lastpar']);
698 return ( $par ? 2 : 0 );
699 break;
701 case 'nameusage':
702 $_209 = 1 ; // for us always 1 otherwise vk_patientdata('namecode_patient');
703 $_212 = vk_patientdata('namecode_partner');
704 $retval = ( $_212 ) ? 3 : 0;
705 break;
707 case 'namepar':
708 $inival = mb_strpad($patnl['pdn_lastpar'], 25, ' ', STR_PAD_RIGHT);
709 $retval = mb_strtoupper($inival, 'UTF-8');
710 break;
711 case 'pxnamepar':
712 $inival = str_pad($patnl['pdn_pxlastpar'], 10, ' ', STR_PAD_RIGHT);
713 $retval = mb_strtoupper($inival, 'UTF-8');
714 break;
716 case 'initials':
717 $ini = trim($patnl['pdn_initials']);
718 $ini_new = ( $ini ) ? preg_replace('/[^a-zA-Z]*/','', $ini) : '';
719 $retval = str_pad($ini_new, 6, ' ', STR_PAD_RIGHT);
720 break;
722 case 'postalcode':
723 // check for country code
724 $pcode = ( $pat['country_code'] == CNLCODE ) ? $pat['postal_code'] : '' ;
725 $retval = str_pad($pcode, 6, ' ', STR_PAD_LEFT);
726 break;
727 case 'foreignpostalcode':
728 // check for country code
729 $pcode = ( $pat['country_code'] != CNLCODE ) ? $pat['postal_code'] : '' ;
730 $retval = str_pad($pcode, 9, ' ', STR_PAD_LEFT);
731 break;
733 case 'stnumber': $retval = str_pad($patnl['pdn_number'], 5, '0', STR_PAD_LEFT); break;
734 case 'stnumberaffix': $retval = str_pad($patnl['pdn_addition'], 6, ' ', STR_PAD_LEFT); break;
736 case 'countrycode':
737 $ccode = ( $pat['country_code'] != CNLCODE ) ? $pat['country_code'] : '';
738 $twocode = ( $ccode ) ? vk_countrycode($ccode) : '';
739 $retval = str_pad($twocode, 2, ' ', STR_PAD_LEFT);
740 break;
743 return $retval;
747 //-----------------------------------------------------------------------------
749 * FIND THE ISOCODE FOR A COUNTRY CODE
751 * the two digits code
753 * @param int $cid - country id
754 * @return string
756 function vk_countrycode($cid) {
757 $q = sprintf("SELECT * FROM geo_country_reference WHERE countries_id = %d ", $cid);
758 $r = mysql_query($q);
759 $row = mysql_fetch_array($r);
760 return $row['countries_iso_code_2'];
763 //-----------------------------------------------------------------------------
765 * PRESTATIE CODE TABLE
767 * get values from it
769 * @param string $flag prestatie - cl_dbc_prestatiecode | declaratie for cl_declaratiecode
770 * @return string
772 function vk_claimcode($flag = 'prestatie') {
773 global $dbcidglobal;
774 $cdbc = content_diagnose($dbcidglobal);
775 $pcode = $cdbc['ax_pcode'];
776 $cdate = $cdbc['ax_cdate'];
778 switch ( $flag ) {
779 case 'prestatie': $retval = str_pad($pcode, 12, ' ', STR_PAD_LEFT); break;
780 case 'declaratie':
781 $q = sprintf("SELECT cl_declaratiecode AS cd FROM cl_prestatiecode WHERE cl_dbc_prestatiecode = '%s'
782 AND cl_prestatiecode_begindatum <= '%s' AND cl_prestatiecode_einddatum >= '%s' ", $pcode, $cdate, $cdate);
783 $r = mysql_query($q) or die(mysql_error());
785 if ( $row = mysql_fetch_array($r) ) $retval = str_pad($row['cd'], 6, ' ', STR_PAD_LEFT);
786 else $retval = str_pad('', 6, ' ', STR_PAD_LEFT);
787 break;
790 return $retval;
793 //-----------------------------------------------------------------------------
795 * DBC DATES
797 * return the start/end dates for a DBC
799 * @param int $flag 1-opening date 2-closing date
800 * @return string
802 function vk_dbcdates($flag = 1) {
803 global $dbcidglobal;
804 $cdbc = content_diagnose($dbcidglobal);
805 $odate = $cdbc['ax_odate'];
806 $cdate = $cdbc['ax_cdate'];
808 // put them in vektis form YYYYMMDD
809 $od = str_replace('-','', $odate);
810 $cd = str_replace('-','', $cdate);
812 return (( $flag == 1 ) ? $od : $cd);
816 //-----------------------------------------------------------------------------
818 * DBC INFO
820 * return different informations about a DBC
822 * @param string $info
823 * @return
825 function vk_dbcinfo($info = 'ztn') {
826 global $dbcidglobal;
827 $cdbc = content_diagnose($dbcidglobal);
829 switch ( $info ) {
830 case 'ztn' : $ztn = $cdbc['ax_ztn']; $retval = str_pad($ztn, 20, ' ', STR_PAD_LEFT); break;
831 case 'tariff':
832 $decode = trim(vk_claimcode('declaratie'));
833 $date = trim(vk_dbcdates(2)); // closing date?
835 $q = sprintf("SELECT cl_dbc_tarief FROM cl_dbc_tarief WHERE cl_declaratiecode = '%s'
836 AND cl_dbc_tarief_begindatum <= '%s' AND cl_dbc_tarief_einddatum >= '%s' ", $decode, $date, $date);
837 $r = mysql_query($q) or die(mysql_error());
838 if ( mysql_num_rows($r) ) {
839 $row = mysql_fetch_array($r); $val = $row['cl_dbc_tarief'];
840 } else {
841 $val = 0;
843 $retval = str_pad($val, 8, '0', STR_PAD_LEFT);
844 break;
847 return $retval;
850 //-----------------------------------------------------------------------------
852 * WRITE THE DATA INTO THE FILE
854 * write the provided date into the file
856 * @param string $data
857 * @return
859 function vk_write_file($data) {
860 global $filepointer;
861 if ( !$filepointer ) return FALSE;
863 flock($filepointer, LOCK_EX);
864 fwrite($filepointer, $data);
865 flock($filepointer, LOCK_UN);
869 //-----------------------------------------------------------------------------
871 * COUNT THE TOTAL NUMBER OF DBC READY FOR VEKTIS GENERATION
873 * @param int $type - the vektis records type (new; old - to be resubmited)
874 * @return int
876 function vk_number_ready($type = 1) {
877 switch ( $type ) {
878 case '1': $type = 1; break;
879 case '3': $type = 3; break;
880 default: $type = 1;
883 $q = sprintf("SELECT COUNT(*) AS c FROM cl_axes WHERE ax_vkstatus = $type ");
885 $r = mysql_query($q) or die(mysql_error());
886 $row = mysql_fetch_array($r);
887 return (int)$row['c'];
890 //-----------------------------------------------------------------------------
892 * RETURN DBCs READY FOR VEKTIS GENERATION
894 * statuses 0 - DBC open, nothing to do
895 * 1 - DBC closed; to be sent to VK
896 * 2 - DBC closed; sent to VK but w/out returning codes
897 * 3 - DBC closed; sent to VK and invalid; to be resubmited
898 * 4 - DBC closed; sent to VK and validated.
899 * @param int $status - what status do you want
900 * @return array
902 function vk_vektis_ready($status = 1) {
903 $q = sprintf("SELECT ax_id FROM cl_axes WHERE ax_vkstatus = %d", $status);
904 $r = mysql_query($q) or die(mysql_error());
906 $result = array();
907 if ( mysql_num_rows($r) ) {
908 while ( $row = mysql_fetch_array($r) ) {
909 $result[] = content_diagnose($row['ax_id']);
910 } // while
911 } else {
912 return FALSE;
915 return $result;
919 //-----------------------------------------------------------------------------
921 * GENERATE AN UNIQUE SESSION ID
923 * it's about vektis session - the generating for file stage
924 * an unique number for a moment in time
926 * @param none
927 * @return string
929 function vk_vektis_session() {
930 return date('dmYHis');
933 //-----------------------------------------------------------------------------
935 * DISPLAY THE GENERATED FILE
938 * @param none
939 * @return none
941 function vk_display_file() {
942 global $filename;
944 $link_filename = basename($filename);
945 echo "<p>The file <a href='" .VK_WORKINGLNK. "$link_filename'>$filename</a> was generated.</p>";
947 $filepointer = @fopen($filename, "rb");
948 $buffer = '';
950 if ( $filepointer ) {
951 while ( !feof($filepointer) ) {
952 $buffer .= fgets($filepointer, 1024);
956 echo "<textarea rows='20' cols='150' wrap='off' readonly>$buffer</textarea>";
959 //-----------------------------------------------------------------------------
961 * COMMIT TO DB THE VEKTIS
963 * save to db the content of the newly generates Vektis file.
965 * @param none
966 * @return none
968 function vk_db_commit() {
969 $arr_database = $_SESSION['arrdb'];
970 mysql_query("START TRANSACTION");
971 mysql_query("BEGIN");
973 if ( $arr_database ) {
974 $data = date('Y-m-d', strtotime($arr_database['cvd_date']));
975 // prepate the sql insert statements
976 foreach ( $arr_database['cvd_pid'] as $ak => $av ) {
977 $query = sprintf("INSERT INTO cl_vektis_data
978 (cvd_session,
979 cvd_pid,
980 cvd_date,
981 cvd_116,
982 cvd_uzovi,
983 cvd_ztn,
984 cvd_tariff,
985 cvd_426,
986 cvd_dbcid)
987 VALUES ('%s', %d, '%s', '%s', '%s', '%s', %d, '%s', %d)",
988 $arr_database['cvd_session'],
989 $av,
990 $data,
991 $arr_database['cvd_116'],
992 $arr_database['cvd_uzovi'][$ak],
993 trim($arr_database['cvd_ztn'][$ak]),
994 $arr_database['cvd_tariff'][$ak],
995 trim($arr_database['cvd_426'][$ak]),
996 $arr_database['cvd_dbcid'][$ak]
997 ); // $query
999 // saving to the table
1000 mysql_query($query) or die(mysql_error());
1002 //echo '<pre>'.print_r($query, true).'</pre>'; // debug
1003 } // foreach
1005 // marked the DBC's as sent to vektis
1006 foreach ( $arr_database['cvd_dbcid'] as $dbcid) {
1007 $queryupdate = sprintf("UPDATE cl_axes SET ax_vkstatus = 2 WHERE ax_id = %d ", $dbcid);
1008 mysql_query($queryupdate) or die(mysql_error());
1012 mysql_query("COMMIT");
1015 //-----------------------------------------------------------------------------
1017 * PARSE THE UPLOADED FILE
1020 * @param string $file
1021 * @param int $state - 1 for simulation, 2 for real situation
1022 * @return none
1024 function vk_parse_returning_file($file = '', $state = 1) {
1025 if ( !$file ) return FALSE;
1027 $filepath = realpath($file);
1028 $fp = @fopen($filepath, "rb");
1029 $buffer = '';
1030 $_SESSION['vk_retfile'] = $filepath;
1032 if ( $fp ) {
1033 while ( !feof($fp) ) {
1034 $buffer = fgets($fp);
1036 // we get the type of line from the first two digits
1037 $f2 = substr($buffer, 0, 2);
1038 switch ( $f2 ) {
1039 case '01':
1040 $extarr = vk_process_extra($buffer, 1); $com = vk_process_common($buffer, 1);
1041 vk_shows_line($buffer, $extarr, $com, 1, $state);
1042 break;
1043 case '02':
1044 $extarr = vk_process_extra($buffer, 2); $com = vk_process_common($buffer, 2);
1045 vk_shows_line($buffer, $extarr, $com, 2, $state);
1046 break;
1047 case '04':
1048 $extarr = vk_process_extra($buffer, 4); $com = vk_process_common($buffer, 4);
1049 vk_shows_line($buffer, $extarr, $com, 4, $state);
1050 break;
1051 case '99':
1052 $extarr = vk_process_extra($buffer, 99); $com = vk_process_common($buffer, 99);
1053 vk_shows_line($buffer, $extarr, $com, 99);
1054 break;
1058 } // if $fp
1062 //-----------------------------------------------------------------------------
1064 * PROCESS EXTRA INFORMATIONS
1066 * process extra informations from every line in returning file
1068 * @param string $line - whole line (sent line + returning info)
1069 * @param int $case - the line type
1070 * @return array
1072 function vk_process_extra($line = '', $case = 1) {
1073 if ( !$line ) return FALSE;
1075 // the start and len values are taken from the vektis documentation
1076 switch ( $case ) {
1077 case 1:
1078 $start = 310; $len = 44;
1079 $extrastr = mb_substr($line, $start, $len);
1080 $_181 = mb_substr($extrastr, 0, 24);
1081 $_182 = mb_substr($extrastr, 24, 8);
1082 $_196 = mb_substr($extrastr, 32, 4);
1083 $_197 = mb_substr($extrastr, 36, 4);
1084 $_198 = mb_substr($extrastr, 40, 4);
1085 $retarr = array('s181' => $_181, 's182' => $_182, 's196' => $_196, 's197' => $_197, 's198' => $_198);
1086 break;
1087 case 2:
1088 $start = 310; $len = 12;
1089 $extrastr = mb_substr($line, $start, $len);
1090 $_296 = mb_substr($extrastr, 0, 4);
1091 $_297 = mb_substr($extrastr, 4, 4);
1092 $_298 = mb_substr($extrastr, 8, 4);
1093 $retarr = array('s296' => $_296, 's297' => $_297, 's298' => $_298);
1094 break;
1095 case 4:
1096 $start = 310; $len = 30;
1097 $extrastr = mb_substr($line, $start, $len);
1098 $_481 = mb_substr($extrastr, 0, 8);
1099 $_482 = mb_substr($extrastr, 8, 1);
1100 $_483 = mb_substr($extrastr, 9, 8);
1101 $_484 = mb_substr($extrastr, 17, 1);
1102 $_496 = mb_substr($extrastr, 18, 4);
1103 $_497 = mb_substr($extrastr, 22, 4);
1104 $_498 = mb_substr($extrastr, 26, 4);
1105 $retarr = array('s481' => $_481, 's482' => $_482, 's483' => $_483, 's484' => $_484, 's496' => $_496, 's497' => $_497, 's498' => $_498);
1106 break;
1107 case 99:
1108 $start = 45; $len = 12;
1109 $extrastr = mb_substr($line, $start, $len);
1110 $_9909 = mb_substr($extrastr, 0, 11);
1111 $_9910 = mb_substr($extrastr, 11, 1);
1112 $retarr = array('s9909' => $_9909, 's9910' => $_9910);
1113 break;
1114 default : return FALSE;
1115 } // switch
1117 return $retarr;
1122 //-----------------------------------------------------------------------------
1124 * PROCESS COMMON INFORMATIONS
1126 * common informations are the common elements from the file and already saved database
1127 * there are the links between db saved info and returning file
1129 * @param string $line - whole line (sent line + returning info)
1130 * @param int $case - the line type
1131 * @return none
1133 function vk_process_common($line = '', $case = 1) {
1134 if ( !$line ) return FALSE;
1136 // the start and len values are taken from the vektis documentation
1137 switch ( $case ) {
1138 case 1:
1139 $_116 = mb_substr($line, 80, 12);
1140 $_117 = mb_substr($line, 92, 8);
1141 $retarr = array('s116' => $_116, 's117' => $_117);
1142 break;
1143 case 2:
1144 $_204 = mb_substr($line, 23, 4);
1145 $_206 = mb_substr($line, 42, 11);
1146 $retarr = array('s204' => $_204, 's206' => $_206);
1147 break;
1148 case 4:
1149 $_414 = mb_substr($line, 99, 20);
1150 $_418 = mb_substr($line, 136, 8);
1151 $_426 = mb_substr($line, 176, 20);
1152 $retarr = array('s414' => $_414, 's418' => $_418, 's426' => $_426);
1153 break;
1154 } // switch
1156 return $retarr;
1160 //-----------------------------------------------------------------------------
1162 * VALIDATE THE RETURNING FILE
1167 * @param string $errcode
1168 * @return bool|array('valid' => true|false, 'letter' => 'X|T|D|space', 'expl' => explanation, 'code' => code)
1170 function vk_validate_vektis($errcode) {
1171 // if we don't have a retcode, then return valid (aka do nothing)
1172 if ( $errcode == '0000') return array('valid' => TRUE, 'letter' => '', 'expl' => '', 'code' => '');
1174 $earr = vk_error_code($errcode);
1175 $retarr = array();
1177 if ( $earr ) {
1178 switch ( $earr['cvr_content'] ) {
1179 case 'X':
1180 case 'T':
1181 case 'D': $retarr['valid'] = FALSE; break;
1182 default: $retarr['valid'] = TRUE;
1184 $retarr['letter'] = $earr['cvr_content'];
1185 $retarr['expl'] = $earr['cvr_expl'];
1186 $retarr['code'] = $earr['cvr_code'];
1189 return $retarr;
1192 //-----------------------------------------------------------------------------
1194 * RETURN THE ERROR DESCRIPTION FOR A CODE
1196 * works with cl_vektis_retcodes table
1198 * @param string $retcode
1199 * @return array
1201 function vk_error_code($retcode) {
1202 $q = sprintf("SELECT * FROM cl_vektis_retcodes WHERE cvr_code = '%s' ", $retcode);
1203 $r = mysql_query($q) or die(mysql_error());
1204 return mysql_fetch_array($r);
1207 //-----------------------------------------------------------------------------
1209 * SHOWS A LINE FROM THE VALIDATION FILE
1211 * shows the validation result
1212 * if in 'real' mode it saves also into db
1214 * @param string $buffer - whole line
1215 * @param array $extarr - extra fields
1216 * @param array $com - common fields
1217 * @param int $line - line type (e.g. 01, 04, 99)
1218 * @param int $state - 1 simulation, 2 real
1219 * @return
1221 function vk_shows_line($buffer, $extarr, $com, $line, $state = 1) {
1223 switch ( $line ) {
1224 case 1:
1225 $e1 = vk_validate_vektis($extarr['s196']);
1226 $e2 = vk_validate_vektis($extarr['s197']);
1227 $e3 = vk_validate_vektis($extarr['s198']);
1228 break;
1229 case 2:
1230 $e1 = vk_validate_vektis($extarr['s296']);
1231 $e2 = vk_validate_vektis($extarr['s297']);
1232 $e3 = vk_validate_vektis($extarr['s298']);
1233 break;
1234 case 4:
1235 $e1 = vk_validate_vektis($extarr['s496']);
1236 $e2 = vk_validate_vektis($extarr['s497']);
1237 $e3 = vk_validate_vektis($extarr['s498']);
1238 break;
1239 case 99:
1240 $lastline = vk_format_msg($extarr, 1);
1241 break;
1244 // common part
1245 if ( $line != 99 ) {
1246 if ( !$e1['valid'] || !$e2['valid'] || !$e3['valid'] ) {
1247 $class = 'vk_error';
1248 $e = array($e1, $e2, $e3);
1249 if ( $state == 2 ) vk_mod_vkstatus($line, $com, $e);
1250 } else {
1251 $class = 'vk_expl';
1255 $e1str = ( $e1['expl'] ) ? vk_format_msg($e1) : '';
1256 $e2str = ( $e2['expl'] ) ? vk_format_msg($e2) : '';
1257 $e3str = ( $e3['expl'] ) ? vk_format_msg($e3) : '';
1259 $msgline = ( $lastline ) ? $lastline : $e1str . $e2str . $e3str;
1260 if ( $lastline ) $class = 'vk_expl';
1261 $shstr = "<div class='vk_nline'>$buffer</div><div class='$class'>$msgline</div>";
1263 // display the built string
1264 echo $shstr;
1267 //-----------------------------------------------------------------------------
1269 * FORMATS THE MESSAGE FOR RETURNING CODES
1271 * for the last line there is a special format
1273 * @param array $e - all infos about a retcode
1274 * @param bool $lastline - is the last line? (default:false)
1275 * @return string
1277 function vk_format_msg($e, $lastline = 0) {
1278 if ( $lastline ) {
1279 $str = "TOTAL ASSIGNED AMOUNT: {$e['s9909']} D/C: {$e['s9910']} <br />";
1280 } else {
1281 // common line format
1282 $content = ( $e['letter'] != 'O') ? $e['letter'] : 'OK';
1283 $str = "CODE: {$e['code']} - {$e['expl']} ($content) <br />";
1286 return $str;
1289 //-----------------------------------------------------------------------------
1291 * MODIFY THE VEKTIS STATUS
1294 * @param int $line - in what line the error appeared
1295 * @param array $com - common part (sent/returned files)
1296 * @param array $ee - those three array errors
1297 * @return
1299 function vk_mod_vkstatus($line, $com, $ee) {
1300 // function of the line, we treat different the errors
1301 switch ( $line ) {
1302 case 1:
1303 foreach ( $ee as $e) {
1304 // for X-T letters on the first level we invalidate all the file
1305 if ( $e['letter'] == 'X' || $e['letter'] == 'T' ) {
1306 vk_file_invalidatevektis();
1307 } //if
1309 break;
1310 case 2:
1311 $pid = $com['s206'];
1312 foreach ( $ee as $e) {
1313 // for X-T letters on the first level we invalidate all the file ??
1314 if ( $e['letter'] == 'D' ) {
1315 vk_file_invalidatedbc($pid, 2);
1316 } else if ( $e['letter'] == 'O' ){
1317 // make it valid
1320 break;
1321 case 4:
1322 foreach ( $ee as $e) {
1323 // for X-T letters on the first level we invalidate all the file ??
1324 if ( $e['letter'] == 'D' ) {
1325 vk_file_invalidatedbc($com, 4); // we send as pid the common elements
1326 } else if ( $e['letter'] == 'O' ){
1327 // make it valid
1330 break;
1331 default: return FALSE;
1332 } // switch
1336 //-----------------------------------------------------------------------------
1338 * RETURNS SOME FIELDS FROM THE FILE
1340 * 116 - vektis invoice number for all the file
1343 * @param string $var - what field
1344 * @param string $ztn - what ztn to look for (needed only for 426 or so, because there are many lines)
1345 * @return string|bool - the invoice number
1347 function vk_file_getvar($var = '116', $ztn = 0) {
1349 if ( !isset($_SESSION['vk_retfile']) || empty($_SESSION['vk_retfile']) ) {
1350 return FALSE;
1353 // array that containts lines where are the requested var
1354 $elemarr = array('116' => '01', '426' => '04');
1356 $fp = @fopen($_SESSION['vk_retfile'], "rb");
1357 if ( $fp ) {
1358 while ( !feof($fp) ) {
1359 $buffer = fgets($fp);
1360 // we get the type of line from the first two digits
1361 $f2 = substr($buffer, 0, 2);
1363 // we parse all the lines looking for our line type
1364 if ( $f2 == $elemarr[$var] ) {
1365 // different cases
1366 if ( $var = '116' ) {
1367 $varfield = mb_substr($buffer, 80, 12);
1370 if ( $var = '426' ) {
1371 // not needed in this moment
1375 } else return FALSE;
1377 return trim($varfield);
1381 //-----------------------------------------------------------------------------
1383 * INVALIDATE ALL VEKTIS FILE
1385 * look for dbcs after unique vektis invoice number
1387 * @param none
1388 * @return void
1390 function vk_file_invalidatevektis() {
1391 $inv = vk_file_getvar('116');
1393 $q = sprintf("SELECT * FROM cl_vektis_data WHERE cvd_116 = '%s' ", $inv);
1394 $r = mysql_query($q) or die(mysql_error());
1395 while ( $row = mysql_fetch_array($r) ) {
1396 // 3 - means 'to be resubmitted'
1397 $q2 = sprintf("UPDATE cl_axes SET ax_vkstatus = 3 WHERE ax_id = %d ", $row['cvd_dbcid']);
1398 $r2 = mysql_query($q2) or die(mysql_error());
1402 //-----------------------------------------------------------------------------
1404 * INVALIDATE ALL DBC FROM VEKTIS FILE
1406 * for a specified patient
1408 * @param int $pid - patient id
1409 * @param int $case - what situation? row type 02 or 04 ?
1410 * @return void
1412 function vk_file_invalidatedbc($pid, $case) {
1414 if ( $case == 2 ) {
1415 $inv = vk_file_getvar('116');
1416 $q = sprintf("SELECT * FROM cl_vektis_data WHERE cvd_116 = '%s' AND cvd_pid = %d", $inv, $pid);
1417 } else if ( $case == 4) {
1418 // here we don't need the patient id but we use this var to retrieve the common elements
1419 // so here, $pid means actually $com array
1420 $q = sprintf("SELECT * FROM cl_vektis_data WHERE cvd_426 = '%s' ", trim($pid['s426']));
1423 $r = mysql_query($q) or die(mysql_error());
1424 if ( mysql_num_rows($r) ) {
1425 while ( $row = mysql_fetch_array($r) ) {
1426 // 3 - means 'to be resubmitted'
1427 $q2 = sprintf("UPDATE cl_axes SET ax_vkstatus = 3 WHERE ax_id = %d ", $row['cvd_dbcid']);
1428 $r2 = mysql_query($q2) or die(mysql_error());
1430 } // if
1433 //-----------------------------------------------------------------------------
1435 * CHANGE DBC STATUS FROM 'WRONG TO RIGHT'
1437 * wrong means it's 3 (to be resubmitted), right means it's 1 (to be sent)
1439 * @param int $dbcid
1440 * @return void
1442 function vk_dbc_resubmit($dbcid = 0) {
1443 if ( !$dbcid ) return FALSE;
1445 // ax_vkstatus = 3 -> supplementary caution measure
1446 $q = sprintf("UPDATE cl_axes SET ax_vkstatus = 1 WHERE ax_id = %d AND ax_vkstatus = 3 ", $dbcid);
1447 mysql_query($q) or die(mysql_error());
1451 //-----------------------------------------------------------------------------
1453 * CUSTOM FUNCTION TO FIND SPECIAL DBC
1455 * condition: Overloop DBCs (all DBCs with encounters both in 2007 and 2008):
1457 * @param int $dbcid
1458 * @return void
1460 function vk_is_overloop_dbc($dbcid = 0) {
1461 if ( !$dbcid ) return FALSE;
1463 $dbc = content_diagnose($dbcid);
1464 $odate = $dbc['ax_odate'];
1465 $cdate = $dbc['ax_cdate'];
1467 global $patientglobal;
1468 $pid = $patientglobal;
1470 // 2007 encounters
1471 $q1 = mysql_query("SELECT COUNT(*) AS a FROM openemr_postcalendar_events WHERE pc_pid = $pid AND pc_apptstatus = '@'
1472 AND pc_eventDate >= '$odate' AND pc_eventDate <= '2007-12-31' ") or die(mysql_error());
1473 $r1 = mysql_fetch_array($q1);
1474 $enc2007 = $r1['a'];
1476 if ( $enc2007 ) {
1477 // 2008 encounters
1478 $q2 = mysql_query("SELECT COUNT(*) AS a FROM openemr_postcalendar_events WHERE pc_pid = $pid
1479 AND pc_apptstatus = '@'
1480 AND pc_eventDate >= '2008-01-01' AND pc_eventDate <= '$cdate' ") or die(mysql_error());
1481 $r2 = mysql_fetch_array($q2);
1482 $enc2008 = $r2['a'];
1483 } else {
1484 $enc2008 = 0;
1485 } //if $enc2007
1487 return ($enc2007 && $enc2008);
1492 //-----------------------------------------------------------------------------
1494 * CUSTOM FUNCTION TO CALCULATE DEDUCTION FOR DBC's
1496 * function of F* codes in 2007 (not 2008!)
1498 * @param int $dbcid
1499 * @return int
1501 function vk_deduction($dbcid = 0) {
1502 global $patientglobal;
1503 $pid = $patientglobal;
1505 $enarr = array( 'F101' => '2090', 'F102' => '20040', 'F103' => '41610', 'F104' => '10160',
1506 'F105' => '6840', 'F106' => '8550' , 'F221' => '4750', 'F151' => '2090',
1507 'F152' => '16150','F153' => '44170', 'F154' => '15290', 'F155' => '9780',
1508 'F156' => '9210', 'F224' => '4940');
1509 $total_sum = 0;
1510 foreach ( $enarr as $ek => $ev ) {
1511 $q = mysql_query("SELECT COUNT(*) AS a FROM openemr_postcalendar_events WHERE pc_pid = $pid AND pc_apptstatus = '@' AND pc_eventDate >= '2007-01-01' AND pc_eventDate <= '2007-12-31' AND pc_title LIKE '$ek%'");
1512 $r = mysql_fetch_array($q);
1513 $total_sum += $r['a'] * $ev;
1516 $total_sum = round($total_sum);
1518 return $total_sum;
1521 //-----------------------------------------------------------------------------