ongke0711 > 21-04-23, 05:27 PM
ongke0711 > 23-04-23, 09:26 AM
danhxetnghiem > 23-04-23, 07:57 PM
(23-04-23, 09:26 AM)ongke0711 Đã viết: Tôi thấy file Log này dạng chuẩn HL7 nên dùng code đọc từng dòng lấy dữ liệu cũng được. Tôi nhớ lúc trước có làm rồi, để tìm lại xem.
Dim filePath As String, fileLine As String
Dim fileNumber As Long, i As Long, k As Long, currentRow As Long, startRow As Long
Dim sSampleID As String, sPatientID As Long, sTestDate As String, sTestTime As String, sCheckID As String
filePath = sFilePath
fileNumber = FreeFile()
Open filePath For Input As #fileNumber
startRow = 6 'Dòng bat dau trích xuat du lieu
currentRow = 0
i = 0
Dim arrResult(50, 2) As Variant ' Khai báo lai so dòng cho mang neu vuot hon 50
Do While Not EOF(fileNumber)
Line Input #fileNumber, fileLine
If InStr(1, fileLine, "PID") > 0 Then sPatientID = Trim(Mid(Replace(fileLine, "|", ""), 7, 4))
If InStr(1, fileLine, "OBR") > 0 Then sSampleID = Trim(Mid(Replace(fileLine, "|", ""), 5, 12))
If InStr(1, fileLine, "OBR") > 0 Then sTestDate = Trim(Mid(Replace(fileLine, "|", ""), 20, 8))
If InStr(1, fileLine, "OBR") > 0 Then sTestTime = Trim(Mid(Replace(fileLine, "|", ""), 28, 6))
If InStr(1, fileLine, "OBX|1|NM|WBCHistogram^LeftLine") > 0 Then Exit Do
If currentRow >= startRow Then
Dim lineColumns() As String
lineColumns = Split(fileLine, "|")
arrResult(i, 0) = lineColumns(3): arrResult(i, 2) = lineColumns(5)
i = i + 1
End If
currentRow = currentRow + 1
Loop
sCheckID = sSampleID & "_" & sPatientID & "_" & sTestDate & "_" & sTestTime
Close #fileNumber
CurrentDb.Execute "DELETE * FROM tblKQXN_Temp", dbFailOnError
For k = 0 To i - 1
CurrentDb.Execute "INSERT INTO tblKQXN_Temp (PatientID, Params, Flags, Val, SampleID, TestDate, TestTime, CheckID)" _
& " VALUES (" & sPatientID & ",'" & arrResult(k, 0) & "','" & Trim(arrResult(k, 1)) & "'," & CDbl(arrResult(k, 2)) & ",'" & sSampleID & "','" & sTestDate & "','" & sTestTime & "','" & sCheckID & "')", dbFailOnError
Next
Me.txtSampleID = sSampleID
Me.txtTestDate = sTestDate
Me.txtTestTime = sTestTime
Me.txtPatientID = sPatientID
Me.txtPatientName = DLookup("PatientName", "tblBenhNhan", "[PatientID]=" & sPatientID)
Me.txtAddress = DLookup("Address", "tblBenhNhan", "[PatientID]=" & sPatientID)
Me.txtCheckID = sCheckID
'MsgBox "Import thành công"
End Sub
ongke0711 > 24-04-23, 11:51 AM
(23-04-23, 07:57 PM)danhxetnghiem Đã viết: file .log này mình thấy giống y file .txt, vẫn dùng cách hôm trước vẫn lấy được. Mình đã thử rồi, lấy y như .txt vậy.