
DECLARE @OrgId int = (select ID from sCommon.tCompanyInformation Where id > 100);
-- Fit
IF NOT EXISTS (
    SELECT 1 FROM sExamination.tOPDFitnessStatus 
    WHERE FitnessStatusId = 1 AND OrgId = @OrgId
)
BEGIN
    INSERT INTO sExamination.tOPDFitnessStatus
    (FitnessStatusId, Code, Title, IsObsolete, OrgId, CreatedUserId, CreatedDateTime)
    VALUES
    (1, 'FT', 'Fit', 0, @OrgId, 1, sCommon.fGetDate())
END

-- UnFit
IF NOT EXISTS (
    SELECT 1 FROM sExamination.tOPDFitnessStatus 
    WHERE FitnessStatusId = 2 AND OrgId = @OrgId
)
BEGIN
    INSERT INTO sExamination.tOPDFitnessStatus
    (FitnessStatusId, Code, Title, IsObsolete, OrgId, CreatedUserId, CreatedDateTime)
    VALUES
    (2, 'UFT', 'UnFit', 0, @OrgId, 1, sCommon.fGetDate())
END

-- Fit for limited duties
IF NOT EXISTS (
    SELECT 1 FROM sExamination.tOPDFitnessStatus 
    WHERE FitnessStatusId = 3 AND OrgId = @OrgId
)
BEGIN
    INSERT INTO sExamination.tOPDFitnessStatus
    (FitnessStatusId, Code, Title, IsObsolete, OrgId, CreatedUserId, CreatedDateTime)
    VALUES
    (3, 'FLD', 'Fit for limit duties', 0, @OrgId, 1, sCommon.fGetDate())
END

-- Fit after corrective measure
IF NOT EXISTS (
    SELECT 1 FROM sExamination.tOPDFitnessStatus 
    WHERE FitnessStatusId = 4 AND OrgId = @OrgId
)
BEGIN
    INSERT INTO sExamination.tOPDFitnessStatus
    (FitnessStatusId, Code, Title, IsObsolete, OrgId, CreatedUserId, CreatedDateTime)
    VALUES
    (4, 'FCMA', 'Fit after corrective measure with medical advice', 0, @OrgId, 1, sCommon.fGetDate())
END

-- Temporary Unfit
IF NOT EXISTS (
    SELECT 1 FROM sExamination.tOPDFitnessStatus 
    WHERE FitnessStatusId = 5 AND OrgId = @OrgId
)
BEGIN
    INSERT INTO sExamination.tOPDFitnessStatus
    (FitnessStatusId, Code, Title, IsObsolete, OrgId, CreatedUserId, CreatedDateTime)
    VALUES
    (5, 'TUF', 'Temporary Unfit', 0, @OrgId, 1, sCommon.fGetDate())
END

update OFS set OFS.Code = SOFS.Code, OFS.Title = SOFS.Title, 
	   OFS.CreatedUserId = 1, CreatedDateTime = sCommon.fGetDate()
from sExamination.tOPDFitnessStatus OFS
INNER JOIN sExamination.tStaticOPDFitnessStatusMaster SOFS ON SOFS.Id = OFS.FitnessStatusId

-----------------------------------------------------------------------------------------------------------

INSERT INTO sExamination.tVisitTypeMaster
VALUES (1,'Direct Consultation','Direct Consultation',0,1,1,sCommon.fGetDate(),1,sCommon.fGetDate())
INSERT INTO sExamination.tVisitTypeMaster
VALUES (2,'Tele Consultation','Tele Consultation',0,1,1,sCommon.fGetDate(),1,sCommon.fGetDate())
INSERT INTO sExamination.tVisitTypeMaster
VALUES (3,'Virtual Consultation','Virtual Consultation',0,1,1,sCommon.fGetDate(),1,sCommon.fGetDate())