I'm trying to write a report for my hospital's registration department where when scheduling makes a date change to an appointment the report will only return that row if certain criteria has been meet.
1)The appointment is a brand new appointment.
2)The appointment date has changed (the fields are datetime fields)not the time.
The two tables that record changes are apptaud and schedlog. When the appt (appt_id) is edited a new row in each of these tables is added. Can we write the report so that each row is evaluated on the change. Below are two examples of what I wrote for the Record Selection Expert currently but can not seem to get the right results.
Using Apptaud Table:
{res2.restype_id} = 2 and
{res2.resunit_id} in [5, 6] and
{apptaud.new_apptstatus_id} = 1 and
DateValue({apptaud.new_start_datetime}) <> DateValue({apptaud.old_start_datetime}) and
{apptaud.start_datetime} = {?StartDate}
Using the Schedlog Table:
{res2.restype_id} = 2 and
{res2.resunit_id} in [5, 6] and
{appt.scheduled_datetime} = {?StartDate} and
(
({schedlog.audittype_id} = 2)
or
({schedlog.audittype_id} = 1 and
{schedlog.reschedreason_id} in [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 3, 4, 5, 6, 7, 8, 9] and
DateValue({schedlog.scheduled_datetime}) <> DateValue({schedlog.scheduled_datetime}))
)
SQL Query for Schedlog Example:
SELECT "appt"."start_datetime", "res2"."resunit_id", "res2"."restype_id", "loc"."name", "pat"."name_display", "pattype"."abbr", "appt"."scheduled_datetime", "apptclass"."abbr", "appt"."appt_id", "pat"."birthdate", "visit"."pat_acct_num", "loc2"."abbr", "schedlog"."audittype_id", "schedlog"."reschedreason_id", "schedlog"."scheduled_datetime", "resunit"."abbr"
FROM (((("phsprod"."dbo"."res" "res2" INNER JOIN ((((((("phsprod"."dbo"."appt" "appt" INNER JOIN "phsprod"."dbo"."resunit" "resunit" ON "appt"."resunit_id"="resunit"."resunit_id") INNER JOIN "phsprod"."dbo"."patbooking" "patbooking" ON "appt"."appt_id"="patbooking"."appt_id") INNER JOIN "phsprod"."dbo"."visitapptlist" "visitapptlist" ON "appt"."appt_id"="visitapptlist"."appt_id") INNER JOIN "phsprod"."dbo"."schedlog" "schedlog" ON "appt"."appt_id"="schedlog"."appt_id") INNER JOIN "phsprod"."dbo"."facility" "facility" ON "resunit"."facility_id"="facility"."facility_id") LEFT OUTER JOIN "phsprod"."dbo"."loc" "loc2" ON "resunit"."resunit_id"="loc2"."loc_id") LEFT OUTER JOIN "phsprod"."dbo"."loc" "loc" ON "facility"."facility_id"="loc"."loc_id") ON "res2"."resunit_id"="resunit"."resunit_id") LEFT OUTER JOIN "phsprod"."dbo"."pat" "pat" ON "patbooking"."pat_id"="pat"."pat_id") LEFT OUTER JOIN "phsprod"."dbo"."apptclass" "apptclass" ON "patbooking"."apptclass_id"="apptclass"."apptclass_id") INNER JOIN "phsprod"."dbo"."visit" "visit" ON "visitapptlist"."visit_id"="visit"."visit_id") LEFT OUTER JOIN "phsprod"."dbo"."pattype" "pattype" ON "visit"."pattype_id"="pattype"."pattype_id"
WHERE "res2"."restype_id"=2 AND ("res2"."resunit_id"=5 OR "res2"."resunit_id"=6) AND ("appt"."scheduled_datetime">={ts '2011-06-06 00:00:00'} AND "appt"."scheduled_datetime"<{ts '2011-06-07 00:00:00'}) AND ("schedlog"."audittype_id"=2 OR "schedlog"."audittype_id"=1 AND ("schedlog"."reschedreason_id"=1 OR "schedlog"."reschedreason_id"=2 OR "schedlog"."reschedreason_id"=3 OR "schedlog"."reschedreason_id"=4 OR "schedlog"."reschedreason_id"=5 OR "schedlog"."reschedreason_id"=6 OR "schedlog"."reschedreason_id"=7 OR "schedlog"."reschedreason_id"=8 OR "schedlog"."reschedreason_id"=9 OR "schedlog"."reschedreason_id"=10 OR "schedlog"."reschedreason_id"=11 OR "schedlog"."reschedreason_id"=12 OR "schedlog"."reschedreason_id"=13 OR "schedlog"."reschedreason_id"=14 OR "schedlog"."reschedreason_id"=15 OR "schedlog"."reschedreason_id"=16 OR "schedlog"."reschedreason_id"=17 OR "schedlog"."reschedreason_id"=18 OR "schedlog"."reschedreason_id"=19 OR "schedlog"."reschedreason_id"=20 OR "schedlog"."reschedreason_id"=21 OR "schedlog"."reschedreason_id"=22))
ORDER BY "resunit"."abbr"
1)The appointment is a brand new appointment.
2)The appointment date has changed (the fields are datetime fields)not the time.
The two tables that record changes are apptaud and schedlog. When the appt (appt_id) is edited a new row in each of these tables is added. Can we write the report so that each row is evaluated on the change. Below are two examples of what I wrote for the Record Selection Expert currently but can not seem to get the right results.
Using Apptaud Table:
{res2.restype_id} = 2 and
{res2.resunit_id} in [5, 6] and
{apptaud.new_apptstatus_id} = 1 and
DateValue({apptaud.new_start_datetime}) <> DateValue({apptaud.old_start_datetime}) and
{apptaud.start_datetime} = {?StartDate}
Using the Schedlog Table:
{res2.restype_id} = 2 and
{res2.resunit_id} in [5, 6] and
{appt.scheduled_datetime} = {?StartDate} and
(
({schedlog.audittype_id} = 2)
or
({schedlog.audittype_id} = 1 and
{schedlog.reschedreason_id} in [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 3, 4, 5, 6, 7, 8, 9] and
DateValue({schedlog.scheduled_datetime}) <> DateValue({schedlog.scheduled_datetime}))
)
SQL Query for Schedlog Example:
SELECT "appt"."start_datetime", "res2"."resunit_id", "res2"."restype_id", "loc"."name", "pat"."name_display", "pattype"."abbr", "appt"."scheduled_datetime", "apptclass"."abbr", "appt"."appt_id", "pat"."birthdate", "visit"."pat_acct_num", "loc2"."abbr", "schedlog"."audittype_id", "schedlog"."reschedreason_id", "schedlog"."scheduled_datetime", "resunit"."abbr"
FROM (((("phsprod"."dbo"."res" "res2" INNER JOIN ((((((("phsprod"."dbo"."appt" "appt" INNER JOIN "phsprod"."dbo"."resunit" "resunit" ON "appt"."resunit_id"="resunit"."resunit_id") INNER JOIN "phsprod"."dbo"."patbooking" "patbooking" ON "appt"."appt_id"="patbooking"."appt_id") INNER JOIN "phsprod"."dbo"."visitapptlist" "visitapptlist" ON "appt"."appt_id"="visitapptlist"."appt_id") INNER JOIN "phsprod"."dbo"."schedlog" "schedlog" ON "appt"."appt_id"="schedlog"."appt_id") INNER JOIN "phsprod"."dbo"."facility" "facility" ON "resunit"."facility_id"="facility"."facility_id") LEFT OUTER JOIN "phsprod"."dbo"."loc" "loc2" ON "resunit"."resunit_id"="loc2"."loc_id") LEFT OUTER JOIN "phsprod"."dbo"."loc" "loc" ON "facility"."facility_id"="loc"."loc_id") ON "res2"."resunit_id"="resunit"."resunit_id") LEFT OUTER JOIN "phsprod"."dbo"."pat" "pat" ON "patbooking"."pat_id"="pat"."pat_id") LEFT OUTER JOIN "phsprod"."dbo"."apptclass" "apptclass" ON "patbooking"."apptclass_id"="apptclass"."apptclass_id") INNER JOIN "phsprod"."dbo"."visit" "visit" ON "visitapptlist"."visit_id"="visit"."visit_id") LEFT OUTER JOIN "phsprod"."dbo"."pattype" "pattype" ON "visit"."pattype_id"="pattype"."pattype_id"
WHERE "res2"."restype_id"=2 AND ("res2"."resunit_id"=5 OR "res2"."resunit_id"=6) AND ("appt"."scheduled_datetime">={ts '2011-06-06 00:00:00'} AND "appt"."scheduled_datetime"<{ts '2011-06-07 00:00:00'}) AND ("schedlog"."audittype_id"=2 OR "schedlog"."audittype_id"=1 AND ("schedlog"."reschedreason_id"=1 OR "schedlog"."reschedreason_id"=2 OR "schedlog"."reschedreason_id"=3 OR "schedlog"."reschedreason_id"=4 OR "schedlog"."reschedreason_id"=5 OR "schedlog"."reschedreason_id"=6 OR "schedlog"."reschedreason_id"=7 OR "schedlog"."reschedreason_id"=8 OR "schedlog"."reschedreason_id"=9 OR "schedlog"."reschedreason_id"=10 OR "schedlog"."reschedreason_id"=11 OR "schedlog"."reschedreason_id"=12 OR "schedlog"."reschedreason_id"=13 OR "schedlog"."reschedreason_id"=14 OR "schedlog"."reschedreason_id"=15 OR "schedlog"."reschedreason_id"=16 OR "schedlog"."reschedreason_id"=17 OR "schedlog"."reschedreason_id"=18 OR "schedlog"."reschedreason_id"=19 OR "schedlog"."reschedreason_id"=20 OR "schedlog"."reschedreason_id"=21 OR "schedlog"."reschedreason_id"=22))
ORDER BY "resunit"."abbr"