Advertisement
Leb_dev

Untitled

Oct 7th, 2019
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub InsertScript()
  2.     Dim sheetIndex, index
  3.    
  4.     Dim fso As Object
  5.     Set fso = CreateObject("Scripting.FileSystemObject")
  6.     Dim oFile As Object
  7.     Set oFile = fso.CreateTextFile("C:\Oracle\SQL.txt")
  8.        
  9.     Dim sheet As Worksheet
  10.     Dim q
  11.     q = Chr(39)
  12.    
  13.     sheetIndex = 1
  14.     For Each sheet In ActiveWorkbook.Worksheets
  15.         If EndsWith(sheet.Name, "(Ç)") Then
  16.             oFile.WriteLine "INSERT INTO CITY_COMMON_ASSIGNMENT_PACKAGE (ID, NAME, DIAGNOSTIC, DISPANSERIZATION, ARCHIVED) VALUES (" + CStr(sheetIndex) + ", " + q + sheet.Name + q + ", 1, 1, 0);"
  17.             sheetIndex = sheetIndex + 1
  18.         End If
  19.     Next
  20.     oFile.WriteLine
  21.    
  22.     sheetIndex = 1
  23.     index = 1
  24.     For Each sheet In ActiveWorkbook.Worksheets
  25.         Dim template, t, content  As String
  26.         Dim i, required As Integer
  27.         i = 2
  28.         If EndsWith(sheet.Name, "(Ç)") Then
  29.             Debug.Print "PROCESSED: " + sheet.Name
  30.             For Each Row In sheet.Rows
  31.                 If (sheet.Cells(i, 1).Value = "") Then
  32.                     Exit For
  33.                 End If
  34.                
  35.                 content = ""
  36.                 If InStr(UCase(sheet.Cells(i, 2).Value), "ÊÎÍÑÓËÜÒÀÖÈ") <> 0 Then
  37.                     template = q + "openEHR-EHR-COMPOSITION.t_consultation_order.v1" + q
  38.                     t = q + "Consultation" + q
  39.                     content = content + AddField("specialityName", sheet.Cells(i, 3).Value)
  40.                 ElseIf InStr(UCase(sheet.Cells(i, 2).Value), "ËÈ") <> 0 Then
  41.                     template = q + "openEHR-EHR-COMPOSITION.t_laboratory_test_order.v1" + q
  42.                     t = q + "Laboratory" + q
  43.                 ElseIf InStr(UCase(sheet.Cells(i, 2).Value), "ÈÈ") <> 0 Then
  44.                     template = "null"
  45.                     t = q + "Instrumental" + q
  46.                 Else:
  47.                     Err.Raise vbObjectError + 1, "Macro1", "WRONG ARGUMENT IN " + sheet.Name + "." + sheet.Cells(1, 2) + "." + CStr(i)
  48.                 End If
  49.            
  50.                 content = content + AddField("specializationId", sheet.Cells(i, 4).Value)
  51.                 content = content + AddField("laboratoryId", sheet.Cells(i, 5).Value)
  52.                 content = content + AddField("biomaterial", sheet.Cells(i, 7).Value)
  53.                 content = content + AddField("biomaterialCode", sheet.Cells(i, 6).Value)
  54.                 content = content + AddField("locusCode", sheet.Cells(i, 8).Value)
  55.                 content = content + AddField("locus", sheet.Cells(i, 9).Value)
  56.                 content = content + AddField("instrumentalId", sheet.Cells(i, 10).Value)
  57.                 content = content + AddField("ldpId", sheet.Cells(i, 11).Value)
  58.                 If content = "" Then
  59.                     'Err.Raise vbObjectError + 1, "Macro1", "CONTENT EMPTY " + sheet.Name + "." + CStr(i)
  60.                    content = "{}"
  61.                 Else
  62.                     content = "{" + Left(content, Len(content) - 1) + "}"
  63.                 End If
  64.                
  65.                 If (UCase(sheet.Cells(i, 2).Value) = "ÄÀ") Then
  66.                     required = 1
  67.                 Else
  68.                     required = 0
  69.                 End If
  70.                
  71.                 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) + ");"
  72.                
  73.                 i = i + 1
  74.                 index = index + 1
  75.             Next
  76.             'ElseIf EndsWith(sheet.Name, "(Ä)") Then
  77.            'Debug.Print "SKIPPED: " + sheet.Name
  78.        Else
  79.             Debug.Print "SKIPPED: " + sheet.Name
  80.         End If
  81.                
  82.         oFile.WriteLine
  83.         sheetIndex = sheetIndex + 1
  84.     Next
  85.    
  86.     oFile.Close
  87.     Set fso = Nothing
  88.     Set oFile = Nothing
  89. End Sub
  90.  
  91. Public Function EndsWith(str As String, ending As String) As Boolean
  92.      Dim endingLen As Integer
  93.      endingLen = Len(ending)
  94.      EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))
  95. End Function
  96.  
  97. Public Function AddField(fieldName As String, fieldValue As String) As String
  98.     AddField = ""
  99.     If fieldValue <> "-" And fieldValue <> "" Then
  100.         AddField = """" + fieldName + """:""" + fieldValue + ""","
  101.     End If
  102. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement