Skip to content

Commit

Permalink
Background Checks update: Language and training adds.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrrv committed Apr 11, 2024
1 parent a0d87f4 commit 70128e0
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 25 deletions.
95 changes: 95 additions & 0 deletions BackgroundChecks/BackgroundChecks-Status.sql
Original file line number Diff line number Diff line change
@@ -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
86 changes: 61 additions & 25 deletions BackgroundChecks/BackgroundChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
subjectPid = Data.viewas
impersonated = True


def actionForDate(d):
if d is None:
return "None"
Expand All @@ -21,6 +22,7 @@ def actionForDate(d):
return "Expires Soon"
return "Valid"


def formatDate(d):
a = actionForDate(d)
s = d.ToString("MMMM dd, yyyy")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "<style>.y { background: #dfd;} .n { background: #fdd; }</style>"
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 = "<style>.y { background: #dfd;} .n { background: #fdd; } .box-content a:not(.btn) {text-decoration: underline;}</style>"

adminMode = (model.Data.view == "admin" and userPerson.Users[0].InRole('Admin'))

Expand All @@ -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 "</b><a href=\"https://my.tenth.org/Person2/{}#tab-volunteer\">Documents</a> ".format(r.PeopleId)
print "<a href=\"?viewas={}\">Impersonate</a>".format(r.PeopleId)
print "</b>"
if userPerson.Users[0].InRole('BackgroundCheck'):
print "<a href=\"https://my.tenth.org/Person2/{}#tab-volunteer\">Documents</a> ".format(r.PeopleId)
print "<a href=\"?viewas={}\">Impersonate</a>".format(r.PeopleId)
print "</p>"

print "<h3>Documents On-Hand</h3>"
Expand Down Expand Up @@ -139,12 +147,12 @@ def needs(r, p): # row, person
print "<p><i>No Documents</i></p>"

n = needs(r, model.GetPerson(r.PeopleId))
if len(n) > 0:
if len(n) > 0 or r.InProgressLastUpdate is not None:
print "<h3>Action Required</h3>"
print "<ul>"

if 'JuAdd' in n:
print "<li>Database admin must reconcile this person's \"Just Added\" status.</li>"
print "<li>Admin staff must reconcile this person's \"Just Added\" status.</li>"

if 'Bio' in n:
print "<li>Subject must update their profile to include full name, gender, and date of birth.</li>"
Expand All @@ -155,15 +163,21 @@ def needs(r, p): # row, person
elif 'PMM Emp' in n or 'PMM Vol' in n:
print "<li>Subject must submit for a background check renewal.</li>"

if 'PMM Completion' in n:
print "<li>Subject must complete the PMM process to get their CAHC results.</li>"
if 'PMM Completion' in n or r.InProgressLastUpdate is not None:
if r.Status == "Invalid":
print "<li>Subject must complete the PMM process to get their CAHC results.</li>"
else:
print "<li>Admin staff should check that their background check is appropriately marked as approved.</li>"

if 'FBI Vol' in n:
print "<li>Subject must complete FBI fingerprinting or an affidavit.</li>"

if 'FBI Emp' in n:
print "<li>Subject must complete FBI fingerprinting.</li>"

if 'Training' in n:
print "<li>Subject must complete Training.</li>"

print "</ul>"


Expand Down Expand Up @@ -193,9 +207,6 @@ def needs(r, p): # row, person
else:
print "<p>It appears that you already have an affidavit in progress or on file.</p>"

else:
print "<p>It appears that yoy arrived to a place where you were not expected. Please contact the church office.</p>"

# Submission
elif model.HttpMethod == "post":
sql = "SELECT * FROM ({0}) as k WHERE PeopleId = {1}".format(mainQuery, subjectPid)
Expand Down Expand Up @@ -231,12 +242,26 @@ def needs(r, p): # row, person
print submit
print "<p>Something weird happened. Please contact the church office, and give them this exact message.</p>"

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 "<p>Something strange happened. Please contact the church office, and give them this exact message.</p>"


# Default user view
else:
model.Styles = "<style>.y { background: #dfd;} .n { background: #fdd; } .box-content a:not(.btn) {text-decoration: underline;}</style>"

print "<p>"
if userPerson.Users[0].InRole('BackgroundCheck') or userPerson.Users[0].InRole('BackgroundCheckLight'):
print "<a href=\"?view=list\" class=\"btn btn-default\">List View</a> "
print "<a href=\"/RunScript/BackgroundChecks-Status\" class=\"btn btn-default\">Grid View</a> "
if userPerson.Users[0].InRole('Admin'):
print "<a href=\"?view=admin\" class=\"btn btn-default\">Technical Admin View</a> "
print "</p>"

sql = "SELECT * FROM ({0}) as k WHERE PeopleId = {1}".format(mainQuery, subjectPid)

hasResult = False
Expand All @@ -254,7 +279,7 @@ def needs(r, p): # row, person
print "<p>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.</p> "

if len(n) == 0:
if r.Status != "Invalid":
print "<p><b>You are currently cleared to serve as {}.</b></p>".format(
"an employee" if forEmployment else "a volunteer")

Expand All @@ -277,7 +302,7 @@ def needs(r, p): # row, person
if 'Bio' in n:
print "<div class=\"well\"><p>Please update your profile to include your " \
"full name, gender, and date of birth.</p><p><a href=\"/Person2/{}\" " \
"class=\"btn btn-primary\">Update Your Profile</a></p></div>".format(bgc.person.PeopleId)
"class=\"btn btn-primary\">Update Your Profile</a></p></div>".format(subjectPid)

elif 'Ssn' in n:
print "<div class=\"well\">"
Expand Down Expand Up @@ -328,7 +353,7 @@ def needs(r, p): # row, person
print "</div>"

if 'PMM Completion' in n:
print "<div class=\"well\">Within one or two business days, you should soon receive an email with instructions " \
print "<div class=\"well\">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 " \
Expand All @@ -338,18 +363,23 @@ def needs(r, p): # row, person
print "</div>"

if 'FBI Vol' in n:
print "<div class=\"well\">We need your FBI Fingerprinting clearance or an affidavit. <br />"
print "If you <b>have only lived in Pennsylvania within the last 10 years</b>, " \
"<a href=\"?view=affid\">please click here to sign an affidavit</a>.<br /> "
print "If you <b>have lived outside Pennsylvania within the last 10 years</b>, we will need you to get an" \
" FBI fingerprint check. <a href=\"https://uenroll.identogo.com/workflows/1KG6ZJ/appointment/bio\"" \
" target=\"_blank\">Click here to enter your information and arrange a fingerprinting " \
"appointment.</a> Pennsylvania uses IdentoGo as a provider for this service. Either make your " \
print "<div class=\"well\">We need your FBI Fingerprinting clearance or an affidavit. <ul>"
print "<li>If you <b>have only lived in Pennsylvania within the last 10 years</b>, " \
"<a href=\"?view=affid\">please click here to sign an affidavit</a>.</li>"
print "<li>If you <b>have lived outside Pennsylvania within the last 10 years</b>, 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 "<a href=\"/OnlineReg/96\" >upload it here</a>."
print "</div>"
"IdentoGo. (This is much LESS convenient than it sounds, and also more expensive.) " \
"<a href=\"https://uenroll.identogo.com/workflows/1KG6ZJ/appointment/bio\"" \
" target=\"_blank\">Click here to enter your information and arrange a fingerprinting " \
"appointment.</a> " \
"Once you receive your certification in the mail, please scan it and " \
"<a href=\"/OnlineReg/96\" >upload it here</a>.</li>"
print "<li>If you <b>already have the fingerprinting credential</b> because of your work or volunteering elsewhere, you can " \
"<a href=\"/OnlineReg/96\" >upload it here</a>. The body of the document should begin with " \
"\"Your fingerprint based record check\"...</li>"
print "</ul></div>"

if 'FBI Emp' in n:
print "<div class=\"well\">We need your FBI Fingerprinting clearance. Please make an appointment for fingerprinting. " \
Expand All @@ -359,6 +389,12 @@ def needs(r, p): # row, person
print "<br /><a href=\"https://uenroll.identogo.com/workflows/1KG756/appointment/bio\" class=\"btn btn-primary\">Make Appointment</a>&nbsp;<a href=\"/OnlineReg/96\" class=\"btn btn-primary\">Submit Document</a>"
print "</div>"

if 'Training' in n:
print "<div class=\"well\">We need you to complete training on preventing sexual abuse of children. We will be in touch with instructions."
print "</div>"

if not hasResult:
print "<p>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 "</p>"
print "</p>"

print "<p>If you have questions or need help, please email <a href=\"mailto:clearances@tenth.org\">clearances@tenth.org</a> or <a href=\"https://outlook.office365.com/owa/calendar/TenthPresbyterianChurch@tenth.org/bookings/s/2llJyCFr80Scs1p6QV919w2\">make an appointment here</a>.</p>"

0 comments on commit 70128e0

Please sign in to comment.