Skip to content

Instantly share code, notes, and snippets.

@halcwb
halcwb / CalcPAFratio.vb
Created July 27, 2023 10:12
Calculate PAF ration using FiO2 estimation
Sub Main
Console.WriteLine(CalcPAFratio("", 0, 100, 50))
Console.WriteLine(CalcPAFratio("", 0, 50, 100))
Console.WriteLine(CalcPAFratio("lowflow", 5, 100, 50))
Console.WriteLine(CalcPAFratio("mask", 6, 100, 50))
Console.WriteLine(CalcPAFratio("mask", 12, 100, 50))
End Sub
@halcwb
halcwb / CalcEstimatedBW.vb
Created July 27, 2023 10:11
Calculate estimated/ideal body weight
Sub Main
Dim dblAge As Double = 0
For intM As Integer = 0 To 12
dblAge = intM / 12
Console.WriteLine("{0}, {1}", intM, CalcEstimatedBW(dblAge, "", 0))
Next
For intY As Integer = 0 To 9
dblAge = intY
@halcwb
halcwb / CalcAaO2Grandient.vb
Last active July 26, 2023 10:59
Calculate an A-a O2 gradient
Sub Main
Console.WriteLine(CalcAaO2Gradient(21, 80, 45))
End Sub
' A-a O2 Gradient = [ (FiO2) × (Atmospheric Pressure - H2O Pressure) - (PaCO2/0.8) ] – PaO2
' Normal gradient = (age / 4) + 4
' Returns -1 if A-a O2 gradient cannot be calculated
Function CalcAaO2Gradient(dblFiO2 As Double, dblPaO2 As Double, dblPaCO2 As Double) As Double
Dim dblGrad As Double = -1
Const dblPatm As Double = 760
@halcwb
halcwb / CalcEGFR.vb
Last active July 26, 2023 09:49
Function to calculate the eGFR according to available parameters
Sub Main
Dim dblCreat As Double = 88.42
Dim dblUrea As Double = 0.3571
Dim dbleGFR As Double
' cannot calculate
dblEGFR = CalcEGFR("", 0, 0, 0, 0, 0)
Console.WriteLine(System.Math.Round(dbleGFR, 0)) ' -1
@halcwb
halcwb / QueryOpenAI.vb
Last active July 26, 2023 06:25
Code to query open AI
Sub Main
Dim strApiKey As String = "<API_KEY>"
Dim strContent As String = "say: Hello world, this is from open AI"
Dim strResult = MakeWebRequest(CreateOpenAIRequest(strApiKey, strContent))
Console.WriteLine(ParseOpenAIJson(strResult, "content"))
End Sub
Function CreateOpenAIRequest(strApiKey As String, strContent As String) As System.Net.Http.HttpRequestMessage
@halcwb
halcwb / InsertFunction.sql
Last active July 26, 2023 09:43
Insert a parameterized function in a MV database
begin transaction
declare @stat_ModuleID as smallint;
declare @stat_VBScript as nvarchar(max);
declare @stat_Name as nvarchar(100);
declare @stat_Description as nvarchar(1000);
declare @stat_OldVbScript as nvarchar(max);
declare @stat_LastUpdateGUID as uniqueidentifier;
-- makes it an internal parameterized function
@halcwb
halcwb / CalcAge.vbs
Last active July 27, 2023 18:43
Calculate age in years, months, weeks and days
Sub Main
Dim dtmFrom As Date
Dim dtmTo As Date
' 366. 1-1-2022 - 1-1-2023 -> Age: 1 years, 11 months, 0 weeks, -334 days
dtmFrom = New System.DateTime(2022, 1, 1)
dtmTo = New System.DateTime(2023, 1, 1)
' TestCase(1, dtmFrom, dtmTo)
TestAll()
TestRand()
@halcwb
halcwb / CalcBSA.vb
Last active July 27, 2023 17:31
Calculate BSA using different formulas
Sub Main
Dim dblW As Double = 10
Dim dblH As Double = 70
Dim strForm As String = ""
System.Console.WriteLine("{0}: {1}", strForm, CalcBSA(strForm, dblW, dblH))
strForm = "mosteller"
System.Console.WriteLine("{0}: {1}", strForm, CalcBSA(strForm, dblW, dblH))
strForm = "dubois"
System.Console.WriteLine("{0}: {1}", strForm, CalcBSA(strForm, dblW, dblH))
@halcwb
halcwb / FixPrecision.vb
Last active July 27, 2023 17:25
FixPrecision
Sub Main
Dim dblNum As Double = 1.12345
Console.WriteLine("FixPrec: {0}", FixPrecision(dblNum, 2))
End Sub
' Purpose: Relative rounding of a number with a specified minimum precision. All digits
' before the decimal point are preserved. Digits after the decimal point are preserved
' as follows:
@halcwb
halcwb / DateTime.fsx
Last active June 17, 2023 10:54
F# DateTime extensions
module DateTime =
open System
let create (year: int) (month: int) (day: int) = DateTime(year, month, day)
let withContinuation fSucc fErr year month day =