Skip to content

Commit

Permalink
Merge branch 'oop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Oct 28, 2024
2 parents 6d7c1ea + a05fe4e commit 9fb4c67
Showing 1 changed file with 62 additions and 16 deletions.
78 changes: 62 additions & 16 deletions src/server.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
diagnosis <- setRefClass(
"Diagnosis",
fields = list(
hosp_soft = "numeric", # cross-proportion of surgical and vyntus
hosp = "numeric", # proportion of surgical centres
soft = "numeric", # proportion of vyntus software
heart_rate = "function",
breathing_frequency = "function"
)
)

person <- setRefClass(
"Person",
fields = list(
sex = "numeric",
height = "numeric",
bmi = "numeric"
)
)

simple <- diagnosis(
hosp_soft = c(0.3994, 0.0029, 0.5478, 0.0499),
hosp = 0.5849,
soft = 0.0528,
heart_rate = function(.self, person) {
(9168804 * person$height + 5.13e9) ^ (1 / 4.3)
},
breathing_frequency = function(.self, person) {
(- 0.0114363 * person$height + 0.0007431 * person$sex - 0.1421088 * .self$hosp + 6.693345) ^ (1 / 0.4)
}
)

moderate <- diagnosis(
hosp_soft = c(0.6439, 0.0060, 0.2938, 0.0563),
hosp = 0.6499,
soft = 0.0624,
heart_rate = function(.self, person) {
(9.9e8 * person$height - 2.86e9 * person$bmi + 1.4e11) ^ (1 / 5)
},
breathing_frequency = function(.self, person) {
(-0.037375 * person$height - 1.778892 * person$sex + 0.0134113 * person$height * person$sex - 0.3806323 * .self$hosp + 16.65239) ^ (1 / 0.6)
}
)

fontan <- diagnosis(
hosp_soft = c(0.7834, 0.0072, 0.1697, 0.0397),
hosp = 0.7906,
soft = 0.0469,
heart_rate = function(.self, person) {
(-144400.5 * person$height - 3.81e7 * person$sex + 2076971 * person$bmi * person$sex + 1.24e7 * .self$soft + 9.75e7) ^ (1 / 3.5)
},
breathing_frequency = function(.self, person) {
exp(-0.0044619 * person$height + 0.0225936 * log(person$bmi) * person$sex - 0.0820773 * .self$hosp + 4.609728)
}
)

server <- function(input, output) {
vo2_ml_min <- function() {
NA
Expand All @@ -6,16 +62,6 @@ server <- function(input, output) {
vo2_ml_kg_min <- function() {
NA
}

heart_rate <- function(diagnosis, height, bmi, is_male) {
is_vyntus <- 0.0469 # prop. of Vyntus on Fontan (only relevant case here)
switch(diagnosis,
"simple" = (9168804 * height + 5.13e9) ^ (1 / 4.3),
"moderate" = (9.9e8 * height - 2.86e9 * bmi + 1.4e11) ^ (1 / 5),
"fontan" = (-144400.5 * height - 3.81e7 * is_male + 2076971 * bmi * is_male + 1.24e7 * is_vyntus + 9.75e7) ^ (1 / 3.5)
)
}

ventilation <- function() {
NA
}
Expand All @@ -28,11 +74,11 @@ server <- function(input, output) {
NA
}

breathing_frequency <- function() {
NA
}

output$results_table <- renderTable({
diag <- get(input$diagnosis)
person <- person(
sex = as.numeric(input$sex), height = input$height, bmi = input$bmi
)
data.frame(
"Metric" = c(
"VO2 ml/min", "VO2 ml/kg/min", "Heart rate", "Ventilation",
Expand All @@ -41,11 +87,11 @@ server <- function(input, output) {
"Value" = c(
vo2_ml_min(),
vo2_ml_kg_min(),
heart_rate(input$diagnosis, input$height, input$bmi, as.numeric(input$sex)),
diag$heart_rate(diag, person),
ventilation(),
oxygen_pulse(),
ve_vco2_slope(),
breathing_frequency()
diag$breathing_frequency(diag, person)
)
)
})
Expand Down

0 comments on commit 9fb4c67

Please sign in to comment.