DROP PROCEDURE IF EXISTS hms.Select_Parameter1;
CREATE PROCEDURE hms.`Select_Parameter1`(_Branch_Id int,
_Tenant_Id int,
_disease_Id int,_ParameterId int,_Patient_Id int)
BEGIN
IF EXISTS
(SELECT b.Target_Value
FROM patient_progress_tracking_header b
WHERE b.DiseaseId = _disease_Id)
THEN
SELECT a.ParameterName,
b.Target_Value,
b.Measurement_Frequency,
date_format(c.Last_Date,"%y/%d/%m") as 'Last_Date',
c.Result,
date_format(c.Next_Due_Date,"%y/%d/%m") as 'Next_Due_Date',
date_format(c.Current_Test_Date,"%y/%d/%m") as 'Current_Test_Date',
c.Test_Result,
b.ParameterId
FROM patient_progress_tracking_header b
RIGHT JOIN Disease_parameter a
ON b.DiseaseId=a.DiseaseId
INNER JOIN patient_progress_tracking_details c
ON b.DiseaseId = c.DiseaseId
WHERE a.Branch_Id = _Branch_Id
AND a.Tenant_Id = _Tenant_Id
AND a.DiseaseId = _disease_Id
AND a.Patient_Id=_Patient_Id;
ELSE
Insert Into patient_progress_tracking_header(Branch_Id,Tenant_Id,Patient_Id,DiseaseId)values(_Branch_Id,_Tenant_Id,_Patient_Id,_disease_Id);
Insert Into patient_progress_tracking_details(DiseaseId,Patient_Id,Branch_Id,Tenant_Id)values(_disease_Id,_Patient_Id,_Branch_Id,_Tenant_Id);
SELECT a.ParameterName,
a.Target_Value,
b.Measurement_Frequency,
date_format(c.Last_Date,"%y/%d/%m") as 'Last_Date',
c.Result,
date_format(c.Next_Due_Date,"%y/%d/%m") as 'Next_Due_Date',
date_format(c.Current_Test_Date,"%y/%d/%m") as 'Current_Test_Date',
c.Test_Result,
b.ParameterId
FROM patient_progress_tracking_header b
RIGHT JOIN Disease_parameter a
ON b.DiseaseId =a.DiseaseId
INNER JOIN patient_progress_tracking_details c
ON b.DiseaseId = c.DiseaseId
WHERE a.Branch_Id = _Branch_Id
AND a.Tenant_Id = _Tenant_Id
AND a.DiseaseId = _disease_Id
AND a.Patient_Id=_Patient_Id;
END IF;
END;
thsi is my procedure..
in else part first time all the parametername and targetvalue are coming from Disease_Parameter table but when all the value get inserted into othe two tables..only one parametername is getting Proper DiseasId...Other parameter gets 0 DiseasId...It should be also take same DiseaseID.