<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Reports extends Provider_Controller {

    public function index() {
        $data = array();
        $this->renderProviderSecurePage('reports/report', $data);
    }

    public function report(){
    	$this->index();
    }
    public function addnew() {
        $data = array();
	    $data["account_message"] = "";
	    $data["firstname"] = $data["lastname"] = $data["email"] = $data["password"]= $data["street1"] = $data["street2"]= $data["city"] = $data["zipcode"]="";
         if ($_POST){
		$data['password'] = trim($this->input->post('password'));	 
	    $data['practice_id'] = $_SESSION['practice_id'];
		$data['practice_user_id'] = $_SESSION['practice_id'];
		$data['username'] = "NON-USER-".rand(1000000,99999999);
        $data['password'] = "NON-USER-".rand(1000000,99999999);
	    $data['country'] = "NG";
		$data['firstname'] = trim($this->input->post('firstname'));
		$data['lastname']   = trim($this->input->post('lastname'));
		$data['email'] = trim($this->input->post('email'));
		
		$data['street1'] = trim($this->input->post('street1'));
		$data['street2'] = trim($this->input->post('street2'));
		$data['city'] = trim($this->input->post('city'));
		$data['state'] = trim($this->input->post('state'));
$data["loc"] = $_SERVER["REMOTE_ADDR"];

  		$data["action"] = MERMS_PROVIDERS_CREATEMEMBER;
  		$out = array();
		$ret = $this->mermsemr_api($data, $out);
 		$data["account_message"] = "This is the return ".$ret;
            echo "Posted";
         }

        $out = array();
        $out =  $this->getPatientList();
        $data["patient_list"] = $out["patient_list"]; 


        $this->renderProviderSecurePage('patient/newpatient', $data);
    }

    private function getPatientList(){
        
        $mysql = "SELECT p.practice_id,p.id AS patient_id,p.member_id,p.long_id,m.firstname,m.lastname,m.phone,p.added " 
		         ." FROM patients p LEFT JOIN members m ON m.id=p.member_id ORDER BY p.added DESC";
	    $query = $this->db->query($mysql);
        $num = $query->num_rows();
        $data["patient_list"] = $query->result();
        return $data;
     }
    
}
