<?
include_once('report_mo3.php') ;
class report_mo_sess extends report_mo3
{
 var $title='Журнал МО - сеансы МО' ;
 var $view_only_model=0 ;
 var $mo_sort='pkey desc' ;
 var $recs_doctor=array() ;
 var $allow_export_to_csv=1 ;

 // шаблон - вывод ссылками без разделитея
 function print_template_HTML($list_recs,$options=array())
 {     //print_2x_arr($list_recs) ;
       $id=($options['id'])? 'id='.$options['id']:'' ;
       //$arr_member_views=
       ?><div class=list_mo_sessions_report <?echo $id?>>
         <table class="report_mo_sess" >
           <colgroup><col id="c0"><col id="c1"><col id="c3"><col id="c4"><col id="c11"><col id="c12"><col id="c13"></colgroup>
           <tr><th>№</th>
               <th>Дата/время</th>
               <?if (MEMBER()->rol==1){?><th>Сессия МО</th><?}?>
               <th>ФИО<br>сотрудника</th>
               <th>Модель</th>
               <th>Терминал/Врач</th>
               <th>Давление</th>
               <th>Пульс</th>
               <th>Температура</th>
               <th>Алкоголь</th>
               <th>ЦНС</th>
               <th>Жалобы</th>
               <th>Результат осмотра<br>на терминале</th>
               <th>Признаки заболевания<br>и пониженной<br>работоспособности</th>
               <th>Комментарий врача</th>
               <th>Результат осмотра</th>
               <th>Допуск</th>
           </tr><?
           $i=$this->first_obj ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
           {  $this->view_tr_item($i,$rec) ;
              if ($rec['mo1_id'])
              { $rec_prev_mo=ESMO()->get_mo_by_id_now($rec['mo1_id']) ;
                if ($rec_prev_mo)
                { $this->view_tr_item('',$rec_prev_mo,array('tr_class'=>'history')) ;
                  if ($rec_prev_mo['mo1_id'])
                  { $rec_prev_mo2=ESMO()->get_mo_by_id_now($rec_prev_mo['mo1_id']) ;
                    if ($rec_prev_mo2) { $this->view_tr_item('',$rec_prev_mo2,array('tr_class'=>'history')) ;
                                         //unset($list_recs[$rec_prev_mo['mo1_id']]) ;
                                       }
                  }
                  ?><tr><td colspan="9"></td></tr><?
                  //unset($list_recs[$rec['mo1_id']]) ;
                }
              }
              $i++ ;
           }
         ?></table></div>
           <style>
              table.report_mo_sess{}
              table.report_mo_sess td.dopusk_1{color:green;}
              table.report_mo_sess td.dopusk_2{color:#D70300;}
              table.report_mo_sess td.name a{color:black;text-decoration:none;}
              table.report_mo_sess td.name a:hover{text-decoration:underline;}
              table.report_mo_sess tr.history td{background-color:rgba(185, 221, 253, 0.15);;}
           </style>
        <?
        //damp_array($rec,1,-1) ;
     }

     function view_tr_item($i,$rec,$options=array())
     {   if (!isset($recs_doctor[$rec['doctor_id']])) $this->recs_doctor[$rec['doctor_id']]=ACCOUNTS()->get_member_by_id($rec['hand_check_user_id']) ;

         ?><tr class="item <?echo $options['tr_class']?>">
            <td><?echo $i ;?></td>
            <td><?echo date('d.m.Y',$rec['c_data']).'<br>'.date('H:i:s',$rec['c_data'])?><br>
                <?echo $_SESSION['ARR_mo_tk_type'][$rec['tk']] ; ?><br>#<?echo '<a href="/cab/mo/'.$rec['pkey'].'/" target=_blank>'.$rec['pkey'].'</a>'?>

            </td>
            <?if (MEMBER()->rol==1){?><td><?echo $rec['session_id']?><br><?echo date('H:i:s',$rec['session_id'])?></td><?}?>
            <?/*<td><?echo $rec['_org_name'].'<br>'.$rec['_otdel_name']?></td>*/?>
            <td class="name"><?if ($rec['member_id'])
                { echo '<strong><a href="/cab/personal/person/'.$rec['member_id'].'/">'.$rec['member_name'].'</a></strong>'?><br><?
                  if ($rec['member_dr']) echo $rec['member_dr'].'<br>' ;
                  echo (($rec['member_pol'])? 'Женский':'Мужской').'<br>' ;
                  echo 'Пропуск: <strong>'.$rec['propusk'].'</strong>';
                }
                ?>
            </td>
            <td><?echo $_SESSION['ARR_model_osmotr'][$rec['model']]?></td>
            <td><?if ($rec['terminal_id']) echo $rec['terminal_id'] ;
                  if ($rec['hand_check_user_id']) echo $this->recs_doctor[$rec['hand_check_user_id']]['obj_name'] ;
                ?>
            </td>
            <td><?if ($rec['tonometer']) echo (($rec['systolic'])? $rec['systolic']:'-').' / '.(($rec['diastolic'])? $rec['diastolic']:'-')?></td>
            <td><?if ($rec['pulsometer']) echo ($rec['pulse'])? $rec['pulse']:'-';?></td>
            <td><?if ($rec['thermometer']) echo ($rec['temperature']>0)? $rec['temperature']:'-';?></td>
            <td><?echo ($rec['alko']>0)? '<span class="red bold">Есть</span>'.(($rec['alko_value']>0)? ' ('.$rec['alko_value'].')':''):($rec['alcotester']? 'Нет':'-');?></td>
            <td><?if ($rec['pupilometer']) echo ($rec['narko'])? '<span class="red bold">Не пройден</span>':'Нет';?></td>
            <td><? if ($rec['status']>=2 and $rec['status']<=3) echo ($rec['question'])? '<span class="red bold">Есть</span>':'Нет' ; else echo '-' ;
                   if ($rec['question_comment']) echo '<br>'.$rec['question_comment'] ;
                ?>
            </td>
            <td class="comment"><? if ($rec['_comment']) echo '<div class=red>'.$rec['_comment'].'</div>' ; ?></td>
            <td><?  if ($rec['doctor_fixed_comment']) echo $rec['doctor_fixed_comment'].'<br>' ;
                    echo ($rec['simptoms'])? '<span class="red bold">Есть</span>':''?><br><?echo _IL('IL_diagnoz')->recs[$rec['simptoms']]['obj_name']?></td>
            <td><?echo ($rec['doctor_comment'])? $rec['doctor_comment']:''?></td>
            <td><? echo $rec['_status_name'] ; ?></td>
            <td class="dopusk_<?echo $rec['dopusk']?>"><? echo $rec['_dopusk_status']?></td>
        </tr><?
     }

    function print_template_CSV($list_recs,$options=array())
         { $i=$options['from'] ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
             { $data=array() ;
               $data['MO ID']=$rec['pkey'] ;
               $data['Дата']=date('d.m.Y',$rec['c_data']) ;
               $data['Время']=date('H:i:s',$rec['c_data']) ;
               $data['Терминал']=$rec['terminal_id'] ;
               $data['Тип контроля']=$_SESSION['ARR_mo_type'][$rec['mo_type']] ;
               $data['Модель']=$_SESSION['ARR_model_osmotr'][$rec['model']] ;
               $data['ФИО сотрудника']=$rec['member_name'] ;
               $data['ДатаРожд']=$rec['member_dr'] ;
               $data['Возраст']=$rec['age'] ;
               $data['Пол']=($rec['member_pol'])? 'Женский':'Мужской' ;
               $data['Пропуск']='"'.$rec['propusk'].'"';
               $data['Терминал/Врач']=($rec['hand_check_user_id'])? $this->recs_doctor[$rec['hand_check_user_id']]['obj_name']:$rec['terminal_id']  ;
               $data['Давление']=($rec['tonometer'])? (($rec['systolic'])? $rec['systolic']:'-').' / '.(($rec['diastolic'])? $rec['diastolic']:'-'):''  ;
               $data['Пульс']=($rec['pulsometer'])? (($rec['pulse'])? $rec['pulse']:'-'):'';  ;
               $data['Температура']=($rec['thermometer'])? (($rec['temperature']>0)? $rec['temperature']:'-'):'';  ;
               $data['Алкоголь']=($rec['alko']>0)? 'Есть'.(($rec['alko_value']>0)? ' ('.$rec['alko_value'].')':''):($rec['alcotester']? 'Нет':'-')  ;
               $data['Жалобы']=($rec['status']>=2 and $rec['status']<=3)? ($rec['question'])? 'Есть':'Нет':'-'   ;
                               if ($rec['question_comment']) $data['Жалобы'].=' '.$rec['question_comment'] ;
               $data['Результат осмотра на терминале']=($rec['_comment'])? strip_tags($rec['_comment']):'-'   ;
               $data['ПЗиПР']=(($rec['simptoms'])? 'Есть':'')._IL('IL_diagnoz')->recs[$rec['simptoms']]['obj_name'] ;
               $data['Комментарий врача']=($rec['doctor_comment'])? $rec['doctor_comment']:'' ;
               $data['Результат осмотра']=strip_tags($rec['_status_name']);
               $data['Допуск']=strip_tags($rec['_dopusk_name']);


               $this->put_data_to_CSV($data,$i) ;
               $i++ ;
             }

         }


}

?>
