select vd.OPNO as EMR,vd.id as VISITID,vd.CreatedDate as VISITDATE,pm.gender as GENDER, CONCAT(TIMESTAMPDIFF(YEAR, pm.DOB, now()),
' Years,',
TIMESTAMPDIFF(MONTH, pm.DOB, now()) % 12,
' Months,',
FLOOR(TIMESTAMPDIFF(DAY, pm.DOB, now()) % 30.4375),
' Days') as age,nu.SyBP as SYSTOLICBP,nu.DiBP as DIASTOLICBP,
IFNULL((SELECT
DATE_FORMAT(CreatedDate, '%d-%m-%Y')
FROM
visitdetails
WHERE
PatientID = pm.ID AND Status != 2
ORDER BY CreatedDate DESC LIMIT 1),'N/A') AS LastVisitDate,
GROUP_CONCAT(dm.Code,'-', '' SEPARATOR '; ') as Diagnosis
from nursingdetails nu inner join visitdetails vd on vd.id=nu.visitid
inner join patientmaster pm on pm.id=vd.patientid
inner join diagnosisdetails dg on dg.visitid=vd.id
inner join diagnosismaster dm on dm.id=dg.IcdId where date(vd.createdDate)>'2023-03-20' group by vd.id;