Visual Basic code snippet for using the generalFormRequestManager


Private Sub CommandButton1_Click()

On Error GoTo Err_Trap

Dim bStatus As Boolean
Dim strFormOID As String
Dim lFormVersion As Long
Dim eFormLanguage As LanguageType
Dim strIntermediates As String
Dim eHasDirectSend As YesNoType

Dim formRequestManagerEx As GENERALFORMREQUESTMANAGER450Lib.GeneralFormRequestManager
Set formRequestManagerEx = New GENERALFORMREQUESTMANAGER450Lib.GeneralFormRequestManager

Dim formRequestEx As GENERALFORMREQUESTMANAGER450Lib.GeneralFormRequest
Dim formResultEx As GENERALFORMREQUESTMANAGER450Lib.GeneralFormResult

'### set module language to german
formRequestManagerEx.ModuleLanguage = enGerman

'### load an example form
bStatus = formRequestManagerEx.LoadPDF("medforms.40.40.10.5060", strFormOID, _
                                        lFormVersion, eFormLanguage, strIntermediates, _
                                        eHasDirectSend, formRequestEx, formResultEx)
        

'### set addresses
Dim IAddress As GENERALFORMREQUESTMANAGER450Lib.Address
Set IAddress = formRequestEx.CreateAddress
Dim eAddressRole As AddressRoleType
Dim strAddressName As String
Dim lIndex As Long
Dim lMaxOccurs As Long
Dim eIsDefined As GENERALFORMREQUESTMANAGER450Lib.YesNoType

Dim strConstrained As String
Dim bHasAddress, bFirst As Boolean
bHasAddress = True
bFirst = True


While bHasAddress

    If bFirst Then
            bStatus = formRequestEx.GetFirstAddressRole(eAddressRole, strAddressName, lIndex, _
                                                        lMaxOccurs, eIsDefined, strConstrained)
            bFirst = False
    Else
            bStatus = formRequestEx.GetNextAddressRole(eAddressRole, strAddressName, lIndex, _
                                                       lMaxOccurs, eIsDefined, strConstrained)
    End If
    If bStatus Then
        '### set the producer
        If eAddressRole = enAddressRoleProducer Then
            IAddress.Initialize
            bStatus = IAddress.SetCompany("Gruppenpraxis XY", "", "")
            bStatus = IAddress.SetPostal("Arztgasse 17b5", "", "4000", "Basel", "BS", "")
            bStatus = formRequestEx.AddAddress(strAddressName, "2000000110000", "", "", _
                                               "speciality", IAddress)
        End If
        '### set the consumer
        If eAddressRole = enAddressRoleConsumer Then
            IAddress.Initialize
            bStatus = IAddress.SetCompany("Krankenkasse AG", "Sektion Basel", "")
            bStatus = IAddress.SetPostal("Kassengraben 222", "", "4000", "Basel", "", "")
            bStatus = formRequestEx.AddAddress(strAddressName, "2034567890222", "", "", _
			                                   "", IAddress)
        End If
        '### set the provider
        If eAddressRole = enAddressRoleProvider Then
            IAddress.Initialize
            bStatus = IAddress.SetPerson("Aerztin", "Patricia", "Frau", "Dr. med.", "")
            bStatus = IAddress.SetPostal("Arztgasse 17b5", "", "4000", "Basel", "BS", "")
            bStatus = formRequestEx.AddAddress(strAddressName, "2000000000000", "", "", _
                                               "speciality", IAddress)
        End If
        '### set the patient
        If eAddressRole = enAddressRolePatient Then
            IAddress.Initialize
            bStatus = IAddress.SetPerson("Muster", "Peter", "Herr", "", "c/o Mieter Karl")
            bStatus = IAddress.SetPostal("Musterstrasse 5", "", "7304", "Maienfeld", "", "")
            bStatus = formRequestEx.SetPatient(strAddressName, enMale, DateValue("1940-6-25"), _
                                               "", IAddress)
        End If
    Else
        bHasAddress = False
    End If
Wend


'### add a diagnosis
Dim eStructRole As GENERALFORMREQUESTMANAGER450Lib.StructRoleType
Dim strStructName As String
Dim bHasStruct As Boolean
bHasStruct = True
bFirst = True

While bHasStruct
    If bFirst Then
        bStatus = formRequestEx.GetFirstStructRole(eStructRole, strStructName, lIndex, _ 
                                                   lMaxOccurs, eIsDefined, strConstrained)
        bFirst = False
        
    Else
        bStatus = formRequestEx.GetNextStructRole(eStructRole, strStructName, lIndex, _
                                                  lMaxOccurs, eIsDefined, strConstrained)
    End If
    If bStatus Then
        If eStructRole = enStructRoleDiagnosis Then
            bStatus = formRequestEx.AddDiagnosis(strStructName, enDiagnosisFreeText, _
                                                 "n/a", "previously undiscovered virus", _
                                                 0, enYes, Null)
            bHasStruct = False
        End If
    Else
        bHasStruct = False
    End If
Wend

'### set transport
bStatus = formRequestEx.SetTransport("2000000110000", "", "", "", "2034567890222", "")

'### set request
bStatus = formRequestEx.SetRequest(enRolePhysician, enPlacePractice, "", enNo, enNo)

'### set form
Dim dRequestFormDate As Date
dRequestFormDate = DateValue("2011-09-20")
Dim strRequestFormID As String
strRequestFormID = "internal-id"
Dim lRequestTimestamp As Long
lRequestTimetamp = 11111111

bStatus = formRequestEx.SetFormObject(strRequestFormID, dRequestFormDate, lRequestTimestamp)

'###
Dim lTotalVars As Long
Dim lUndefVars As Long
Dim strPDFFile As String

'### produce an xml
Dim lXMLGenerationAttributes As Long
lXMLGenerationAttributes = 0
Dim strOutputXml As String
Dim lValidationError As Long
Dim lTimestamp As Long


bStatus = formRequestManagerEx.GetXML(lXMLGenerationAttributes, strOutputXml, _
                                      lValidationError, lTimestamp)
If bStatus Then
    Dim strTargetFile As String
    strTargetFile = "d:\TestXML.xml"
    FileCopy strOutputXml, strTargetFile
Else
    Dim strAbortInfo As String
    Call formRequestManagerEx.GetAbortInfo(strAbortInfo)
End If

Exit Sub

Err_Trap:
    MsgBox "Error: " & Err.Description, vbCritical, _
           "Opps! Error" & Str$(Err.Number)

'### relase resources

End Sub