Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub InsertScript()
- Dim sheetIndex, index
- Dim fso As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
- Dim oFile As Object
- Set oFile = fso.CreateTextFile("C:\Oracle\SQL.txt")
- Dim sheet As Worksheet
- Dim q
- q = Chr(39)
- sheetIndex = 1
- For Each sheet In ActiveWorkbook.Worksheets
- If EndsWith(sheet.Name, "(Ç)") Then
- oFile.WriteLine "INSERT INTO CITY_COMMON_ASSIGNMENT_PACKAGE (ID, NAME, DIAGNOSTIC, DISPANSERIZATION, ARCHIVED) VALUES (" + CStr(sheetIndex) + ", " + q + sheet.Name + q + ", 1, 1, 0);"
- sheetIndex = sheetIndex + 1
- End If
- Next
- oFile.WriteLine
- sheetIndex = 1
- index = 1
- For Each sheet In ActiveWorkbook.Worksheets
- Dim template, t, content As String
- Dim i, required As Integer
- i = 2
- If EndsWith(sheet.Name, "(Ç)") Then
- Debug.Print "PROCESSED: " + sheet.Name
- For Each Row In sheet.Rows
- If (sheet.Cells(i, 1).Value = "") Then
- Exit For
- End If
- content = ""
- If InStr(UCase(sheet.Cells(i, 2).Value), "ÊÎÍÑÓËÜÒÀÖÈ") <> 0 Then
- template = q + "openEHR-EHR-COMPOSITION.t_consultation_order.v1" + q
- t = q + "Consultation" + q
- content = content + AddField("specialityName", sheet.Cells(i, 3).Value)
- ElseIf InStr(UCase(sheet.Cells(i, 2).Value), "ËÈ") <> 0 Then
- template = q + "openEHR-EHR-COMPOSITION.t_laboratory_test_order.v1" + q
- t = q + "Laboratory" + q
- ElseIf InStr(UCase(sheet.Cells(i, 2).Value), "ÈÈ") <> 0 Then
- template = "null"
- t = q + "Instrumental" + q
- Else:
- Err.Raise vbObjectError + 1, "Macro1", "WRONG ARGUMENT IN " + sheet.Name + "." + sheet.Cells(1, 2) + "." + CStr(i)
- End If
- content = content + AddField("specializationId", sheet.Cells(i, 4).Value)
- content = content + AddField("laboratoryId", sheet.Cells(i, 5).Value)
- content = content + AddField("biomaterial", sheet.Cells(i, 7).Value)
- content = content + AddField("biomaterialCode", sheet.Cells(i, 6).Value)
- content = content + AddField("locusCode", sheet.Cells(i, 8).Value)
- content = content + AddField("locus", sheet.Cells(i, 9).Value)
- content = content + AddField("instrumentalId", sheet.Cells(i, 10).Value)
- content = content + AddField("ldpId", sheet.Cells(i, 11).Value)
- If content = "" Then
- 'Err.Raise vbObjectError + 1, "Macro1", "CONTENT EMPTY " + sheet.Name + "." + CStr(i)
- content = "{}"
- Else
- content = "{" + Left(content, Len(content) - 1) + "}"
- End If
- If (UCase(sheet.Cells(i, 2).Value) = "ÄÀ") Then
- required = 1
- Else
- required = 0
- End If
- oFile.WriteLine "INSERT INTO CITY_COMMON_ASSIGNMENT (ID, PACKAGE_ID, NAME, TEMPLATE_ID, " + q + "TYPE" + q + ", CONTENT, REQUIRED) VALUES (" + CStr(index) + ", " + CStr(sheetIndex) + ", " + q + sheet.Cells(i, 3).Value + q + ", " + template + ", " + t + ", " + q + content + q + ", " + CStr(required) + ");"
- i = i + 1
- index = index + 1
- Next
- 'ElseIf EndsWith(sheet.Name, "(Ä)") Then
- 'Debug.Print "SKIPPED: " + sheet.Name
- Else
- Debug.Print "SKIPPED: " + sheet.Name
- End If
- oFile.WriteLine
- sheetIndex = sheetIndex + 1
- Next
- oFile.Close
- Set fso = Nothing
- Set oFile = Nothing
- End Sub
- Public Function EndsWith(str As String, ending As String) As Boolean
- Dim endingLen As Integer
- endingLen = Len(ending)
- EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))
- End Function
- Public Function AddField(fieldName As String, fieldValue As String) As String
- AddField = ""
- If fieldValue <> "-" And fieldValue <> "" Then
- AddField = """" + fieldName + """:""" + fieldValue + ""","
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement