<?php
namespace App\Controllers;

use CodeIgniter\RESTful\ResourceController;

class API_DashboardTM extends ResourceController {
	protected $format = 'json';
    
	public function index() {
		$db = \Config\Database::connect();
		$date1 = $this->request->getPost('date1');
		$date2 = $this->request->getPost('date2');
		$sql = "select r.REQID, r.REFFID, sr.SP_ACCESSNUMBER, r.REQTYPE, p.PATNUMBER, p.FIRSTNAME, p.LASTNAME, r.REQDATE, r.LOGDATE,
TESTS = STUFF((
	SELECT ', ',HISCODE
	FROM cmod.dbo.CM_TM_TESTS
	WHERE REQID= r.REQID
	FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
from cmod.dbo.CM_TM_REQUESTS r 
left join cmod.dbo.CM_TM_PATIENTS p on r.PATID=p.PATID
left join SP_REQUESTS sr on sr.HOSTORDERNUMBER=r.REFFID
--where r.REQDATE between '$date1 00:00' and '$date2 23:59'";
		$query = $db->query($sql);
		$results = $query->getResultArray();
		$data['data'] = $results;
        return $this->respond($data,200);
    }
}
