stable, before a refactor
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
class CallStoredProc
|
||||
def initialize(procedure_name, args = {})
|
||||
@procedure_name = procedure_name
|
||||
@args = args
|
||||
end
|
||||
|
||||
def call
|
||||
params_sql = @args.map { |key, value| "@#{key} = :#{key}" }.join(', ')
|
||||
sql_template = "EXEC #{@procedure_name} #{params_sql}"
|
||||
sanitized_sql = VhcsRecord.send(:sanitize_sql_array, [sql_template, @args])
|
||||
|
||||
VhcsRecord.connection.exec_query(sanitized_sql)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,94 @@
|
||||
class GetAllIDCardDataByPlanTPAQuery
|
||||
|
||||
def initialize(pl_plan_key)
|
||||
@pl_plan_key = ActiveRecord::Base.connection.quote(pl_plan_key)
|
||||
end
|
||||
|
||||
def call
|
||||
VhcsRecord.connection.exec_query(sql).rows
|
||||
end
|
||||
|
||||
def to_id_cards_data
|
||||
raw_data = call
|
||||
|
||||
all_id_cards_data = []
|
||||
raw_data.each do |rd|
|
||||
id_card_data = {
|
||||
id: rd[0],
|
||||
mb_member_key: rd[1],
|
||||
mbr_type: rd[2],
|
||||
division: rd[3],
|
||||
full_name: rd[7],
|
||||
family_id: rd[8],
|
||||
mbr_class: rd[9],
|
||||
effect_date: rd[11],
|
||||
state: rd[12],
|
||||
pl_plan_key: rd[14],
|
||||
group_number: rd[15],
|
||||
medical_group_num: rd[16],
|
||||
dental_group_num: rd[17],
|
||||
pb_product_key: rd[18],
|
||||
mb_member_key: rd[19]
|
||||
}
|
||||
|
||||
all_id_cards_data.push(id_card_data)
|
||||
end
|
||||
|
||||
all_id_cards_data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sql
|
||||
<<~SQL
|
||||
SELECT DISTINCT ROW_NUMBER() OVER(ORDER BY pbm.FamilyId ASC) as Id, pbc.MBMemberKey,
|
||||
CASE WHEN div.PBENtityKey = 344215 OR div.PBENtityKey = 344217 THEN 'OSB' ELSE ou.CompanyNumber END as MbrType,
|
||||
substring(div.LastName,0,41) as Div ,
|
||||
substring(pbe.FirstName,0,25) as MbrFirst,
|
||||
substring(pbe.MiddleName,0,25) as MbrMiddle,
|
||||
substring(pbe.LastName,0,50) as MbrLast,
|
||||
(substring(pbe.FirstName, 0, 25) + ' ' + substring(pbe.LastName, 0, 50)) as FullName,
|
||||
pbm.FamilyId,
|
||||
UPPER(lct.shortdesc) as MbrClass,
|
||||
2 as MedOrDent,pp.InEffect as EffectDate,
|
||||
pbea.State,ISNULL(oua.State,pbea.State) as EmpState,
|
||||
M.PLPlanKey,
|
||||
PC.GroupNumber,
|
||||
PC.MedicalNumber,
|
||||
PC.DentalNumber,
|
||||
P.PBProductKey,
|
||||
m.PBEntityKey as PrimaryMBMemberKey
|
||||
FROM VWMBMember M INNER JOIN PBEntityClaimsData pbc on pbc.MBMemberKey=M.MBMemberKey
|
||||
LEFT OUTER Join HLPlanCode PC ON PC.PlanKey = M.PLPlanKey
|
||||
INNER JOIN PBMember pbm on pbm.PBEntityKey=pbc.PBEntityKey and pbm.EnrolleeTypeKey=1044
|
||||
INNER JOIN PBEntity pbe on pbe.PBEntityKey=pbm.PBEntityKey
|
||||
INNER JOIN PBEntityAddress pbea on pbea.PBEntityKey=pbe.PBEntityKey and pbea.AddressTypeID=1137
|
||||
INNER JOIN PBCoveredEntities ce on ce.PBEntityKey=pbe.PBEntityKey
|
||||
INNER JOIN PBProductParticipation pp on pp.PBProductParticipationKey=ce.PBProductParticipationKey
|
||||
INNER JOIN (SELECT ce1.PBEntityKey, pp1.PBProductAvailabilityKey, MAX(pp1.WhenLastChanged) as WhenLastChanged,
|
||||
pp1.CoverageTypeCode
|
||||
FROM PBCoveredEntities ce1
|
||||
INNER JOIN PBProductParticipation pp1 on pp1.PBProductParticipationKey = ce1.PBProductParticipationKey
|
||||
GROUP BY ce1.PBEntityKey, pp1.PBProductAvailabilityKey,pp1.CoverageTypeCode)
|
||||
cepp ON cepp.PBEntityKey = ce.PBEntityKey AND cepp.PBProductAvailabilityKey = pp.PBProductAvailabilityKey
|
||||
and cepp.CoverageTypeCode = pp.CoverageTypeCode
|
||||
INNER JOIN GEN_LookupTables lct ON lct.RecordID = pp.CoverageTypeCode
|
||||
INNER JOIN PBProductAvailability pa on pa.PBProductAvailabilityKey=pp.PBProductAvailabilityKey
|
||||
INNER JOIN PBProduct p on p.PBProductKey=pa.PBProductKey
|
||||
INNER JOIN PBAffiliation aff ON aff.PBAffiliationKey = pp.PBAffiliationKey
|
||||
INNER JOIN PBEntity div on div.PBEntityKey=aff.ParentPBEntityKey
|
||||
LEFT OUTER JOIN PBOrgUnit ou on ou.PBEntityKey=div.PBEntityKey
|
||||
LEFT OUTER JOIN PBEntityAddress oua on oua.PBEntityKey=ou.PBEntityKey and oua.AddressTypeID=1137 WHERE p.PBProductKey in (Select DISTINCT PBProductKey From PBProduct Where FullDescription NOT LIKE '%LIFE%' AND FullDescription NOT LIKE '%VIS%')
|
||||
AND pp.InEffect <= getdate() +90
|
||||
AND (pp.OutOfEffect-1 > getdate() AND
|
||||
pp.OutOfEffect>pp.InEffect)
|
||||
AND pp.OutOfEffect=(Select Max(Part.OutOfEffect) From PBProductParticipation Part
|
||||
INNER JOIN PBProductAvailability Aval on Aval.PBProductAvailabilityKey=Part.PBProductAvailabilityKey
|
||||
INNER JOIN PBProduct Prod on Prod.PBProductKey=Aval.PBProductKey
|
||||
Where Prod.PBProductKey = p.PBProductKey
|
||||
AND Part.PBProductParticipationKey = pp.PBProductParticipationKey)
|
||||
AND M.EnrolleeTypeKey = '1044'
|
||||
AND M.PLPlanKey = #{@pl_plan_key}
|
||||
SQL
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,95 @@
|
||||
class GetIdCardDataTpaQuery
|
||||
def initialize(family_id)
|
||||
@family_id = ActiveRecord::Base.connection.quote(family_id)
|
||||
if family_id.length == 9
|
||||
@entity_type = ActiveRecord::Base.connection.quote("FamilyId")
|
||||
else
|
||||
@entity_type = ActiveRecord::Base.connection.quote("PBEntityKey")
|
||||
end
|
||||
end
|
||||
|
||||
def call
|
||||
VhcsRecord.connection.exec_query(sql).rows.first
|
||||
end
|
||||
|
||||
def to_id_card_data
|
||||
raw_data = call
|
||||
|
||||
id_card_data = {
|
||||
id: raw_data[0],
|
||||
mb_member_key: raw_data[1],
|
||||
mbr_type: raw_data[2],
|
||||
division: raw_data[3],
|
||||
full_name: raw_data[7],
|
||||
family_id: raw_data[8],
|
||||
mbr_class: raw_data[9],
|
||||
effect_date: raw_data[11],
|
||||
state: raw_data[12],
|
||||
pl_plan_key: raw_data[14],
|
||||
group_number: raw_data[15],
|
||||
medical_group_num: raw_data[16],
|
||||
dental_group_num: raw_data[17],
|
||||
pb_product_key: raw_data[18],
|
||||
mb_member_key: raw_data[19]
|
||||
}
|
||||
|
||||
[id_card_data]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sql
|
||||
<<~SQL
|
||||
SELECT DISTINCT ROW_NUMBER() OVER(ORDER BY pbm.FamilyId ASC) as Id, pbc.MBMemberKey,
|
||||
isnull(ou.CompanyNumber,'') as MbrType,
|
||||
CASE WHEN m.PLPlanKey = '14' THEN 'DUPLIN COUNTY GOVERNMENT' ELSE substring(div.LastName,0,41) END as Div,
|
||||
substring(pbe.FirstName,0,25) as MbrFirst,
|
||||
substring(pbe.MiddleName,0,25) as MbrMiddle,
|
||||
substring(pbe.LastName,0,50) as MbrLast,
|
||||
(substring(pbe.FirstName, 0, 25) + ' ' + substring(pbe.LastName, 0, 50)) as FullName,
|
||||
pbm.FamilyId,
|
||||
UPPER(lct.shortdesc) as MbrClass,
|
||||
2 as MedOrDent,
|
||||
pp.InEffect as EffectDate,
|
||||
pbea.State,ISNULL(oua.State,pbea.State) as EmpState,
|
||||
M.PLPlanKey,
|
||||
PC.GroupNumber,
|
||||
PC.MedicalNumber,
|
||||
PC.DentalNumber,
|
||||
P.PBProductKey,
|
||||
m.PBEntityKey as PrimaryMBMemberKey
|
||||
FROM VWMBMember M
|
||||
INNER JOIN PBEntityClaimsData pbc on pbc.MBMemberKey=M.MBMemberKey
|
||||
Inner Join HLPlanCode PC ON PC.PlanKey = M.PLPlanKey
|
||||
INNER JOIN PBMember pbm on pbm.PBEntityKey=pbc.PBEntityKey and pbm.EnrolleeTypeKey=1044
|
||||
INNER JOIN PBEntity pbe on pbe.PBEntityKey=pbm.PBEntityKey
|
||||
INNER JOIN PBEntityAddress pbea on pbea.PBEntityKey=pbe.PBEntityKey and pbea.AddressTypeID=1137
|
||||
INNER JOIN PBCoveredEntities ce on ce.PBEntityKey=pbe.PBEntityKey
|
||||
INNER JOIN PBProductParticipation pp on pp.PBProductParticipationKey=ce.PBProductParticipationKey
|
||||
INNER JOIN (SELECT ce1.PBEntityKey, pp1.PBProductAvailabilityKey, MAX(pp1.WhenLastChanged) as WhenLastChanged,
|
||||
pp1.CoverageTypeCode
|
||||
FROM PBCoveredEntities ce1
|
||||
INNER JOIN PBProductParticipation pp1 on pp1.PBProductParticipationKey = ce1.PBProductParticipationKey
|
||||
GROUP BY ce1.PBEntityKey, pp1.PBProductAvailabilityKey,pp1.CoverageTypeCode)
|
||||
cepp ON cepp.PBEntityKey = ce.PBEntityKey AND cepp.PBProductAvailabilityKey = pp.PBProductAvailabilityKey
|
||||
and cepp.CoverageTypeCode = pp.CoverageTypeCode
|
||||
INNER JOIN GEN_LookupTables lct ON lct.RecordID = pp.CoverageTypeCode
|
||||
INNER JOIN PBProductAvailability pa on pa.PBProductAvailabilityKey=pp.PBProductAvailabilityKey
|
||||
INNER JOIN PBProduct p on p.PBProductKey=pa.PBProductKey
|
||||
INNER JOIN PBAffiliation aff ON aff.PBAffiliationKey = pp.PBAffiliationKey
|
||||
INNER JOIN PBEntity div on div.PBEntityKey=aff.ParentPBEntityKey
|
||||
LEFT OUTER JOIN PBOrgUnit ou on ou.PBEntityKey=div.PBEntityKey
|
||||
LEFT OUTER JOIN PBEntityAddress oua on oua.PBEntityKey=ou.PBEntityKey and oua.AddressTypeID=1137
|
||||
WHERE p.PBProductKey in (Select PBProductKey From PBProduct Where FullDescription NOT LIKE '%LIFE%' AND FullDescription NOT LIKE '%VISION%' AND FullDescription NOT LIKE '%DENT%')
|
||||
AND pp.InEffect <= getdate() +90
|
||||
AND (pp.OutOfEffect-1 > getdate() AND pp.OutOfEffect>pp.InEffect)
|
||||
AND pp.OutOfEffect=(Select Max(Part.OutOfEffect) From PBProductParticipation Part
|
||||
INNER JOIN PBProductAvailability Aval on Aval.PBProductAvailabilityKey=Part.PBProductAvailabilityKey
|
||||
INNER JOIN PBProduct Prod on Prod.PBProductKey=Aval.PBProductKey
|
||||
Where Prod.PBProductKey = p.PBProductKey
|
||||
AND Part.PBProductParticipationKey = pp.PBProductParticipationKey)
|
||||
AND pbm.#{@entity_type}=#{@family_id}
|
||||
AND M.EnrolleeTypeKey='1044'
|
||||
SQL
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user