Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.20 KB | None | 0 0
  1. Dim penPngList As New List(Of String)
  2.  
  3. 'Get information on the pen docked
  4. Dim penID As String
  5. penID = _form.SessionData(0).DeviceState.PadDeviceID
  6. 'penID = "aaa"
  7.  
  8. Try
  9. Dim i = 0
  10.  
  11. For Each er As ExportResult In _form.Validator.ExportResults
  12.  
  13.  
  14. If er.DataPathName = "xml" Then
  15.  
  16. 'Load the XML
  17. Dim doc As New XmlDocument
  18. doc.Load(er.ExpandedFilePath)
  19.  
  20. 'Get MySql Reader ready
  21. Dim rdr0 As MySqlDataReader
  22. Dim rdr As MySqlDataReader
  23.  
  24. Dim sessionID As Int32
  25.  
  26. 'Grab the Descriptor
  27. Dim document As XPathDocument = New XPathDocument(er.ExpandedFilePath)
  28. Dim navigator As XPathNavigator = document.CreateNavigator()
  29.  
  30. Dim descNode As XPathNavigator = navigator.SelectSingleNode("//MIFORMS_EXPORT/SESSION/FIELD[@NAME='DESCRIPTOR']")
  31.  
  32. 'Strip the Descriptor to get ID
  33. Dim descriptorString As String = descNode.InnerXml
  34. 'Const descriptorString As String = "3_cytoxdemtest_0199_999_1"
  35.  
  36. 'Strip the Descriptor to get ID
  37. Dim descriptorSplitArray As String() = descriptorString.Split("_")
  38. Dim id As String = descriptorSplitArray(0)
  39.  
  40. 'TASK: Get the pen image PNG name
  41. 'Get the total Session count in XML
  42. Dim penImageRaw As Int32 = doc.GetElementsByTagName("SESSION").Count
  43.  
  44. If penImageRaw > 0 Then
  45. 'Grab the last session element (Last one is count-1)
  46. Dim test As XmlNode = doc.GetElementsByTagName("SESSION").Item(penImageRaw - 1)
  47. Dim list As XmlNodeList = test.ChildNodes
  48.  
  49. For Each node As XmlNode In list
  50. If String.Equals(node.Name, "IMAGE") Then
  51.  
  52. Dim penImageExplode As String() = node.FirstChild.Value.Split("")
  53. PenImage = penImageExplode(penImageExplode.Length - 1)
  54. penPngList.Add(PenImage)
  55.  
  56. End If
  57. Next
  58.  
  59. Else
  60. MsgBox("ERROR: No Session nodes found")
  61. End If
  62.  
  63. 'Set-up MySql connection
  64. Const connStr As String = "server=localhost;user id=root; password=password; database=backend; pooling=false"
  65. Dim conn As New MySqlConnection(connStr)
  66. conn.Open()
  67.  
  68. 'Get the information from that ID the concerned ID
  69. Dim stm As String = "SELECT Patient , Visit, Project, Centre FROM identifiers WHERE ID = '" & id & "'"
  70. Dim cmd As New MySqlCommand(stm, conn)
  71. rdr = cmd.ExecuteReader()
  72.  
  73.  
  74. If rdr.Read Then
  75. patient = rdr.GetString(0)
  76. visit = rdr.GetInt32(1)
  77. project = rdr.GetString(2)
  78. centre = rdr.GetString(3)
  79. Else
  80. Throw New Exception("Could not find the identifier")
  81. End If
  82.  
  83. 'Connect to the patient using the information gathered from above
  84. Dim connStrToProject As String = "server=localhost;user id=root; password=password; database=" & project & "; pooling=false"
  85. Dim connToProject As New MySqlConnection(connStrToProject)
  86. connToProject.Open()
  87.  
  88. 'Set-up MySql connection
  89. Const connStr0 As String = "server=localhost;user id=root; password=password; database=backend; pooling=false"
  90. Dim conn0 As New MySqlConnection(connStr0)
  91. conn0.Open()
  92.  
  93. 'Get the session info
  94. Dim stm0 As String = "SELECT MAX(Session) FROM " & project & ".bay"
  95. Dim cmd0 As New MySqlCommand(stm0, conn0)
  96. rdr0 = cmd0.ExecuteReader()
  97.  
  98. While (rdr0.Read())
  99. If rdr0("MAX(Session)") Is DBNull.Value Then
  100. sessionID = 1
  101. Else
  102. sessionID = rdr0.GetInt32(0)
  103. sessionID = sessionID + 1
  104. End If
  105. End While
  106.  
  107. rdr0.Close()
  108.  
  109. 'For each page of the form pages
  110. For Each myPage As FormPage In _form.Pages()
  111.  
  112. 'Go through each control on the page
  113. For Each myControl As FormControl In myPage.Controls()
  114.  
  115. Dim nowDate As String
  116. nowDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  117.  
  118. 'convert cm to DIU (device-independent units)
  119. Dim rectHeight As Int32 = (myControl.Size.Height / 2.54) * 72
  120. Dim rectWidth As Int32 = (myControl.Size.Width / 2.54) * 72
  121. Dim rectX As Int32 = (myControl.Position.X / 2.54) * 72
  122. Dim rectY As Int32 = (myControl.Position.Y / 2.54) * 72
  123.  
  124. 'As date variable numbers repeat, MiForm adds _x, which breaks update query.
  125. 'This is where we strip that out.
  126. Dim stringToCheck As String = myControl.Name
  127. Const stringToFind As String = "_"
  128. Dim exp As New Regex(stringToFind, RegexOptions.IgnoreCase)
  129. Dim occurrences As Integer = exp.Matches(stringToCheck).Count
  130.  
  131. If occurrences = 1 And stringToCheck.Contains("_M") = False Or myControl.Name.Contains("_T") = False Then
  132. Dim singleVal = myControl.Name.Split("_")
  133. Dim sameValue = singleVal(0)
  134.  
  135. Dim insertQuery1 As String = "INSERT INTO audit_pen (`Session`, `Patient`, `ValidText`, `FieldNumber`, `Marker_Height`, `Marker_Width`, `Marker_X`, `Marker_Y`, `PenPng`, `Visit`, `Page`, `EntryDate`) " & _
  136. "VALUES ('" & sessionID + 1 & "', '" & patient & "', '" & myControl.Value & "', '" & sameValue & "', '" & rectHeight & "', '" & rectWidth & "', '" & rectX & "', '" & rectY & "', '" & penPngList(i) & "', '" & visit & "', '" & myPage.Name & "', '" & nowDate & "')"
  137.  
  138. Dim insertQuery1Exe As New MySqlCommand(insertQuery1, connToProject)
  139. rdr = insertQuery1Exe.ExecuteReader()
  140. rdr.Close()
  141.  
  142. Dim insertQueryForRepeatVars As String = "UPDATE patient" & patient & " SET `Data Verified (valid)` = '1' , " & _
  143. "`Valid Text (validc)` = '" & myControl.Value & "' , " & _
  144. "`Verified DEC (namev)` = '" & penID & "' , " & _
  145. "`Base DEC (nameb)` = '[Valid Override]' , `Compare DEC (namec)` = '[Valid Override]' , " & _
  146. "`LatestPenDate` = '" & nowDate & "' , " & _
  147. "`Base Entry Date (mdateb)` = '" & nowDate & "' , " & _
  148. "`Compare Entry Date (mdatec)` = '" & nowDate & "' , " & _
  149. "UploadedXML = '" & er.DataPathName & "' , " & _
  150. "FromDigiPen = '1' , " & _
  151. "rect_height = '" & rectHeight & "' , " & _
  152. "rect_width = '" & rectWidth & "' , " & _
  153. "rect_x = '" & rectX & "' , " & _
  154. "rect_y = '" & rectY & "' , " & _
  155. "PenPngLocation = '/images/" & penPngList(i) & "'" & _
  156. "WHERE `Visit Number (VISIT)` = '" & visit & "' AND " & _
  157. "`Page Number (PAGE)` = '" & myPage.Name & "' AND " & _
  158. "`Variable Number (var)` = '" & sameValue & "'"
  159.  
  160. Dim insertQueryForRepeatVarsExe As New MySqlCommand(insertQueryForRepeatVars, connToProject)
  161. rdr = insertQueryForRepeatVarsExe.ExecuteReader()
  162. rdr.Close()
  163.  
  164. End If
  165.  
  166. 'If underscore occured twice, that means "_x" was added in a date field "AO001DATE_M_x"
  167. If occurrences = 2 Or myControl.Name.Contains("_M") Or myControl.Name.Contains("_T") Then
  168. Dim test = myControl.Name.Split("_")
  169. Dim sameVarName = test(0) + "_" + test(1)
  170.  
  171. Dim insertQuery2 As String = "INSERT INTO audit_pen (`Session`, `Patient`, `ValidText`, `FieldNumber`, `Marker_Height`, `Marker_Width`, `Marker_X`, `Marker_Y`, `PenPng`, `Visit`, `Page`, `EntryDate`) " & _
  172. "VALUES ('" & sessionID + 1 & "', '" & patient & "', '" & myControl.Value & "', '" & sameVarName & "', '" & rectHeight & "', '" & rectWidth & "', '" & rectX & "', '" & rectY & "', '" & penPngList(i) & "', '" & visit & "', '" & myPage.Name & "', '" & nowDate & "')"
  173.  
  174. Dim insertQuery2Exe As New MySqlCommand(insertQuery2, connToProject)
  175. rdr = insertQuery2Exe.ExecuteReader()
  176. rdr.Close()
  177.  
  178. 'Update the patient data for repeat values
  179. Dim insertQueryForRepeatValues As String = "UPDATE patient" & patient & " SET `Data Verified (valid)` = '1' , " & _
  180. "`Valid Text (validc)` = '" & myControl.Value & "' , " & _
  181. "`Verified DEC (namev)` = '" & penID & "' , " & _
  182. "`Base DEC (nameb)` = '[Valid Override]' , `Compare DEC (namec)` = '[Valid Override]' , " & _
  183. "`LatestPenDate` = '" & nowDate & "' , " & _
  184. "`Base Entry Date (mdateb)` = '" & nowDate & "' , " & _
  185. "`Compare Entry Date (mdatec)` = '" & nowDate & "' , " & _
  186. "UploadedXML = '" & er.DataPathName & "' , " & _
  187. "FromDigiPen = '1' , " & _
  188. "rect_height = '" & rectHeight & "' , " & _
  189. "rect_width = '" & rectWidth & "' , " & _
  190. "rect_x = '" & rectX & "' , " & _
  191. "rect_y = '" & rectY & "' , " & _
  192. "PenPngLocation = '/images/" & penPngList(i) & "'" & _
  193. "WHERE `Visit Number (VISIT)` = '" & visit & "' AND " & _
  194. "`Page Number (PAGE)` = '" & myPage.Name & "' AND " & _
  195. "`Variable Number (var)` = '" & sameVarName & "'"
  196.  
  197. Dim insertQueryForRepeatValuesExe As New MySqlCommand(insertQueryForRepeatValues, connToProject)
  198. rdr = insertQueryForRepeatValuesExe.ExecuteReader()
  199. rdr.Close()
  200.  
  201. End If
  202.  
  203. If occurrences = 0 Then
  204.  
  205. Dim insertQuery2 As String = "INSERT INTO audit_pen (`Session`, `Patient`, `ValidText`, `FieldNumber`, `Marker_Height`, `Marker_Width`, `Marker_X`, `Marker_Y`, `PenPng`, `Visit`, `Page`, `EntryDate`) " & _
  206. "VALUES ('" & sessionID + 1 & "', '" & patient & "', '" & myControl.Value & "', '" & myControl.Name & "', '" & rectHeight & "', '" & rectWidth & "', '" & rectX & "', '" & rectY & "', '" & penPngList(i) & "', '" & visit & "', '" & myPage.Name & "', '" & nowDate & "')"
  207.  
  208. Dim insertQuery2Exe As New MySqlCommand(insertQuery2, connToProject)
  209. rdr = insertQuery2Exe.ExecuteReader()
  210. rdr.Close()
  211.  
  212. 'Update the patient data
  213. Dim insertQuery As String = "UPDATE patient" & patient & " SET `Data Verified (valid)` = '1' , " & _
  214. "`Valid Text (validc)` = '" & myControl.Value & "' , " & _
  215. "`Verified DEC (namev)` = '" & penID & "' , " & _
  216. "`Base DEC (nameb)` = '[Valid Override]' , `Compare DEC (namec)` = '[Valid Override]' , " & _
  217. "`LatestPenDate` = '" & nowDate & "' , " & _
  218. "`Base Entry Date (mdateb)` = '" & nowDate & "' , " & _
  219. "`Compare Entry Date (mdatec)` = '" & nowDate & "' , " & _
  220. "UploadedXML = '" & er.DataPathName & "' , " & _
  221. "FromDigiPen = '1' , " & _
  222. "rect_height = '" & rectHeight & "' , " & _
  223. "rect_width = '" & rectWidth & "' , " & _
  224. "rect_x = '" & rectX & "' , " & _
  225. "rect_y = '" & rectY & "' , " & _
  226. "PenPngLocation = '/images/" & penPngList(i) & "'" & _
  227. "WHERE `Visit Number (VISIT)` = '" & visit & "' AND " & _
  228. "`Page Number (PAGE)` = '" & myPage.Name & "' AND " & _
  229. "`Variable Number (var)` = '" & myControl.Name & "'"
  230.  
  231. Dim insertQueryExe As New MySqlCommand(insertQuery, connToProject)
  232. rdr = insertQueryExe.ExecuteReader()
  233. rdr.Close()
  234.  
  235. End If
  236.  
  237. Next myControl
  238. i += 1
  239. Next myPage
  240. End If
  241. Next
  242.  
  243. Catch ex As Exception
  244.  
  245. Dim nowDate As String
  246. nowDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  247.  
  248. Dim rdrError As MySqlDataReader
  249.  
  250. 'Connect to the patient using the information gathered from above
  251. Const connStrToProject As String = "server=localhost;user id=root; password=password; database=backend; pooling=false"
  252. Dim connToProject As New MySqlConnection(connStrToProject)
  253. connToProject.Open()
  254.  
  255. Dim insertError As String = "INSERT INTO penerror (`Pen`, `Error`, `Study`, `ErrorDate`) VALUES ('" & penID & "', """ & ex.Message & """, '" & project & "', '" & nowDate & "')"
  256. Dim insertErrorExe As New MySqlCommand(insertError, connToProject)
  257. rdrError = insertErrorExe.ExecuteReader()
  258. rdrError.Close()
  259.  
  260. End Try
  261.  
  262. Throw New Exception("Could not find the identifier")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement