Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function report(){
- $this->set('alldrugs', $this->Drug->find('list', array(
- //'cache' => 'drugList',
- //'cacheConfig' => 'sql',
- 'fields' => array('id', 'generic'),
- 'order' => 'Drug.generic',
- 'recursive' => -1,
- )));
- if (!empty($this->data['DrugCalls'])) {
- $this->Session->setFlash(sprintf($this->data['DrugCalls']['DrugList']['id']));
- //$this->redirect(array('controller'=>'drugs','action'=>'generatePatientInfo',$this->data['DrugCalls']['DrugList']['id']));
- }
- }
- function generatePatientInfo($id=null) {
- $this->layout = 'ajax';
- // get drug info
- $drug = $this->Drug->read(
- array(
- 'Drug.id', 'Drug.generic'
- ),
- $id
- );
- $this->set('drug',$drug);
- $patients = $this->Drug->query('SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
- . 'FROM drugs, drug_lactation_links, lactation, calls, patients '
- . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_lactation_links.drug_id AND '
- . 'drug_lactation_links.lactation_id = lactation.id AND lactation.call_id = calls.id AND calls.patient_id = patients.id '
- . 'UNION '
- . 'SELECT patients.id, calls.id call_id, patients.first_name, patients.last_name, patients.phone, patients.email, calls.created '
- . 'FROM drugs, drug_pregnancy_links, pregnancies, calls, patients '
- . 'WHERE drugs.id = ' . $id . ' AND drugs.id = drug_pregnancy_links.drug_id AND '
- . 'drug_pregnancy_links.pregnancy_id = pregnancies.id AND pregnancies.call_id = calls.id AND calls.patient_id = patients.id '
- . 'ORDER BY created DESC'
- );
- $this->set(compact('patients'));
- $this->set('title_for_layout', 'Patient contact information for ' . $drug['Drug']['generic']);
- }
- <?php //report.ctp ?>
- <div>
- <?php echo $form->create('DrugCalls', array('url' => array('controller' => 'drugs', 'action' => 'report')));?>
- <?php //echo $form->create('Patient Calls');?>
- <fieldset>
- <legend><?php printf('Calls for Generic Report'); ?></legend>
- <?php
- echo $form->input('DrugList', array('type' => 'select', 'id' => 'DrugList', 'label' => 'Select generic drug:',
- 'empty' => 'Select', 'options' => $alldrugs)
- );
- echo '<br />NOTE: Select a drug above to generate a list of patients who called about it.' .
- '<br/>' . 'The report will need to be imported into Excel.';
- echo $form->end(__('Submit', true));
- ?>
- </fieldset>
- </div>
- <?php
- //generate_patient_info.ctp
- // add the header row
- $header = array('First Name','Last Name','Phone Number','Email');
- $csv->addRow(array('Enter Generic: ' . $drug['Drug']['generic']));
- $csv->addRow(array('Drug ID: ' . $drug['Drug']['id']));
- $csv->addRow($header);
- // add all the data
- foreach($patients as $patient) {
- $csv->addRow(array(
- $patient[0]['first_name'],
- $patient[0]['last_name'],
- $patient[0]['phone'],
- $patient[0]['email'],
- ));
- }
- $csv->addRow(array());
- // render the CSV file
- echo $csv->render('Patients-list.csv');
- ?>
Add Comment
Please, Sign In to add comment