diff --git a/BackgroundChecks/BackgroundChecks-Status.sql b/BackgroundChecks/BackgroundChecks-Status.sql new file mode 100644 index 0000000..5a4f28a --- /dev/null +++ b/BackgroundChecks/BackgroundChecks-Status.sql @@ -0,0 +1,95 @@ +SELECT s.*, + IIF(s.Minor >= GETDATE() OR ( + s.CAHC >= GETDATE() AND + s.PATCH >= GETDATE() AND ( + s.FBI > GETDATE() OR ( + s.Aff >= GETDATE() AND + s.Employee <> 'Employee' + ) + ) + ), '', 'Invalid') as Status + +FROM ( + SELECT + tp.PeopleId, + COALESCE(p.Nickname, p.FirstName) as GoesBy, + p.LastName, + + CASE WHEN p.Age IS NOT NULL AND p.Age < 18 THEN DATEADD(year, 18, p.BDate) ELSE NULL END AS Minor, + + DATEADD(year, 5, CAHC.ExpDate) as CAHC, + DATEADD(year, 5, PATCH.ExpDate) as PATCH, + DATEADD(year, 5, FBI.ExpDate) as FBI, + DATEADD(year, 5, Aff.ExpDate) as Aff, + DATEADD(year, 2, LastTraining.TrainingDate) as Training, + IIF(t.Name = 'F51', 'Employee', '') as Employee, + InProgress.InProgressSince as InProgressLastUpdate + + FROM People p + LEFT JOIN TagPerson tp ON p.PeopleId = tp.PeopleId + LEFT JOIN Tag t on tp.Id = t.Id + + LEFT JOIN ( + SELECT PeopleId, max(Date) as ExpDate FROM ( + SELECT PeopleId, TRY_CAST(RIGHT(vfv1.Name,CHARINDEX(' ', (REVERSE(vfv1.Name))) - 1) as Date) as Date + FROM VolunteerForm vfv1 WHERE UPPER(LEFT(vfv1.Name, LEN('CAHC'))) = CONCAT('CAHC', ' ') + UNION + SELECT PeopleId, DateValue as Date + FROM PeopleExtra WHERE Field = 'Background Check: Latest CAHC' + ) CAHCa + GROUP BY PeopleId + ) as CAHC ON p.PeopleId = CAHC.PeopleId + + LEFT JOIN ( + SELECT PeopleId, max(Date) as ExpDate FROM ( + SELECT PeopleId, TRY_CAST(RIGHT(vfv1.Name,CHARINDEX(' ', (REVERSE(vfv1.Name))) - 1) as Date) as Date + FROM VolunteerForm vfv1 WHERE UPPER(LEFT(vfv1.Name, LEN('PATCH'))) = CONCAT('PATCH', ' ') + UNION + SELECT PeopleId, DateValue as Date + FROM PeopleExtra WHERE Field = 'Background Check: Latest PATCH' + ) PATCHa + GROUP BY PeopleId + ) as PATCH ON p.PeopleId = PATCH.PeopleId + + LEFT JOIN ( + SELECT PeopleId, max(Date) as ExpDate FROM ( + SELECT PeopleId, TRY_CAST(RIGHT(vfv1.Name,CHARINDEX(' ', (REVERSE(vfv1.Name))) - 1) as Date) as Date + FROM VolunteerForm vfv1 WHERE UPPER(LEFT(vfv1.Name, LEN('FBI'))) = CONCAT('FBI', ' ') + UNION + SELECT PeopleId, DateValue as Date + FROM PeopleExtra WHERE Field = 'Background Check: Latest FBI' + ) FBIa + GROUP BY PeopleId + ) as FBI ON p.PeopleId = FBI.PeopleId + + LEFT JOIN ( + SELECT PeopleId, max(Date) as ExpDate FROM ( + SELECT PeopleId, TRY_CAST(RIGHT(vfv1.Name,CHARINDEX(' ', (REVERSE(vfv1.Name))) - 1) as Date) as Date + FROM VolunteerForm vfv1 WHERE UPPER(LEFT(vfv1.Name, LEN('Aff'))) = CONCAT('Aff', ' ') + UNION + SELECT PeopleId, DateValue as Date + FROM PeopleExtra WHERE Field = 'ds-Resident Affidavit Date' OR Field = 'ds-FBI Waiver Affidavit Date' + ) Affa + GROUP BY PeopleId + ) as Aff ON p.PeopleId = Aff.PeopleId + + LEFT JOIN ( + SELECT PeopleId, CONVERT(date, MAX(Updated)) as InProgressSince + FROM BackgroundChecks + WHERE Updated > DATEADD(month, -3, GETDATE()) + AND ReportTypeID = 1 + AND ApprovalStatus = 'Pending' + GROUP BY PeopleId + ) as InProgress ON p.PeopleId = InProgress.PeopleId + + LEFT JOIN ( + SELECT PeopleId, CONVERT(date, MAX(Updated)) as TrainingDate + FROM BackgroundChecks + WHERE ReportTypeID = 3 + AND Score > 80 + GROUP BY PeopleId + ) as LastTraining ON p.PeopleId = LastTraining.PeopleId + + WHERE t.Name = 'F50' OR t.Name = 'F51' + + ) s \ No newline at end of file diff --git a/BackgroundChecks/BackgroundChecks.py b/BackgroundChecks/BackgroundChecks.py index f0065f7..9234f14 100644 --- a/BackgroundChecks/BackgroundChecks.py +++ b/BackgroundChecks/BackgroundChecks.py @@ -12,6 +12,7 @@ subjectPid = Data.viewas impersonated = True + def actionForDate(d): if d is None: return "None" @@ -21,6 +22,7 @@ def actionForDate(d): return "Expires Soon" return "Valid" + def formatDate(d): a = actionForDate(d) s = d.ToString("MMMM dd, yyyy") @@ -51,6 +53,7 @@ def needs(r, p): # row, person p.BirthYear < 1930 # meant to detect if null ): n.append('Bio') + n.append('Invalid') if len(n) > 0: return n @@ -83,12 +86,15 @@ def needs(r, p): # row, person if String.IsNullOrEmpty(p.Ssn) and needSsn: n.append('Ssn') + if actionForDate(r.Training) != "Valid": + n.append("Training") + return n # List mode -if (model.Data.view == "list" and userPerson.Users[0].InRole('BackgroundCheck')) or (model.Data.view == "admin" and userPerson.Users[0].InRole('Admin')): - model.Styles = "" +if (model.Data.view == "list" and (userPerson.Users[0].InRole('BackgroundCheck') or userPerson.Users[0].InRole('BackgroundCheckLight'))) or (model.Data.view == "admin" and userPerson.Users[0].InRole('Admin')): + model.Styles = "" adminMode = (model.Data.view == "admin" and userPerson.Users[0].InRole('Admin')) @@ -103,8 +109,10 @@ def needs(r, p): # row, person print " {} ".format("Employable with Children" if not r.Status == "Invalid" else "Not Employable with Children") else: print " {} ".format("Volunteer with Children" if not r.Status == "Invalid" else "No Volunteering with Children") - print "Documents ".format(r.PeopleId) - print "Impersonate".format(r.PeopleId) + print "" + if userPerson.Users[0].InRole('BackgroundCheck'): + print "Documents ".format(r.PeopleId) + print "Impersonate".format(r.PeopleId) print "

" print "

Documents On-Hand

" @@ -139,12 +147,12 @@ def needs(r, p): # row, person print "

No Documents

" n = needs(r, model.GetPerson(r.PeopleId)) - if len(n) > 0: + if len(n) > 0 or r.InProgressLastUpdate is not None: print "

Action Required

" print "" @@ -193,9 +207,6 @@ def needs(r, p): # row, person else: print "

It appears that you already have an affidavit in progress or on file.

" - else: - print "

It appears that yoy arrived to a place where you were not expected. Please contact the church office.

" - # Submission elif model.HttpMethod == "post": sql = "SELECT * FROM ({0}) as k WHERE PeopleId = {1}".format(mainQuery, subjectPid) @@ -231,12 +242,26 @@ def needs(r, p): # row, person print submit print "

Something weird happened. Please contact the church office, and give them this exact message.

" + elif 'PMM Completion' in n: + # We can't actually do anything with this, so go back to the other view and hope it's not a circle. + print "REDIRECT={}/PyScript/{}".format(model.CmsHost, model.ScriptName) + else: print "

Something strange happened. Please contact the church office, and give them this exact message.

" # Default user view else: + model.Styles = "" + + print "

" + if userPerson.Users[0].InRole('BackgroundCheck') or userPerson.Users[0].InRole('BackgroundCheckLight'): + print "List View " + print "Grid View " + if userPerson.Users[0].InRole('Admin'): + print "Technical Admin View " + print "

" + sql = "SELECT * FROM ({0}) as k WHERE PeopleId = {1}".format(mainQuery, subjectPid) hasResult = False @@ -254,7 +279,7 @@ def needs(r, p): # row, person print "

Thank you for serving at Tenth! To protect our children, our other volunteers, and you, we require " \ "background checks of all staff members and adult volunteers who work with children.

" - if len(n) == 0: + if r.Status != "Invalid": print "

You are currently cleared to serve as {}.

".format( "an employee" if forEmployment else "a volunteer") @@ -277,7 +302,7 @@ def needs(r, p): # row, person if 'Bio' in n: print "

Please update your profile to include your " \ "full name, gender, and date of birth.

Update Your Profile

".format(bgc.person.PeopleId) + "class=\"btn btn-primary\">Update Your Profile

".format(subjectPid) elif 'Ssn' in n: print "
" @@ -328,7 +353,7 @@ def needs(r, p): # row, person print "
" if 'PMM Completion' in n: - print "
Within one or two business days, you should soon receive an email with instructions " \ + print "
Within one or two business days, you should receive an email with instructions " \ "for how to complete the PA Child Abuse History Clearance. The subject line will probably be \"PA Child " \ "Abuse Registry Check - Tenth Presbyterian Church\". " \ "That email includes a code which you should use in place of " \ @@ -338,18 +363,23 @@ def needs(r, p): # row, person print "
" if 'FBI Vol' in n: - print "
We need your FBI Fingerprinting clearance or an affidavit.
" - print "If you have only lived in Pennsylvania within the last 10 years, " \ - "please click here to sign an affidavit.
" - print "If you have lived outside Pennsylvania within the last 10 years, we will need you to get an" \ - " FBI fingerprint check. Click here to enter your information and arrange a fingerprinting " \ - "appointment. Pennsylvania uses IdentoGo as a provider for this service. Either make your " \ + print "
We need your FBI Fingerprinting clearance or an affidavit.
    " + print "
  • If you have only lived in Pennsylvania within the last 10 years, " \ + "please click here to sign an affidavit.
  • " + print "
  • If you have lived outside Pennsylvania within the last 10 years, we will need you to get an" \ + " FBI fingerprint check. Pennsylvania uses IdentoGo as a provider for this service. Either make your " \ "appointment at a location in PA (STRONGLY suggested), or use the \"Card Submission By Mail\" option, " \ "which will provide instructions for completing a fingerprint card and submitting it back to " \ - "IdentoGo. (This is much LESS convenient than it sounds.) Once you receive your certification in the mail, please scan it and " - print "upload it here." - print "
" + "IdentoGo. (This is much LESS convenient than it sounds, and also more expensive.) " \ + "Click here to enter your information and arrange a fingerprinting " \ + "appointment. " \ + "Once you receive your certification in the mail, please scan it and " \ + "upload it here." + print "
  • If you already have the fingerprinting credential because of your work or volunteering elsewhere, you can " \ + "upload it here. The body of the document should begin with " \ + "\"Your fingerprint based record check\"...
  • " + print "
    " if 'FBI Emp' in n: print "
    We need your FBI Fingerprinting clearance. Please make an appointment for fingerprinting. " \ @@ -359,6 +389,12 @@ def needs(r, p): # row, person print "
    Make Appointment Submit Document" print "
    " + if 'Training' in n: + print "
    We need you to complete training on preventing sexual abuse of children. We will be in touch with instructions." + print "
    " + if not hasResult: print "

    We are under the impression that you do not serve in an area that requires a background check. If this is not correct, please contact the church office." - print "

    " \ No newline at end of file + print "

    " + + print "

    If you have questions or need help, please email clearances@tenth.org or make an appointment here.

    " \ No newline at end of file