Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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.
Posted
Updated 30-Dec-12 23:17pm
v5

1 solution

refer below links:
Link 1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900