Skip to content

Commit

Permalink
Merge pull request #574 from woook/s02_NGS_allow_new_test_request
Browse files Browse the repository at this point in the history
requesteddate->daterequested
  • Loading branch information
andyb3 authored Jul 31, 2019
2 parents 38fb037 + 41df21d commit ef79d2b
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions forms/s02_NGSTest
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Private Sub Form_AfterInsert()
Dim S As String
Dim date_now As String
Dim computername As String
Dim username As String
username = VBA.Environ("USERNAME")
Dim UserName As String
UserName = VBA.Environ("USERNAME")
computername = VBA.Environ("COMPUTERNAME")
date_now = Format(Now, "dd/mmm/yyyy Hh:Nn:ss")
Set Q = New ADODB.Recordset
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: " + Me![ReferralID].Column(1) + " " + Me![NGSPanelID].Column(1) + " request added " + CStr(Me![RequestedDate]) + "',#" + date_now + "#,'" + username + "','" + computername + "')"
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: " + Me![ReferralID].Column(1) + " " + Me![NGSPanelID].Column(1) + " request added " + CStr(Me![DateRequested]) + "',#" + date_now + "#,'" + UserName + "','" + computername + "')"
Q.Open S, CurrentProject.Connection
Set Q = Nothing

Expand All @@ -31,12 +31,12 @@ Private Sub Form_Delete(Cancel As Integer)
Dim S As String
Dim date_now As String
Dim computername As String
Dim username As String
username = VBA.Environ("USERNAME")
Dim UserName As String
UserName = VBA.Environ("USERNAME")
computername = VBA.Environ("COMPUTERNAME")
date_now = Format(Now, "dd/mmm/yyyy Hh:Nn:ss")
Set Q = New ADODB.Recordset
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: " + Me![ReferralID].Column(1) + " " + Me![NGSPanelID].Column(1) + " request deleted (requested " + CStr(Me![DateRequested]) + ")',#" + date_now + "#,'" + username + "','" + computername + "')"
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: " + Me![ReferralID].Column(1) + " " + Me![NGSPanelID].Column(1) + " request deleted (requested " + CStr(Me![DateRequested]) + ")',#" + date_now + "#,'" + UserName + "','" + computername + "')"
Q.Open S, CurrentProject.Connection
Set Q = Nothing
If [Form_02 Patient Details]![s_StatusOverall] = 1202218798 Then
Expand All @@ -50,12 +50,12 @@ Private Sub NGSPanelID_AfterUpdate()
Dim S As String
Dim date_now As String
Dim computername As String
Dim username As String
Dim UserName As String
computername = VBA.Environ("COMPUTERNAME")
username = VBA.Environ("USERNAME")
UserName = VBA.Environ("USERNAME")
date_now = Format(Now, "dd/mmm/yyyy Hh:Nn:ss")
Set Q = New ADODB.Recordset
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: Panel changed to " + Me![NGSPanelID].Column(1) + "',#" + date_now + "#,'" + username + "','" + computername + "')"
S = "INSERT INTO PatientLog(InternalPatientID, LogEntry, [Date], Login, PCName) VALUES(" + CStr(Me![InternalPatientID]) + ",'NGS test: Panel changed to " + Me![NGSPanelID].Column(1) + "',#" + date_now + "#,'" + UserName + "','" + computername + "')"
Q.Open S, CurrentProject.Connection
Set Q = Nothing

Expand All @@ -69,98 +69,98 @@ End Sub
Private Sub ReferralID_DblClick(Cancel As Integer)
' define variables
Dim rsCopyNGSTest As ADODB.Recordset
Dim Sql As String
Dim sql As String
Dim date_now As String
Dim computername As String
Dim username As String
Dim UserName As String
Dim NewTestID As String
Dim logentry As String
Dim LogEntry As String

computername = VBA.Environ("COMPUTERNAME")
username = VBA.Environ("USERNAME")
UserName = VBA.Environ("USERNAME")
date_now = Format(Now, "dd/mmm/yyyy Hh:Nn:ss")

' open prompt to confirm test is to be failed and new test created from copy of this testID
msgb = MsgBox("You are about to fail NGSest ID " & Me.NGSTestID & " and create a new test request based on this test." + vbNewLine + "Do you wish to continue?", vbYesNo, "Fail & copy test?")
If msgb = vbYes Then
'' Create a new NGSTest record using fields from the failed test
'build sql to create a copy of all the required fields
Sql = "INSERT INTO ngstest (internalpatientid, referralid, ngspanelid, ngspanelid_b, ngspanelid_c, statusid, daterequested, bookby, resultbuild, bookingauthoriseddate, bookingauthorisedbyid, service, costcentre, department, priority) " & _
sql = "INSERT INTO ngstest (internalpatientid, referralid, ngspanelid, ngspanelid_b, ngspanelid_c, statusid, daterequested, bookby, resultbuild, bookingauthoriseddate, bookingauthorisedbyid, service, costcentre, department, priority) " & _
"SELECT internalpatientid, referralid, ngspanelid, ngspanelid_b, ngspanelid_c, 1202218803, daterequested, bookby, resultbuild, bookingauthoriseddate, bookingauthorisedbyid, service, costcentre, department, priority " & _
"FROM ngstest " & _
"WHERE ngstestid =" & Me.NGSTestID

Debug.Print "inserting new NGStest"
Debug.Print Sql
Debug.Print sql
' create new recordset - A recordset is used over DoCmd as we need to return the key of newly inserted row.
Set rsCopyNGSTest = New ADODB.Recordset
' run the sql to copy test
rsCopyNGSTest.Open Sql, CurrentProject.Connection
rsCopyNGSTest.Open sql, CurrentProject.Connection
'Get ID of new entry
rsCopyNGSTest.Open "SELECT @@identity", CurrentProject.Connection, adOpenKeyset
NewTestID = rsCopyNGSTest.Fields(0).Value
Debug.Print "Newtestid = " & NewTestID
Set rsCopyNGSTest = Nothing

'' copy all ngstest files, adding a prefix to description to make it clear copied from prev test
Sql = "INSERT INTO ngstestfile(ngstestid,description,ngstestfile,dateadded,vcf_filter_import) " & _
sql = "INSERT INTO ngstestfile(ngstestid,description,ngstestfile,dateadded,vcf_filter_import) " & _
"SELECT " & NewTestID & ",'copy_from_NGSTest'+'" & Me.NGSTestID & "'+'_'+description, ngstestfile, dateadded, vcf_filter_import " & _
"FROM ngstestfile " & _
"WHERE ngstestid = " & Me.NGSTestID
Debug.Print "copying NGSTestfiles"
Debug.Print Sql
Debug.Print sql
' turn off warnings so doesn't warn about appending rows
DoCmd.SetWarnings False
DoCmd.RunSQL Sql
DoCmd.RunSQL sql
DoCmd.SetWarnings True

'' copy panels in NGSTestPanelSelection
Sql = "INSERT INTO ngstestpanelselection(ngstestid, selectiontype, selectionid, analysisab) " & _
sql = "INSERT INTO ngstestpanelselection(ngstestid, selectiontype, selectionid, analysisab) " & _
"SELECT " & NewTestID & ", selectiontype, selectionid, analysisab " & _
"FROM ngstestpanelselection " & _
"WHERE ngstestid = " & Me.NGSTestID
Debug.Print "copying panels"
Debug.Print Sql
Debug.Print sql
' turn off warnings so doesn't warn about appending rows
DoCmd.SetWarnings False
DoCmd.RunSQL Sql
DoCmd.RunSQL sql
DoCmd.SetWarnings True

'' update patient log to say new test copied from a failed test
logentry = "NGS: New test request (NGSTestID" & NewTestID & ") created from failed NGSTestID" & Me.NGSTestID & " (including testfiles)"
Sql = "INSERT INTO patientlog(internalpatientid, logentry, [date], login, pcname) " & _
"VALUES (" & CStr(Me![InternalPatientID]) & ",'" + logentry + "',#" + date_now + "#,'" + username + "','" + computername + "')"
LogEntry = "NGS: New test request (NGSTestID" & NewTestID & ") created from failed NGSTestID" & Me.NGSTestID & " (including testfiles)"
sql = "INSERT INTO patientlog(internalpatientid, logentry, [date], login, pcname) " & _
"VALUES (" & CStr(Me![InternalPatientID]) & ",'" + LogEntry + "',#" + date_now + "#,'" + UserName + "','" + computername + "')"
Debug.Print "updating patient log with copying NGSTestfiles"
Debug.Print logentry
Debug.Print Sql
Debug.Print LogEntry
Debug.Print sql
' turn off warnings so doesn't warn about appending rows
DoCmd.SetWarnings False
DoCmd.RunSQL Sql
DoCmd.RunSQL sql
DoCmd.SetWarnings True

'' Deactivate failed test
' set status = 1202218816 (test failed)

Sql = "UPDATE ngstest " & _
sql = "UPDATE ngstest " & _
"SET statusid = 1202218816 " & _
"WHERE NGSTestID = " & Me.NGSTestID
Debug.Print "setting status to test failed"
Debug.Print Sql
Debug.Print sql
' turn off warnings so doesn't warn about appending rows
DoCmd.SetWarnings False
DoCmd.RunSQL Sql
DoCmd.RunSQL sql
DoCmd.SetWarnings True

'' update patient log to say test status set to failed
logentry = "NGS: Status changed to ""test failed"" for NGSTestID" & Me.NGSTestID
Sql = "INSERT INTO patientlog(internalpatientid, logentry, [date], login, pcname) " & _
"VALUES (" + CStr(Me![InternalPatientID]) + ",'" + logentry + "',#" + date_now + "#,'" + username + "','" + computername + "')"
LogEntry = "NGS: Status changed to ""test failed"" for NGSTestID" & Me.NGSTestID
sql = "INSERT INTO patientlog(internalpatientid, logentry, [date], login, pcname) " & _
"VALUES (" + CStr(Me![InternalPatientID]) + ",'" + LogEntry + "',#" + date_now + "#,'" + UserName + "','" + computername + "')"
Debug.Print "updating patient log to record setting test status to test failed"
Debug.Print logentry
Debug.Print Sql
Debug.Print LogEntry
Debug.Print sql
' turn off warnings so doesn't warn about appending rows
DoCmd.SetWarnings False
DoCmd.RunSQL Sql
DoCmd.RunSQL sql
DoCmd.SetWarnings True

' refresh form to reflect changes applied above
Expand Down

0 comments on commit ef79d2b

Please sign in to comment.