Thursday, January 30, 2020

Updated VB.NET Sample Code

We recently had to help a customer get our DLL to work in their VB.Net environment because our sample code was so out of date. In order to spare other customers this pain, we post this code example. Note that this code is for version 37 (v37); change the version to match your particular situation.


Option Explicit On
Imports System.Deployment
Imports System.Runtime.InteropServices

Module Module1
    Private Declare Function mhdllver Lib "vbdrgv37.dll" (ByVal Buf As String,
    ByVal BufLen As Int32) As Integer

    Private Declare Function mhdrg1 Lib "vbdrgv37.dll" (ByRef drg As Int32,
    ByVal DRGVersion As String, ByVal MasksPath As String, ByVal DischStat As String,
    ByVal PtAge As String, ByVal PtGender As String, ByVal DXList As String,
    ByVal ProcList As String, ByVal POAPresent As String, ByVal ExemptFlag As String) As Int32

    Private Declare Sub mhinfo Lib "vbdrgv37.dll" (ByVal drg As Int32,
    ByVal DRGVersion As String, ByVal MasksPath As String, ByRef mdc As Int32,
    ByRef weight As Double, ByRef los As Double, ByVal Desc As String, ByVal DescLen As Int32)

    Private Declare Function mhdrgver Lib "vbdrgv37.dll" (ByVal MPath As String,
    ByVal Buf As String, ByVal BufLen As Int32) As Int32

    Private Declare Sub mherrdesc Lib "vbdrgv37.dll" (ByVal errBuffer As String, ByVal errLength As Int32)


    Sub Main()
        AssignDRG()
    End Sub

    Public Function AssignDRG()
        Dim ReturnCode As Integer
        Dim drg As Int32, mdc As Int32
        Dim Desc As String
        Dim descLen As Int32
        Dim weight As Double, los As Double
        Dim masksdir As String

        Dim myver As String, mydstat As String, myage As String, mysex As String, myexempt As String, mypoa As String
        Dim mydxstring As String
        Dim mypxstring As String
        Dim pos As Int32

        ' Hardcoded in this example
        masksdir = "C:\Program Files (x86)\MandH\MASKS\" & ControlChars.NullChar
' Ideally, got from registry. Old VB-for-Access example:
' masksdir = QueryValue("Software\MandH\", "BaseDir") & "\Masks\"

        myver = "v37e" ' version 37, exempt from HAC rules
        mydstat = "1"
        myage = "77"
        mysex = "1"
        mydxstring = "I2119^" ' ^ terminates the string; any of ,|-+ separate fields; ~ is followed by PoA
        mypxstring = "02703ZZ^"
        mypoa = "N" ' no POA because no HAC rules
        myexempt = "X" ' crazy way this works: X = exempt, Z = not exempt
        descLen = 80 ' left over from dumb ASCII terminal days; use whatever you like

        ' these should come back from the DLL call
        drg = 0
        mdc = 0
        weight = 150
        los = 10
        Desc = Space(descLen)

' confirm which DLL we have loaded
        drg = mhdllver(Desc, descLen)
        ' deal with char ASCIIz (null-terminated string)
        pos = InStr(1, Desc, ControlChars.NullChar, CompareMethod.Binary)
        Console.WriteLine("DLL Version: " & Desc.Substring(0, pos))

' Assign the DRG for this age, sex, discharge status, exemption, diagnoses and procedures
        ReturnCode = mhdrg1(drg, myver, masksdir, mydstat, myage, mysex, mydxstring, mypxstring, mypoa, myexempt)
        Console.WriteLine("DLL.mhdrg1 returned RC=" & ReturnCode.ToString)

        If ReturnCode = 0 Then
            Console.WriteLine("DLL.mhdrg1 returned DRG=" & drg.ToString)
            Call mhinfo(drg, myver, masksdir, mdc, weight, los, Desc, descLen)
            Console.WriteLine("DLL.mhinfo returned ver=" & myver & " " _
                              & "MDC=" & mdc.ToString & " " _
                              & "Weight=" & weight.ToString & " " _
                              & "LOS=" & los.ToString & " ")
            Console.WriteLine("Desc=[" & Desc & "]")
        Else
            Call mherrdesc(Desc, descLen)
            Console.WriteLine("Error: " & Desc)
        End If

' Should produce this output:
' DLL Version: mhdrgv37.dll v2.10 (c) 2015 M+H Consulting, LLC: v37
' DLL.mhdrg1 returned RC=0
' DLL.mhdrg1 returned DRG=251
' DLL.mhinfo returned ver=v37e MDC=5 Weight=1.683 LOS=2.2
' Desc=[PERC CARDIOVASC PROC W/O CORONARY ARTERY STENT W/O MCC                          ]

        Return ReturnCode
    End Function

End Module

No comments:

Post a Comment