Fixes and improvements.
[openemr.git] / library / DBC_decisiontree.php
blobb9ac2c11d62697f0dee883b59dcf9632f4c02f0d
1 <?php
2 /**
3 * DBC DUTCH SYSTEM
4 * Decision Tree - beslisboom
5 *
6 * functions used at the moment of closing dbc to choose a productgroep in the end
7 * Cristian Navalici lemonsoftware [ @ ] gmail [ . ] com
9 * FUNCTIONS' LIST
11 * int dt_main(int $node) - main function; it's the decision point in our algorithm
12 * string dt_whatparam(string $kmcode) - what param is needed for km* function
13 * string dt_nodefunction(int $node) - what function is associated with a node
14 * int dt_comparison(string $function, int $rval) - compare the values to make a decision
15 * int dt_kma001()
16 * int dt_kma002()
19 /**
20 * global variables used in script
23 $beslis_table = ''; // we use different tables for 2007/08
24 $rfsum = 0; // remember for sum - this we add all values from the algorithm
25 $dbcid = 0; // dbc id
26 $enddate = ''; // closing date for dbc (if used from a CLI script)
28 /**
29 * if you run from a cron script (outside the webserver), use it this way
30 * include_once('library/DBC_cfunctions.php');
31 * include_once('library/DBC_decisiontree.php');
32 * global $rfsum;
33 * dt_main(1, 365, '2008-04-02');
34 * $z = dt_whatproductgroep($rfsum, '2008-04-02');
35 * 1 - starting node, 365 - dbcid, '2008-04-02' - closing date
39 //-----------------------------------------------------------------------------
40 /**
41 * MAIN FUNCTION
43 * calls different functions, in a deadly precise algorithm
45 * @param int $node - in what node we are (default:1)
46 * @param int $dbcid - in case we are calling from a script
47 * @param string $end - closing date for dbc (used in dt_allevents)
48 * @return int $rfsum - remember for sum
50 function dt_main($node = 1, $dbcid = 0, $end = '') {
51 // if it's the first time, run the pre_init function
52 if ( $node == 1 ) dt_preinit($dbcid, $end);
54 $function = dt_nodefunction($node);
56 switch ($function) {
57 case 'KMA_001': $r = dt_kma001(); break;
58 case 'KMA_002': $r = dt_kma002(); break;
59 case 'KMA_003': $r = dt_kma003(); break;
60 case 'KMA_004': $r = dt_kma004(); break;
61 case 'KMA_005': $r = dt_kma005(); break;
62 case 'KMT_001': $r = dt_kmt001($node); break;
63 case 'KMT_002': $r = dt_kmt002(); break;
64 case 'KMT_003': $r = dt_kmt003($node); break;
65 case 'KMT_004': $r = dt_kmt004(); break;
66 case 'KMN_001': $r = dt_kmn001($node); break;
67 case 'KMP_001': $r = dt_kmp001(); break;
68 case 'KMC_001': $r = dt_kmc001(); break;
71 global $rfsum;
73 $direction = dt_comparison($node, $r);
74 //echo "F:$function R: $r D: $direction SUM: $rfsum <br /> --------------- <br> "; //debug
75 //echo "F:$function R: $r D: $direction SUM: $rfsum \n"; // debug for CLI
77 if ( $direction ) dt_main($direction);
78 else {
79 global $enddate, $dbcid;
80 if ( !$dbcid ) $enddate = $_SESSION['eind']; // called from webinterface
82 if ( !$dbcid ) {
83 // for a script, we must called this ourselves using global $rfsum and closing date
84 $a = dt_whatproductgroep($rfsum, $enddate);
85 // called from within openemr
86 $_SESSION['pgroep'] = $a['id'];
87 echo $a['name'];
94 //-----------------------------------------------------------------------------
95 /**
96 * DECIDES WHAT TABLE WILL BE USED
98 * because the beslisboom has 2 tables (2007/2008), we must decide which one we'll use
100 * @param int $dbcid - in case we called this from a script (and we don't have $_SESSION)
101 * @param string $end - closing date for dbc
102 * @return void
104 function dt_preinit($dbc, $end) {
105 // it sets some globals
106 global $beslis_table, $dbcid, $enddate;
107 $dbcid = $dbc;
108 $enddate = ( $end ) ? $end : $_SESSION['eind'];
110 $dbc = content_diagnose($dbcid);
111 $odate = $dbc['ax_odate'];
113 if ( $odate <= '2007-12-31' ) {
114 $beslis_table = 'cl_beslisboom_2007';
115 } elseif ( $odate >= '2008-01-01') {
116 $beslis_table = 'cl_beslisboom';
117 } else {
118 // leave room for more versions :)
124 //-----------------------------------------------------------------------------
126 * COMPARISON
128 * function for comparison
130 * @param int $node - node to look for (and retrieve the one value)
131 * @param int $value to compare
132 * @return int - next node
134 function dt_comparison($node, $rval) {
135 global $beslis_table;
136 $q = sprintf("SELECT * FROM %s WHERE cbe_nodeorigin = %d ", $beslis_table, $node);
138 $r = mysql_query($q) or die(mysql_error());
140 if ( !mysql_num_rows($r) ) {
141 return 0;
142 } else {
143 $row = mysql_fetch_array($r);
145 // compare the values function of the operator
146 switch ( $row['cbe_operator'] ) {
147 case '<=': $rez = ( $rval <= $row['cbe_value1'] ); break;
148 case '<': $rez = ( $rval < $row['cbe_value1'] ); break;
149 case '=': $rez = ( $rval == $row['cbe_value1'] ); break;
150 case '>=': $rez = ( $rval >= $row['cbe_value1'] ); break;
153 // update the remember for sum variable
154 global $rfsum;
155 $rfsum += ( $rez ) ? $row['cbe_rfsumT'] : $row['cbe_rfsumF'];
157 // next hop (node)
158 $ret = $rez ? $row['cbe_nodegoal_T'] : $row['cbe_nodegoal_F'];
160 return $ret;
164 //-----------------------------------------------------------------------------
166 * WHAT FUNCTION IS USED FOR A SPECIFIED NODE
168 * function of node, we call a function
170 * @param int node
171 * @return string function name (in fact, a code from the tables)
173 function dt_nodefunction($node) {
174 global $beslis_table;
175 $q = sprintf("SELECT cbe_checkKM AS km FROM %s WHERE cbe_nodeorigin = %d ", $beslis_table, $node);
176 $r = mysql_query($q) or die(mysql_error());
178 if ( !mysql_num_rows($r) ) {
179 return 0;
180 } else {
181 $row = mysql_fetch_array($r);
182 return $row['km'];
186 //-----------------------------------------------------------------------------
188 * WHAT PARAMETER IS NEEDED FOR KM* FUNCTION
190 * some KM* functions work with some parameter; this function retrieves from db
192 * @param int $node - KM node
193 * @param int $par - first or second param (1/2)
194 * @return string $param (empty string for no param)
196 function dt_whatparam($node, $par = 1) {
197 global $beslis_table;
199 if ( $par == 1 ) {
200 $q = sprintf("SELECT cbe_KMpar1 AS param FROM %s WHERE cbe_nodeorigin = %d ", $beslis_table, $node);
201 } else if ( $par == 2) {
202 $q = sprintf("SELECT cbe_KMpar2 AS param FROM %s WHERE cbe_nodeorigin = %d ", $beslis_table, $node);
204 $r = mysql_query($q) or die(mysql_error());
206 if ( !mysql_num_rows($r) ) {
207 return '';
208 } else {
209 $row = mysql_fetch_array($r);
210 return $row['param'];
214 //-----------------------------------------------------------------------------
216 * KMA001
218 * Number of days in clinic
219 * Days in clinic can be recognised by CL_ACTIVITEIT_SOORT=VERBLIJFSDAG.
220 * Exception: act_8.1.6*
222 * NOTE we don't use it now so it's always 0
224 * @param none
225 * @return int
227 function dt_kma001() {
228 return 0;
231 //-----------------------------------------------------------------------------
233 * KMA002
235 * ver 1: Sum of all direct time of activities + total time dagbesteding
236 * If CL_ACTIVITEIT_SOORT = TIJDSCHRIJVEN then sum up all DIRECT_PATIENT-GEBONDEN_TIJD. Add time (if CL_ACTIVITEIT_SOORT * = DAGBESTEDING) *60 (because dagbesteding/daycare is registered in hours; not minutes)
238 * ver 2: Sum of all direct time of activities + 15 times the hours spent in dagbesteding
239 * If CL_ACTIVITEIT_SOORT = TIJDSCHRIJVEN then sum up all DIRECT_PATIENT-GEBONDEN_TIJD. Add time (if CL_ACTIVITEIT_SOORT * = DAGBESTEDING) *15 (because dagbesteding/daycare is registered in hours; not minutes)
241 * @param none
242 * @return int $totaltime
244 function dt_kma002() {
245 $r = dt_allevents();
246 $totaltime = 0;
248 //choose here what $ver we'll use function of a date
249 //$dbc = content_diagnose($_SESSION['show_axid']);
250 //$odate = $dbc['ax_odate'];
251 //$ver = ( $odate <= '2007-12-31') ? 1 : 2;
252 $ver = 2 ; //we'll just use 2 because we don't have dagbestending
254 while ( $row = mysql_fetch_array($r) ) {
255 $qe = sprintf("SELECT cl_activiteit_soort AS cas FROM cl_activiteit ca
256 JOIN cl_event_activiteit cea ON cea.activity_sysid = ca.cl_activiteit_sysid
257 WHERE cea.event_id = %d", $row['pc_eid']);
258 $re = mysql_query($qe) or die(mysql_error());
259 $rowe = mysql_fetch_array($re);
261 $cas = trim($rowe['cas']);
263 // those three times for an event (direct, indirect, travel)
264 $times = dt_times($row['pc_eid']);
266 // SUM UP TIMES
267 if ( $cas == 'Verblijfsdag' ) {
268 /*if ( $ver == 1) {
269 // because dagbesteding/daycare is registered in hours; not minutes
270 //$totaltime += ( $times['dirtime'] * 60 );
271 } else if ( $ver == 2 ){
272 // 15 times the hours spent in dagbesteding
273 //$totaltime += ( $times['dirtime'] * 15 );
275 } else if ( $cas == 'Tijdschrijven' ) {
276 $totaltime += $times['dirtime'];
278 } // while
280 return $totaltime;
283 //-----------------------------------------------------------------------------
285 * KMA003
287 * total minutes total time (Sum of all direct, indirect and travel time of activities + total time dagbesteding)
289 * @param none
290 * @return int
292 function dt_kma003() {
293 $r = dt_allevents();
294 $totaltime = 0;
296 //choose here what $ver we'll use function of a date
297 //$dbc = content_diagnose($_SESSION['show_axid']);
298 //$odate = $dbc['ax_odate'];
299 //$ver = ( $odate <= '2007-12-31') ? 1 : 2;
300 $ver = 2; // it doesn't matter now.
302 while ( $row = mysql_fetch_array($r) ) {
303 $qe = sprintf("SELECT cl_activiteit_soort AS cas FROM cl_activiteit ca
304 JOIN cl_event_activiteit cea ON cea.activity_sysid = ca.cl_activiteit_sysid
305 WHERE cea.event_id = %d", $row['pc_eid']);
306 $re = mysql_query($qe) or die(mysql_error());
307 $rowe = mysql_fetch_array($re);
309 // those three times for an event (direct, indirect, travel)
310 $times = dt_times($row['pc_eid']);
311 $totalt = $times['dirtime'] + $times['tratime'] + $times['indtime'];
312 //echo "{$rowe['cas']} TIME KMA003: $totalt <br>"; //debug
313 // SUM UP TIMES
314 if ( $rowe['cas'] == 'Verblijfsdag' ) {
315 /*if ( $ver == 1) {
316 // because dagbesteding/daycare is registered in hours; not minutes
317 $totaltime += ( $times['dirtime'] * 60 );
318 } else if ( $ver == 2 ) {
319 // 15 times the hours spent in dagbesteding
320 $totaltime += ( $times['dirtime'] * 15 );
322 } else if ( $rowe['cas'] == 'Tijdschrijven' ) {
323 $totaltime += $totalt;
325 //echo "TOTALTIME KMA003: $totaltime EV: {$row['pc_eid']}<br>"; //debug
326 } // while
328 return $totaltime;
331 //-----------------------------------------------------------------------------
333 * KMA004
335 * number of separate kinds of jobs (e.g. Psychologist, psychiatrist, nurse, etc.)
336 * Count how many distinct CL_BEROEPEN_CODE values are in this DBC
338 * NOTE: openemr doesn't use it in 2008
340 * @param none
341 * @return int - distinct values for cl_beroep_code
343 function dt_kma004() {
344 $r = dt_allevents();
345 $beroep = array();
347 while ( $row = mysql_fetch_array($r) ) {
348 $qe = sprintf("SELECT cl_beroep_code FROM cl_beroep cb JOIN cl_user_beroep cub ON cb.cl_beroep_sysid = cub.cl_beroep_sysid WHERE cub.cl_beroep_userid = %d ", $row['pc_aid']);
349 $re = mysql_query($qe) or die(mysql_error());
350 $rowe = mysql_fetch_array($re);
352 $beroep[] = $rowe['cl_beroep_code'];
353 } // while
355 // find and return distict values from the jobs array
356 return count(array_unique($beroep));
360 //-----------------------------------------------------------------------------
362 * KMA005
364 * number of days in clinic without stay overnight
365 * Total number of CL_ACTIVITEIT_SOORT=VERBLIJFSDAG,
366 * but only for act_8.1.6, 8.2.6, 8.3.6, 8.4.6, 8.5.6, 8.6.6
368 * NOTE we don't use it at this moment
370 * @param none
371 * @return int
373 function dt_kma005() {
374 return 0;
377 //-----------------------------------------------------------------------------
379 * KMT001
381 * total minutes time on activity (parameter1)
382 * old ver - Add up total time (direct, indirect, travel, dagbesteding) for activities that are hierarchically under CL_ACTIVITEIT=parameter1
383 * new ver - Add up total time (direct, indirect, travel, 15*dagbesteding) for activities that are hierarchically under CL_ACTIVITEIT=parameter1, but ONLY activities with CL_ACTIVITEIT_SOORT = tijdschrijven or CL_ACTIVITEIT_SOORT = dagbesteding
385 * @param int $node - node to look parameter for
386 * @return int
388 function dt_kmt001($node) {
389 global $dbcid;
391 $par = dt_whatparam($node, 1);
392 $r = dt_allevents();
393 $totaltime = 0;
394 //echo "PAR KMT001: $par <br>"; //debug
395 // choose here what $ver we'll use function of a date
396 $dbc = content_diagnose($dbcid);
397 $odate = $dbc['ax_odate'];
398 $ver = ( $odate <= '2007-12-31') ? 1 : 2;
400 while ( $row = mysql_fetch_array($r) ) {
401 $qe = sprintf("SELECT cl_activiteit_soort AS cas, cl_activiteit_groepcode AS cag
402 FROM cl_activiteit ca JOIN cl_event_activiteit cea ON cea.activity_sysid = ca.cl_activiteit_sysid
403 WHERE cea.event_id = %d", $row['pc_eid']);
404 $re = mysql_query($qe) or die(mysql_error());
405 $rowe = mysql_fetch_array($re);
407 $cas = trim($rowe['cas']);
408 $cag = trim($rowe['cag']);
410 // under the parameter
411 if ( strpos($cag, $par) === 0 ) {
412 // those three times for an event (direct, indirect, travel)
413 $times = dt_times($row['pc_eid']);
414 $totalt = $times['dirtime'] + $times['tratime'] + $times['indtime'];
416 if ( $ver == 1 ) {
417 $totaltime += $totalt;
418 } else if ( $ver == 2 ) {
419 if ( $cas == 'Tijdschrijven' || $cas == 'Dagbesteding' ) $totaltime += $totalt;
421 } // if
423 } // while
424 //echo "TOTALTIME KMT001: $totaltime <br>";
425 return $totaltime;
428 //-----------------------------------------------------------------------------
430 * KMT002
432 * NOTE: openemr doesn't use it in 2008
434 * @param none
435 * @return int
437 function dt_kmt002() {
438 // TO BE IMPLEMENTED
441 //-----------------------------------------------------------------------------
443 * KMT003
445 * total minutes direct time on activity (parameter1)
447 * ver 1 - If CL_ACTIVITEIT_SOORT = TIJDSCHRIJVEN then sum up all DIRECT_PATIENT-GEBONDEN_TIJD. Add time (if CL_ACTIVITEIT_SOORT = DAGBESTEDING) *60 (because dagbesteding/daycare is registered in hours; not minutes) BUT ONLY for activities that are hierarchically under parameter1 of CL_ACTIVITEIT
449 * ver 2 - If CL_ACTIVITEIT_SOORT = TIJDSCHRIJVEN then sum up all DIRECT_PATIENT-GEBONDEN_TIJD.
450 * Add time (if CL_ACTIVITEIT_SOORT = DAGBESTEDING) * 15 (because dagbesteding/daycare is registered in hours; not minutes) BUT ONLY for activities that are hierarchically under parameter1 of CL_ACTIVITEIT;
452 * @param int $node- node to look parameter for
453 * @return int
455 function dt_kmt003($node) {
456 global $dbcid;
458 $par = dt_whatparam($node, 1);
459 $r = dt_allevents();
460 $totaltime = 0;
462 //choose here what $ver we'll use function of a date
463 $dbc = content_diagnose($dbcid);
464 $odate = $dbc['ax_odate'];
465 $ver = ( $odate <= '2007-12-31') ? 1 : 2;
467 while ( $row = mysql_fetch_array($r) ) {
468 $qe = sprintf("SELECT cl_activiteit_soort AS cas, cl_activiteit_groepcode AS cag
469 FROM cl_activiteit ca JOIN cl_event_activiteit cea ON cea.activity_sysid = ca.cl_activiteit_sysid
470 WHERE cea.event_id = %d", $row['pc_eid']);
471 $re = mysql_query($qe) or die(mysql_error());
472 $rowe = mysql_fetch_array($re);
474 $cas = trim($rowe['cas']);
475 $cag = trim($rowe['cag']);
477 // under the parameter
478 if ( strpos($cag, $par) === 0 ) {
479 // those three times for an event (direct, indirect, travel)
480 $times = dt_times($row['pc_eid']);
482 if ( $ver == 1 ) {
483 if ( $cas == 'Tijdschrijven' ) $totaltime += $times['dirtime'];
484 if ( $cas == 'Dagbesteding' ) $totaltime += ($times['dirtime'] * 15); // not used yet!
485 } else if ( $ver == 2 ) {
486 //if ( $cas == 'Tijdschrijven' || $cas == 'Dagbesteding' ) $totaltime += $times['dirtime'];
487 if ( $cas == 'Tijdschrijven' ) $totaltime += $times['dirtime'];
488 if ( $cas == 'Dagbesteding' ) $totaltime += ($times['dirtime'] * 60); // not used yet!
491 } // if
492 } // while
494 return $totaltime;
497 //-----------------------------------------------------------------------------
499 * KMT004
501 * NOTE: openemr doesn't use it in 2008
503 * @param none
504 * @return void
506 function dt_kmt004() {
507 // TO BE IMPLEMENTED
510 //-----------------------------------------------------------------------------
512 * KMN001
514 * The registered primary (main) diagnosis falls under category parameter1 (CL_DIAGNOSE)
516 * Example: if the asked value of CL_DIAGNOSE_CODE is AS1_6 then all CL_DIAGNOSE_CODE
517 * values As1_6* are valid (all values in the same hierarchy)
519 * @param int $node- node to look parameter for
520 * @return bool
522 function dt_kmn001($node) {
523 global $dbcid;
525 $par = dt_whatparam($node, 1);
526 $maindia = df_get_main_diagnose($dbcid);
528 return (strpos($maindia, $par) === 0);
531 //-----------------------------------------------------------------------------
533 * KMP001
535 * NOTE: not used by us
536 * @param none
537 * @return int
539 function dt_kmp001() {
540 return 0;
543 //-----------------------------------------------------------------------------
545 * KMC001
547 * NOTE: openemr doesn't use it in 2008
549 * @param none
550 * @return void
552 function dt_kmc001() {
553 // TO BE IMPLEMENTED
557 //-----------------------------------------------------------------------------
559 * ALL EVENTS FOR A DBC
561 * between opening date and closing date
563 * @param none
564 * @return mysqlresult
566 function dt_allevents() {
567 global $dbcid, $enddate;
569 $dia = content_diagnose($dbcid);
570 $odate = mysql_real_escape_string($dia['ax_odate']);
571 $cdate = ( isset($_SESSION['eind']) && $_SESSION['eind'] ) ? mysql_real_escape_string($_SESSION['eind']) : $enddate;
572 if ( !$cdate ) $cdate = date('Y-m-d'); //as a precaution
573 $pid = ( $dbcid ) ? what_patient($dbcid) : $_SESSION['pid'];
575 // find all events from DBC opening 'till closing date
576 $q = sprintf("SELECT pc_eid, pc_aid FROM openemr_postcalendar_events
577 WHERE pc_pid = %d AND pc_eventDate >= '%s' AND pc_eventDate <= '%s' AND pc_apptstatus = '@' ",
578 $pid, $odate, $cdate);
579 $r = mysql_query($q) or die(mysql_error());
581 return $r;
585 //-----------------------------------------------------------------------------
587 * TIMES FOR AN EVENT
589 * returns direct, indirect and travel time (all in minutes)
591 * @param int $eid - event id
592 * @return array
594 function dt_times($eid = 0) {
595 if ( !$eid ) return 0;
597 // for JOIN - if the second table has inconsistency of data (missing record for an events)
598 // a 'bug' occur and the direct time become 0
599 //$qt = sprintf("SELECT ope.pc_duration, cta.indirect_time, cta.travel_time FROM openemr_postcalendar_events ope JOIN cl_time_activiteit cta ON ope.pc_eid = cta.event_id WHERE pc_eid = %d ", $eid);
600 $qt = sprintf("SELECT pc_duration FROM openemr_postcalendar_events WHERE pc_eid = %d ", $eid);
601 $rt = mysql_query($qt) or die(mysql_error());
602 $rowt = mysql_fetch_array($rt);
604 // direct time
605 $rez['dirtime'] = $rowt['pc_duration'] / 60;
608 $qi = sprintf("SELECT indirect_time, travel_time FROM cl_time_activiteit WHERE event_id = %d ", $eid);
609 $ri = mysql_query($qi) or die(mysql_error());
611 if ( mysql_num_rows($ri) ) {
612 $rowi = mysql_fetch_array($ri);
613 // indirect time
614 $rez['indtime'] = $rowi['indirect_time'];
615 // travel time
616 $rez['tratime'] = $rowi['travel_time'];
617 } else {
618 $rez['indtime'] = $rez['tratime'] = 0;
621 return $rez;
624 //-----------------------------------------------------------------------------
626 * WHAT PRODUCTGROEP
628 * after we have a result, we look up the right productgroep
630 * @param int $rfsum
631 * @param string $endate - ending date for the DBC
632 * @return array - two values id|name
634 function dt_whatproductgroep($rfsum, $endate) {
635 // to avoid the bug: first time, it doesn't display properly
636 if ( !$endate ) {
637 global $dbcid;
638 $dc = content_diagnose($dbcid);
639 $endate = $dc['ax_cdate'];
643 $q = sprintf("SELECT cl_productgroep_sysid as cps, cl_productgroep_beschrijving as cpb
644 FROM cl_productgroep WHERE cl_productgroep_code = %d
645 AND cl_productgroep_begindatum <= '%s' AND cl_productgroep_einddatum >= '%s' ", $rfsum, $endate, $endate);
646 $r = mysql_query($q) or die(mysql_error());
648 $row = mysql_fetch_array($r);
649 $res = array();
650 $res['id'] = $row['cps']; $res['name'] = $row['cpb'];
652 return $res;
655 //-----------------------------------------------------------------------------
657 * SET PRESTATIECODE
659 * last step in the decision tree
660 * if called with $retflag = 1, just return the value
662 * @param int $zsysid - zorg sysid
663 * @param int $pgroep - productgroep sysid
664 * @param int $dbcid - dbcid
665 * @return string|void
667 function dt_prestatiecode($zsysid, $pgroep, $dbcid = 0, $retflag = 0) {
668 $resstr = '';
670 // ZORGTYPE ----------------
671 $qz = sprintf("SELECT cl_zorgtype_prestatiecodedeel AS czp FROM cl_zorg WHERE cl_zorgtype_sysid = %d ", $zsysid);
672 $rz = mysql_query($qz) or die(mysql_error());
673 $rowz = mysql_fetch_array($rz);
675 $czp = (int)$rowz['czp']; $czp = str_pad($czp, 3, '0', STR_PAD_LEFT);
676 $resstr .= substr($rowz['czp'], 0, 3); // only 3 characters allowed
678 // DIAGNOSE ----------------
679 $qd = sprintf("SELECT cl_productgroep_diagnose_blinderen AS cdb, cl_productgroep_code as cpc
680 FROM cl_productgroep WHERE cl_productgroep_sysid = %d ", $pgroep);
681 $rd = mysql_query($qd) or die(mysql_error());
682 $rod = mysql_fetch_array($rd);
684 // posible values 1 - 0
685 if ( $rod['cdb'] == 1 ) {
686 $resstr .= '000';
687 } else {
688 // find CL_DIAGNOSE_PRESTATIECODEDEEL for the main diagnose
689 $maind = df_get_main_diagnose($dbcid);
690 $qpre = sprintf("SELECT cl_diagnose_prestatiecodedeel FROM cl_diagnose WHERE cl_diagnose_code = '%s' ",
691 $maind);
692 $rpre = mysql_query($qpre) or die(mysql_error());
693 $rowpre = mysql_fetch_array($rpre);
695 $resstr .= ( $rowpre['cl_diagnose_prestatiecodedeel'] ) ? $rowpre['cl_diagnose_prestatiecodedeel'] : '000' ;
698 // PRODUCTGROEP CODE ----------------
699 $resstr .= str_pad($rod['cpc'], 6, '0', STR_PAD_LEFT);
701 // save it to the table only if $dbcid is given
702 // otherwise just return the value
703 if ( !$retflag ) {
704 $qu = sprintf("UPDATE cl_axes SET ax_pcode='%s' WHERE ax_id = %d ", $resstr, $dbcid);
705 mysql_query($qu) or die(mysql_error());
706 } else {
707 return $resstr;
711 //-----------------------------------------------------------------------------