Guest User

Untitled

a guest
Jan 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. function report(){
  2. $this->set('alldrugs', $this->Drug->find('list', array(
  3. //'cache' => 'drugList',
  4. //'cacheConfig' => 'sql',
  5. 'fields' => array('id', 'generic'),
  6. 'order' => 'Drug.generic',
  7. 'recursive' => -1,
  8. )));
  9. if (!empty($this->data['DrugCalls'])) {
  10. $this->Session->setFlash(sprintf($this->data['DrugCalls']['DrugList']['id']));
  11. //$this->redirect(array('controller'=>'drugs','action'=>'generatePatientInfo',$this->data['DrugCalls']['DrugList']['id']));
  12. }
  13. }
  14.  
  15. function generatePatientInfo($id=null) {
  16. $this->layout = 'ajax';
  17. // get drug info
  18. $drug = $this->Drug->read(
  19. array(
  20. 'Drug.id', 'Drug.generic'
  21. ),
  22. $id
  23. );
  24. $this->set('drug',$drug);
  25. $patients = $this->Drug->query('SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
  26. . 'FROM drugs, drug_lactation_links, lactation, calls, patients '
  27. . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_lactation_links.drug_id AND '
  28. . 'drug_lactation_links.lactation_id = lactation.id AND lactation.call_id = calls.id AND calls.patient_id = patients.id '
  29. . 'UNION '
  30. . 'SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
  31. . 'FROM drugs, drug_pregnancy_links, pregnancies, calls, patients '
  32. . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_pregnancy_links.drug_id AND '
  33. . 'drug_pregnancy_links.pregnancy_id = pregnancies.id AND pregnancies.call_id = calls.id AND calls.patient_id = patients.id '
  34. . 'ORDER BY created DESC'
  35. );
  36. $this->set(compact('patients'));
  37. $this->set('title_for_layout', 'Patient contact information for ' . $drug['Drug']['generic']);
  38. }
  39.  
  40. <?php //report.ctp ?>
  41. <div>
  42.  
  43. <?php echo $form->create('DrugCalls', array('url' => array('controller' => 'drugs', 'action' => 'report')));?>
  44. <?php //echo $form->create('Patient Calls');?>
  45. <fieldset>
  46. <legend><?php printf('Calls for Generic Report'); ?></legend>
  47. <?php
  48. echo $form->input('DrugList', array('type' => 'select', 'id' => 'DrugList', 'label' => 'Select generic drug:',
  49. 'empty' => 'Select', 'options' => $alldrugs)
  50. );
  51. echo '<br />NOTE: Select a drug above to generate a list of patients who called about it.' .
  52. '<br/>' . 'The report will need to be imported into Excel.';
  53. echo $form->end(__('Submit', true));
  54. ?>
  55. </fieldset>
  56. </div>
  57.  
  58.  
  59.  
  60. <?php
  61. //generate_patient_info.ctp
  62. // add the header row
  63. $header = array('First Name','Last Name','Phone Number','Email');
  64.  
  65. $csv->addRow(array('Enter Generic: ' . $drug['Drug']['generic']));
  66. $csv->addRow(array('Drug ID: ' . $drug['Drug']['id']));
  67. $csv->addRow($header);
  68.  
  69. // add all the data
  70. foreach($patients as $patient) {
  71. $csv->addRow(array(
  72. $patient[0]['first_name'],
  73. $patient[0]['last_name'],
  74. $patient[0]['phone'],
  75. $patient[0]['email'],
  76. ));
  77. }
  78. $csv->addRow(array());
  79.  
  80. // render the CSV file
  81. echo $csv->render('Patients-list.csv');
  82. ?>
Add Comment
Please, Sign In to add comment