
DECLARE @OrgId int = 9999;

Declare @maxPrefixId int;
set @maxPrefixId = (select max(Id) + 1 from [sCommon].[tPrefixSetup]);

INSERT INTO [sCommon].[tPrefixSetup]
(
    OrgId,
    StoreLocationId,
    Id,
    PrefixFunctionalityId,
    Prefix,
    EffectiveDate,
    IsObsolete,
    CreatedUserId,
    CreatedDateTime,
    UpdatedUserId,
    UpdatedDateTime,
    Seed,
    CurrentNumber,
    NumberLength
)
VALUES
(
    @OrgId,
    0,
    @maxPrefixId,
    1022,
    'WA',
    sCommon.fGetDate(),
    0,
    1,
    sCommon.fGetDate(),
    1,
    sCommon.fGetDate(),
    1,
    0,
    5
);

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

IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tAppointment'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tAppointment', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tWellnessRegistration'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tWellnessRegistration', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tGeneralTemplateConsultation'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tGeneralTemplateConsultation', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tConsultationTestRequest'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tConsultationTestRequest', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tConsultationAdditionalFieldMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tConsultationAdditionalFieldMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tProgramMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tProgramMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sHospitalization.tClaimIntimationAssignedDoctor'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sHospitalization.tClaimIntimationAssignedDoctor', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tWellnessActivityCategoryMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tWellnessActivityCategoryMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tWellnessActivityTaskMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tWellnessActivityTaskMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tWellnessActivityMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tWellnessActivityMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tMHIScore'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tMHIScore', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END
IF NOT EXISTS (
    SELECT 1 
    FROM [sCommon].[tTableRowId] 
    WHERE TableTitle = 'sWellness.tWellnessVisitPurposeMaster'
)
BEGIN
    INSERT INTO [sCommon].[tTableRowId]
    (OrgId, TableTitle, CurrentNumber, Seed, Increment, DataType, UpdatedDateTime)
    VALUES (@OrgId, 'sWellness.tWellnessVisitPurposeMaster', [sCommon].[fGetIntIdForOrg](0, @OrgId), 1, 1, NULL, sCommon.fGetDate())
END

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

INSERT INTO [sExamination].[tSetupGroupMaster]
(
    Id,
    OrgId,
    Code,
    Title,
    MainTypeId,
    IsObsolete,
    CreatedUserId,
    CreatedDateTime,
    UpdatedUserId,
    UpdatedDateTime,
    IsActive,
    OrderIndex,
    IsPublish,
    SetupGroupTypeId,
    IsProviderHealthCheckup,
    AssignStatusId,
    PageLimit
)
VALUES
(
   [sCommon].[fGetIntIdForOrg](17,@OrgId),
    @OrgId,
    'Wellness Consultation',
    'Wellness Consultation',
    17,
    0,
    1,
    sCommon.fGetDate(),
    1,
    sCommon.fGetDate(),
    1,
    NULL,
    1,
    NULL,
    NULL,
    NULL,
    NULL
);

INSERT INTO [sExamination].[tSetupMaster]
(
    Id,
    OrgId,
    Title,
    SubTypeId,
    FromDate,
    ToDate,
    RoundNumber,
    Remark,
    ParticipantTypeId,
    GenderId,
    AgeFrom,
    AgeTo,
    GradeFrom,
    GradeTo,
    ProcessTypeId,
    IsObsolete,
    CreatedUserId,
    CreatedDateTime,
    UpdatedUserId,
    UpdatedDateTime,
    StoreLocationId,
    IsClosed,
    SetupGroupId,
    IsPublishSetup,
    IsDiagnosisTrackerUpdated,
    IsHealthIndexUpdated,
    IsEmployeeHistoryUpdated,
    IsTargetGroupRestrictInHR,
    UId,
    AppointerId
)
VALUES
(
    [sCommon].[fGetIntIdForOrg](17,@OrgId),
    @OrgId,
    'Wellness Consultation',
    17,
    '1900-01-01',
    '2500-01-01',
    1,
    'Wellness Consultation',
    95,
    0,
    0,
    100,
    NULL,
    NULL,
    NULL,
    0,
    1,
    sCommon.fGetDate(),
    1,
    sCommon.fGetDate(),
    0,
    0,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
);