jeffsturgeon2002
Programmer
Currently, I am only receiving patients back that have NULL values for the "Termination Date" and "Effective Date". If either one of these fields has a value in it, I'm not receiving them back in my report. The ?DATES.DATE2? will be replaced by actual dates from the end user.
SECTION OF CODE THAT NEEDS ATTENTION
FULL QUERY
Jeff
SELECT * FROM users WHERE clue > 0
SECTION OF CODE THAT NEEDS ATTENTION
Code:
AND -- Filter on Termination Date
(
(pi.InsCardTerminationDate IS NULL OR pi.InsCardTerminationDate < DATEADD(d,1,?DATES.DATE2?)) AND (pi.InsCardTerminationDate IS NULL OR pi.InsCardTerminationDate >= ?DATES.DATE1?)
)
AND -- Filter on Effective Date
(
(pi.InsCardEffectiveDate IS NULL OR pi.InsCardEffectiveDate < DATEADD(d,1,?DATE.DATE2?)) AND (pi.InsCardEffectiveDate IS NULL OR pi.InsCardEffectiveDate >= ?DATE.DATE1?)
)
FULL QUERY
Code:
/* Patient Insurance List */
SET NOCOUNT ON
SELECT dbo.FormatName(pp.Prefix, pp.First, pp.Middle, pp.Last, pp.Suffix) AS Name,
pp.patientid,
ISNULL(pp.Address1,'')+ ' '+ ISNULL(pp.address2,'')AS [Patient Address],
ISNULL(pp.city,'')+ ' '+ ISNULL(pp.state,'')+' '+ ISNULL(pp.zip,'')AS [Patient CSZ],
IsNull(dbo.formatphone(pp.Phone1,1),'') AS Phone,
ISNULL(pp.Phone1Type, ' ') AS [Phone Type],
ISNULL(SUBSTRING(pp.SSN,1,3) + '-' + SUBSTRING(pp.SSN,4,2) + '-' + SUBSTRING(pp.SSN,6,4),'')AS PatientSSN,
CONVERT(varchar,pp.Birthdate,101) AS Birthdate,
IsNull(pp.Sex,'')AS PatientSex,
g.[Last] + ', ' + g.[First] AS [Guarantor Name],
ISNULL(g.Address1,'')+ ' '+ ISNULL(g.address2,'')AS [Guarantor Address],
ISNULL(g.city,'')+ ' '+ ISNULL(g.state,'')+' '+ ISNULL(g.zip,'')AS [Guarantor CSZ],
pp.PatientSameAsGuarantor,
pi.OrderForClaims AS [Order For Claims],
'Ins First Name'= CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.First
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.First
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.First
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.First
ELSE IsNull(pi.[First],'')
END,
'Ins Last Name'= CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.Last
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.Last
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.Last
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.Last
ELSE IsNull(pi.[Last],'')
END,
'Ins Address 1'= CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.Address1
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.address1
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.address1
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.Address1
ELSE IsNull(pi.address1,'')
END,
'Ins Address 2' = CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.Address2
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.address2
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.address2
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.Address2
ELSE IsNull(pi.address2,'')
END,
'Ins City' = CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.City
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.City
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.City
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.City
ELSE IsNull(pi.city,'')
END,
'Ins State' = CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.State
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.State
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.State
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.State
ELSE IsNull(pi.State,'')
END,
'Ins Zip' = CASE
WHEN pi.InsuredSameAsPatient = 1 THEN pp.Zip
WHEN pi.InsuredSameAsGuarantor = 1 THEN g.zip
WHEN pi.InsuredSameAsGuarantor IS NULL THEN g.Zip
WHEN pi.InsuredSameAsPatient IS NULL THEN pp.zip
ELSE IsNull(pi.zip,'')
END,
ic.ListName AS [Insurance Carrier],
ISNULL(pi.InsuredId, ' ') AS [Insured ID],
ISNULL(PI.groupid,'')AS [Group ID],
ig.Name AS InsuranceGroup,
df.ListName AS Doctor,
df1.ListName AS Facility,
ml.Description AS FinancialClass,
ISNULL(CONVERT(VARCHAR,pi.InsCardEffectiveDate,101),'No Effective Date') AS EffectiveDate,
ISNULL(CONVERT(VARCHAR,pi.InsCardTerminationDate,101),'No Termination Date') AS TerminationDate
FROM PatientProfile pp
JOIN PatientInsurance pi ON pp.PatientProfileId = pi.PatientProfileId
JOIN Guarantor g ON pp.GuarantorId = g.GuarantorId
JOIN InsuranceCarriers ic ON pi.InsuranceCarriersId = ic.InsuranceCarriersId
LEFT JOIN InsuranceGroup ig ON ic.InsuranceGroupId = ig.InsuranceGroupId
LEFT JOIN MedLists ml ON pp.FinancialClassMId = ml.MedListsId
LEFT JOIN DoctorFacility df1 ON pp.FacilityId = df1.DoctorFacilityId
LEFT JOIN DoctorFacility df ON pp.DoctorId = df.DoctorFacilityId
WHERE --Filter on doctor
(
(?DOCTOR.ITEMDATA? IS NOT NULL AND pp.DoctorId IN (?DOCTOR.ITEMDATA.U?)) OR
(?DOCTOR.ITEMDATA? IS NULL)
)
AND
(
(?FACILITY.ITEMDATA? IS NOT NULL AND pp.FacilityId IN (?FACILITY.ITEMDATA.U?)) OR
(?FACILITY.ITEMDATA? IS NULL)
)
AND --Filter on Insurance Carrier
(
(?INSURANCECARRIER.ITEMDATA? IS NOT NULL AND pi.InsuranceCarriersId IN (?INSURANCECARRIER.ITEMDATA.U?)) OR
(?INSURANCECARRIER.ITEMDATA? IS NULL)
)
AND --Filter on Insurance Group
(
(?INSURANCEGROUP.ITEMDATA? IS NOT NULL AND ic.InsuranceGroupId IN (?INSURANCEGROUP.ITEMDATA.U?)) OR
(?INSURANCEGROUP.ITEMDATA? IS NULL)
)
AND -- Filter on Termination Date
(
(pi.InsCardTerminationDate IS NULL OR pi.InsCardTerminationDate < DATEADD(d,1,?DATES.DATE2?)) AND (pi.InsCardTerminationDate IS NULL OR pi.InsCardTerminationDate >= ?DATES.DATE1?)
)
AND -- Filter on Effective Date
(
(pi.InsCardEffectiveDate IS NULL OR pi.InsCardEffectiveDate < DATEADD(d,1,?DATE.DATE2?)) AND (pi.InsCardEffectiveDate IS NULL OR pi.InsCardEffectiveDate >= ?DATE.DATE1?)
)
AND --Filter on Patient
(
(?PATIENT.ITEMDATA? IS NOT NULL AND pp.PatientProfileID IN (?PATIENT.ITEMDATA.U?)) OR
(?PATIENT.ITEMDATA? IS NULL)
)
ORDER BY dbo.FormatName(pp.Prefix, pp.First, pp.Middle, pp.Last, pp.Suffix)
Jeff
SELECT * FROM users WHERE clue > 0