-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrManuscriptCovObs2.Rmd
1471 lines (1259 loc) · 71.1 KB
/
ScrManuscriptCovObs2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
#title: "Untitled"
#author: "Luis G. Vazquez de Lara Cisneros."
#date: "15/1/2021"
#site: bookdown::bookdown_site
output:
bookdown::word_document2:
reference_docx: templateword3.docx
bibliography: references.bib
csl: archives-of-medical-research.csl
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE
)
#libraries:
library(tidyverse)
library(lubridate)
#library(scales)
library(flextable) #para Word es mejor que kableExtra en tablas
library(officer)
library(officedown)
#library(kableExtra) #para las figuras
library(knitr) # para estar checando errores (correr chunks antes de compilar)
library(binom)
library(gridExtra)
library(survival)
library(survminer)
#External data
load('Rdata/bdcoving.rda')
load('Rdata/labosvalref.rda') #Base de laboratorios
load('Rdata/bdcovdiario.rda')
load('Rdata/dfmexhosp.rda')
```
# Title {.unnumbered}
Presenting Characteristics, Clinical Features and Outcomes of Hospitalized Patients with Covid-19. Experience in a Tertiary Level Mexican Hospital.
# Summary {.unnumbered}
Background.
Covid-19 is a novel coronavirus disease with a broad clinical spectrum that has spread globally. Currently there is no standardized treatment, and the outcome varies greatly among countries. Accordingly, regional information is needed to inform the decision making for health care providers.
Aim of the study.
Describe the presenting characteristics, clinical course and outcomes of hospitalized patients in a tertiary Mexican hospital.
Methods.
Retrospective cohort study of 619 consecutive patients admitted to the Hospital de Especialidades Manuel Ávila Camacho, IMSS, between April 3rd and October 17th, 2020 with a confirmed diagnosis of Covid-19 by RT-PCR. The data included demographics, socioeconomic data, level of education, clinical data of the entire admission, and the outcome at the moment of discharge.
Results.
All patients had pneumonia. The median age was 55 years, 91% had at least one comorbidity and the most frequent were: overweight/obesity (78.2%), hypertension (35.2%) and diabetes mellitus (20.5%). Fever, malaise and cough were the most common presenting symptoms. D-dimer, fibrinogen, glucose calcium, blood gases and organ damage markers were the most frequent laboratory test values altered. Around 35.1% of patients required invasive ventilation. The overall mortality was 31% and the poorest outcome was seen in those mechanically ventilated outside ICU.
Conclusion.
Overweight, obesity, hypertension and diabetes mellitus were the most common comorbid condtions. Fever, malaise and cough were the most common initial symptoms. Monocytopenia rather than lymphopenia was seen in this cohort. The highest mortality rate was seen in patients on mechanical ventilation outside UCI.
Key words: Covid-19; hospitalization; viral pneumonia; mortality; cohort studies; retrospective studies.
# Introduction {.unnumbered}
Covid-19 is a disease caused by a novel virus named *severe acute respiratory syndrome coronavirus 2* (SARS-Cov-2). It belongs to the subgenus Sarbecovirus, genus Betacoronavirus, subfamily Orthocoronavirinae and family Coronaviridae. The periphery of coronaviruses resembles the solar corona in negative-stained electron microscopy, hence its name [@artika2020]. The disease was first identified in the city of Wuhan, China, and has spread globally, presenting a severe threat to global health. The clinical presentation is heterogeneous, ranging from an asymptomatic disease to a life-threatening condition with respiratory failure. At present, specific therapies are lacking. In Mexico, the first cases were reported in February 2020, with pandemic disease levels peaking during July and August, starting to decrease during the following months. However, as of January 2020, the Mexican health system faced a second wave with more lethality than the first one . During this time *The Mexican Institute of Social Security* (IMSS, after the initials in Spanish), carried the biggest burden of public health care and the highest mortality of patients hospitalized with Covid-19 [@sancheztalanquer2020].
Because the mortality of hospitalized patients with this disease varies from country to country, it is important for the clinician to have data describing the features and behavior of this disease in different clinical settings. The aim of this study is to describe the demographics, presenting characterstics, clinical course and outcomes of hospitalized patients from a Mexican hospital dedicated to patients affected with Covid-19.
# Methods {.unnumbered}
```{r muestra, message=FALSE, warning=FALSE}
#load('Rdata/bdcoving.rda')
bdcoving2 <- bdcoving %>%
filter(motivoegre %in% c(2,3), rescov1 == 1) %>%
select(edad, fecha, imc)
totmuestra <- dim(bdcoving2)[1]
fechaini <- min(bdcoving2$fecha)
fechafin <- max(bdcoving2$fecha)
# covpos <- sum(bdcoving$rescov1 == 1)
# noegre <- sum(!(bdcoving$motivoegre %in% c(2,3)))
#totmuestra <- covpos - noegre
```
This is a retrospective cohort study conducted at the *Hospital de Especialidades de Puebla, IMSS*, Mexico. This site is a 315 bed multi-specialty hospital and a referral center for patients from the states of Puebla, Tlaxcala and Oaxaca. In March 2020 it was converted to a hybrid Covid-19 hospital. Data was collected from the charts of patients admitted between `r month.name[month(fechaini)]` `r day(fechaini)`^rd^ and `r month.name[month(fechafin)]` `r day(fechafin)`^th^ `r year(fechafin)` with a clinical diagnosis of Covid-19 and a positive SARS-Cov-2 RT-PCR nasopharyngeal swab. Patients transferred to other facilities were not included. This study was approved by the *Hospital de Especialidades* institutional review board (No. R-2020-785-126) as a minimal-risk research and informed consent was waived.
The data gathered included demographics, baseline comorbidities, medications, vital signs on admission and initial laboratory test. Prescribed medications and laboratory results were also analyzed for the duration of the admission. Finally, pertinent clinical outcomes were recorded. The Systematic COronary Risk Evaluation (SCORE) index was calculated, which gives the risk of developing fatal cardiovascular disease at 10 years. This score is endorsed by the European Society of Cardiology for high-risk patients and was used because of the high prevalence of cardiovascular risk factors in the Mexican population. The score considers age from 40 years, gender, systolic blood pressure, smoking, and total cholesterol level [@conroy2003a; @versteylen2011]. Socioeconomic level was classified in in high, medium-high, medium-low and low. For this, an *ad-hoc* scale was used obtaining a profile of the household which considered the educational level, current job position and the company where he or she works.
The statistical analysis was performed with the R programming language [@rcoreteam2020] and RStudio [@rstudioteam2021], with the packages **tidyverse** [@wickham2019] and **lubridate** [@grolemund2011]. When appropriate, 95% confidence intervals were calculated with the **binom** package [@dorai-raj2014]. Unless otherwise stated, the results are reported as the median, the inter-quartile range (IQR), and the range (minum-maximum) of the values.
# Results {.unnumbered}
```{r vartexto}
porsexo <- bdcoving%>%
filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
select(sexo)%>%
pivot_longer(sexo, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
na.omit %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = sum(n))
ocuptexto <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1, ocupacion != 7)%>%
select(ocupacion)%>%
mutate(ocupacion = case_when(
ocupacion == 1 ~ 'Personal sanitario',
ocupacion == 2 ~ 'Trabajo de oficina',
ocupacion == 3 ~ 'Trabajo al aire libre',
ocupacion == 4 ~ 'Trabajo en espacio público',
ocupacion == 5 ~ 'Trabajo en casa',
ocupacion == 6 ~ 'No trabaja'
))%>%
pivot_longer(ocupacion, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
na.omit %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = sum(n))
escoltexto <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1)%>%
select(escolaridad)%>%
mutate(escolaridad = case_when(
escolaridad == 1 ~ 'Analfabeta',
escolaridad == 2 ~ 'Primaria',
escolaridad == 3 ~ 'Secundaria',
escolaridad == 4 ~ 'Bachillerato',
escolaridad == 5 ~ 'Licenciatura',
escolaridad == 6 ~ 'Posgrado'
))%>%
rename( Escolaridad = escolaridad) %>%
na.omit %>%
pivot_longer(Escolaridad, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = sum(n))
nivsoctexto <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1)%>%
select(nivsoc)%>%
mutate(nivsoc = case_when(
nivsoc %in% c(1,2) ~ 'Bajo, medio-bajo',
nivsoc %in% c(3,4) ~ 'Medio-alto, alto'
))%>%
na.omit %>%
pivot_longer(nivsoc, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = sum(n))
```
## Patient characteristics. {.unnumbered}
A total of `r totmuestra` cases were included in the study. Table \@ref(tab:tbvargen) shows the somatometric and sociodemographic variables studied. The median age was `r median(bdcoving2$edad, na.rm = TRUE)` years, 50% of patients were between `r quantile(bdcoving2$edad, 0.25, na.rm = TRUE)` and `r quantile(bdcoving2$edad, 0.75, na.rm = TRUE)` years old. The median of body mass index (BMI) was `r round(median(bdcoving2$imc, na.rm = TRUE),1)` kg/m^2^ with an interquartile range (IQR) between `r round(quantile(bdcoving2$imc, 0.25, na.rm = TRUE),1)` and `r round(quantile(bdcoving2$imc, 0.75, na.rm = TRUE),1)`; `r porsexo$frec[2]`% were male. A total of `r ocuptexto$frec[2]`% were health care workers, while `r ocuptexto$frec[6]`% worked in a public space. Patients who were illiterate comprised `r escoltexto$frec[1]`% of the sample, while only `r escoltexto$frec[4]`% had postgraduate studies. A total of `r nivsoctexto$frec[1]`% had a socioeconomic level considered as medium-low or low.
```{r bdvarnum, include=TRUE, eval=TRUE}
roundcond <- function(x, dec = 1){
#browser()
ifelse(trunc(x) == 0,
ifelse(x%%1 < 0.001,
format(round(x),
trim = TRUE),
format(round(x,2),
nsmall = 2,
big.mark = ',',
trim = TRUE)),
ifelse(x%%1 < 0.001,
format(round(x),
nsmall = 0,
big.mark = ',',
trim = TRUE),
format(round(x, dec),
nsmall = dec,
big.mark = ',',
trim = TRUE)) )
}
bdvarnumglob <- bdcoving %>%filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
select(edad, peso, talla, imc)%>%
summarise(across(everything(), list(
faltan = ~sum(is.na(.x)),
mediana = ~ roundcond(median(.x, na.rm = TRUE)),
p25 = ~ roundcond(quantile(.x, 0.25, na.rm = TRUE)),
p75 = ~ roundcond(quantile(.x, 0.75, na.rm = TRUE)),
min = ~ roundcond(min(.x, na.rm = TRUE)),
max = ~ roundcond(max(.x, na.rm = TRUE))
)))%>%
pivot_longer(cols = everything(),
names_sep = '_',
names_to = c('variable', '.value'))%>%
mutate(p25 = ifelse(variable == 'imc', as.character(round(as.numeric(p25), 1)), p25),
p75 = ifelse(variable == 'imc', as.character(round(as.numeric(p75), 1)), p75),
min = ifelse(variable == 'imc', as.character(round(as.numeric(min), 1)), min),
max = ifelse(variable == 'imc', as.character(round(as.numeric(max), 1)), max)) %>%
unite('iqr', c(p25, p75), sep = ' - ') %>%
unite('range',c(min, max), sep = ' - ' ) %>%
mutate(variable = case_when(
variable == 'edad' ~ 'Age',
variable == 'peso' ~ 'Weight',
variable == 'talla' ~ 'Height',
variable == 'imc' ~ 'BMI'
)) %>%
mutate(value = paste0(mediana, ', ', '(', iqr, ') ', '[', range, ']')) %>%
rename(Valor = variable) %>%
select(Valor, value, faltan)
```
```{r dbvarsocdem, include=TRUE}
frecsexo <- bdcoving%>%
filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
select(sexo)%>%
mutate(sexo = factor(sexo, labels = c(' Female',' Male'))) %>%
pivot_longer(sexo, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
na.omit %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = NA)%>%
arrange(frec)%>%
rename(Variable = apps,Valor = valor , Cantidad = n, Porcentaje = frec, Total = total)%>%
mutate (value = paste0(Cantidad, ' (', Porcentaje, ')')) %>%
select( Valor, value, Total)
frecocup <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1, ocupacion != 7)%>%
select(ocupacion)%>%
mutate(ocupacion = case_when(
ocupacion == 1 ~ ' Health care worker',
ocupacion == 2 ~ ' Office job',
ocupacion == 3 ~ ' Outdoor work',
ocupacion == 4 ~ ' Work in a public area',
ocupacion == 5 ~ ' Work at home',
ocupacion == 6 ~ ' Unemployed'
))%>%
pivot_longer(ocupacion, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
na.omit %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = NA)%>%
arrange(frec)%>%
rename(Variable = apps,Valor = valor , Cantidad = n, Porcentaje = frec, Total = total)%>%
mutate (value = paste0(Cantidad, ' (', Porcentaje, ')')) %>%
select(Valor, value, Total)
frecescol <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1)%>%
select(escolaridad)%>%
mutate(escolaridad = case_when(
escolaridad == 1 ~ ' Illiteracy',
escolaridad == 2 ~ ' Primary school',
escolaridad == 3 ~ ' Junior high school',
escolaridad == 4 ~ ' High school',
escolaridad == 5 ~ ' College',
escolaridad == 6 ~ ' Postgraduate studies'
))%>%
rename( Escolaridad = escolaridad) %>%
na.omit %>%
pivot_longer(Escolaridad, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = NA)%>%
mutate(valor = factor(valor, levels = c(' Illiteracy',' Primary school', ' Junior high school', ' High school', ' College', ' Postgraduate studies'))) %>%
arrange(valor)%>%
rename(Variable = apps,Valor = valor , Cantidad = n, Porcentaje = frec, Total = total)%>%
mutate (value = paste0(Cantidad, ' (', Porcentaje, ')')) %>%
select(Valor, value, Total)
#Ahora nivel socioeconómico
frecnivsoc <- bdcoving%>%
filter(motivoegre %in% c(2,3),rescov1 == 1)%>%
select(nivsoc)%>%
mutate(nivsoc = case_when(
nivsoc == 1 ~ ' Low',
nivsoc == 2 ~ ' Medium-low',
nivsoc == 3 ~ ' Medium-high',
nivsoc == 4 ~ ' High'
))%>%
na.omit %>%
pivot_longer(nivsoc, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1), total = NA)%>%
mutate(valor = factor(valor, levels = c(' Low',' Medium-low',' Medium-high',' High'))) %>% #para que se ordenen de bajo a alto
arrange(valor)%>%
rename(Variable = apps,Valor = valor , Cantidad = n, Porcentaje = frec, Total = total)%>%
mutate (value = paste0(Cantidad, ' (', Porcentaje, ')')) %>%
select(Valor, value, Total)
#otra manera de unir, para tener una sóla tabla de las numéricas y categóricas.
bdsexo <- data.frame(Valor = 'Gender', value = '', Total = sum(is.na(bdcoving$sexo)))
bdocup <- data.frame(Valor = 'Occupation', value = '', Total = sum(is.na(bdcoving$ocupacion)) )
bdescol <- data.frame(Valor = 'Schooling', value = '', Total = sum(is.na(bdcoving$escolaridad)) )
bdnivsoc <- data.frame(Valor = 'Socioeconomic level', value = '', Total = sum(is.na(bdcoving$nivsoc)))
dbvarsocdemglob <- bind_rows(bdsexo, frecsexo,
bdocup, frecocup,
bdescol, frecescol,
bdnivsoc, frecnivsoc) %>%
mutate(faltan = Total) %>%
select(-c(Variable, Total))
```
```{r ggedad, fig.cap= 'Distribution of the age in the study group'}
# bdcoving %>%
# ggplot(aes(x = edad)) +
# theme_classic() +
# labs(x = 'Age in years',
# y = 'Number of patients') +
# geom_histogram(binwidth = 10, color = 'darkolivegreen4',
# fill = 'darkolivegreen2')
```
```{r dbvargen}
bdsom <- data.frame(Valor = 'Somatic variables:',
value = 'Median, (IQR), [range]',
faltan = NA)
bdsocd <- data.frame(Valor = 'Sociodemographic variables:',
value = 'No. (%)',
faltan = NA)
bdvargen <- bind_rows(bdsom, bdvarnumglob, bdsocd, dbvarsocdemglob)
```
```{r tbvargen, include=TRUE}
flextable(bdvargen) %>%
set_caption(caption = 'Baseline features of the study patients',
style = 'Table Caption') %>%
set_header_labels(Valor = 'Variable',
value = 'Value',
faltan = 'Missing cases') %>%
#align(j = 2:3, align = 'center', part = 'all') %>%
align(align = 'center', part = 'header') %>%
align(j = 3, align = 'center', part = 'body') %>%
align(i = c(1,6), align = 'center') %>%
bold(part = 'header') %>%
bold(i = c(1,6)) %>%
italic(i = c(1,6)) %>%
bold( i = c(7,10, 17,24), j = 1) %>%
#fontsize(i = c(1,6), j = 1, size = 12) %>%
valign(j = 3, valign = 'top', part = 'body') %>%
set_table_properties(width = 0.6, layout = 'autofit')
```
```{r bdcomorb}
appeng1 <- read_lines('bases-originales/nomappeng.txt')
##creamos sobrepeso y obesidad (app_18, app_19)
bdcoving <- bdcoving %>%
mutate(app_18 = as.factor(ifelse(imc >= 25 & imc < 30, 1, 2)),
app_19 = as.factor(ifelse(imc >= 30, 1, 2)))
#añado has, porque en la base de excel está separada del conjunto de antecedentes personales patológicos (app),
appeng <- c('Hypertension', appeng1, 'Overweight', 'Obesity')
nomappord <- bdcoving%>%select(starts_with('app'))%>%names
#Frecuencia global de antecedentes
frecapp <- bdcoving%>%
filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
select(starts_with('app')) %>%
mutate(across(everything(), ~ ifelse(is.na(.x), 2, .x))) %>%
pivot_longer(starts_with('app'), names_to = 'apps', values_to = 'valor')%>%
group_by(apps, valor) %>%
mutate(apps = factor(apps, levels = nomappord, labels = appeng),
valor = factor(valor, levels = c(1,2), labels = c('Si', 'No')))%>%
summarise(n = n())%>%
mutate(frec = round(n/sum(n)*100, 1),
total = sum(n))%>%
filter(valor == 'Si')%>%
arrange(desc(frec))
porcgordos <- round(((frecapp$n[1] + frecapp$n[2])/totmuestra)*100,1)
#Número de comorbilidades asociadas
totapp <- length(nomappord) -1
facanum <- function(x){
as.numeric(as.character(x))
}
numappglob <- bdcoving %>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
select(-app_7) %>% #medicación empleada no es una comorbilidad
rowwise()%>%
mutate(across(starts_with('app'), facanum) ) %>%
mutate(numapp = (totapp - sum(is.na(c_across(starts_with('app')))))*2 - sum(c_across(starts_with('app')),
na.rm = TRUE))%>%
select(motivoegre, numapp)%>%
ungroup %>%
mutate(numapp = factor(numapp)) %>%
group_by(numapp)%>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 1),
total = sum(n),
validos = sum(n)- sum(is.na(numapp)))%>%
select(numapp, n, frec)
#score index
score <- bdcoving%>%
filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
select(score) %>%
pull
summScore <- summary(score)
```
A total of `r frecapp$n[2]` (`r round(frecapp$frec[2])`%) patients were overweight (BMI more or equal to 25 and less than 30), while `r frecapp$n[1]` (`r round(frecapp$frec[1],1)`%) had obesity (BMI 30 or more). It is worth noting that `r porcgordos`% of patients were overweight or obese. Hypertension was present in `r frecapp$n[3]` patients (`r round(frecapp$frec[3],1)`%). Diabetes mellitus was present in `r frecapp$n[5]` cases (`r round(frecapp$frec[5],1)`%). A total of `r frecapp$n[4]` (`r round(frecapp$frec[4],1)`%) reported chronic medication use. Only `r frecapp$n[18]` (`r round(frecapp$frec[18],1)`%) had a chronic lung disease, and 67 patients (10.8%) were current smokers. The median of the SCORE index was `r summScore[3]`, IQR (`r paste0(summScore[2],'-',summScore[5])`). The maximum number of associated comorbidities in an individual was 8 (one patient); only `r numappglob$n[1]` (`r round(numappglob$frec[1])`%) had no comorbidities; a total of `r sum(numappglob$n[2:4])` (`r round(sum(numappglob$frec[2:4]),1)`%) had either 1, 2 or 3 associated comorbidities. Details of the comorbidities reported are summarised in table 1 and figure 1 of the Supplementary material.
```{r tbapp}
frecapp %>%
mutate(numporc = paste0(n, ' (', frec, ')')) %>%
select(apps, numporc) %>%
filter(apps != 'Use of medication') %>%
flextable() %>%
# set_caption(caption = 'Baseline comorbidities.',
# style = 'Table Caption') %>%
set_header_labels(apps = 'Comorbidity',
numporc = 'No. (%)') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
set_table_properties(width = 0.6, layout = 'autofit')
```
```{r tbnumapp}
# numappglob %>%
# mutate(numporc = paste0(n, ' (', frec, ')' )) %>%
# select(numapp, numporc) %>%
# flextable() %>%
# set_caption(caption = 'Number of associated comorbidities.',
# style = 'Table Caption') %>%
# set_header_labels(numapp = 'Number of comorbidities',
# numporc = 'No. (%)') %>%
# align(align = 'center', part = 'header') %>%
# bold(part = 'header') %>%
# set_table_properties(width = 0.6, layout = 'autofit')
```
```{r fnumapp}
# , fig.cap='Number of associated comorbidities per patient.'
numappglob %>%
ggplot(aes(x = numapp, y = frec)) +
labs(x = 'Number of associated comorbidities',
y = 'Percentage of patients') +
geom_col(color = 'darkolivegreen4',
fill = 'darkolivegreen2' )
```
```{r bdstxprev, results='hide'}
txpreveng <- read_lines('bases-originales/nomtxpreveng.txt')
nomtxprevord <- bdcoving%>%select(starts_with('txprev'))%>%names
# solo emplearemos los pacientes con resultado de la prueba Covid
#Frecuencia global de tratamientos previos
frectxprev <- bdcoving%>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
select(starts_with('txprev')) %>%
pivot_longer(starts_with('txprev'), names_to = 'txprevs', values_to = 'valor')%>%
group_by(txprevs, valor) %>%
na.omit %>%
mutate(txprevs = factor(txprevs, levels = nomtxprevord, labels = txpreveng),
valor = factor(valor, levels = c(1,2), labels = c('Si', 'No'))) %>%
summarise(n = n())%>%
mutate(frec = round(n/sum(n)*100, 2), total = sum(n)) %>%
filter(valor == 'Si')%>%
select(txprevs, n, frec, total ) %>%
arrange(desc(frec))
#Cantidad de tratamientosacumulados por persona:
facanum <- function(x){
as.numeric(as.character(x))
}
numtxprevglob <- bdcoving %>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
mutate(across(starts_with('txprev'), facanum) ) %>%
rowwise()%>%
mutate(numtxprev = (length(nomtxprevord)-sum(is.na(c_across(starts_with('txprev')))))*2 - sum(c_across(starts_with('txprev')), na.rm = TRUE))%>%
select(motivoegre, numtxprev) %>%
ungroup %>%
mutate(numtxprev = factor(numtxprev))%>%
group_by(numtxprev)%>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 2),
total = sum(n),
validos = sum(n)- sum(is.na(numtxprev)))%>%
select(numtxprev, n, frec, validos)
dosomastx <- round(sum(numtxprevglob$frec[-(1:2)]),1)
polifar <- round(sum(numtxprevglob$frec[6:11]),1)
statntxprev <- bdcoving %>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
mutate(across(starts_with('txprev'), facanum) ) %>%
rowwise()%>%
mutate(numtxprev = (length(nomtxprevord)-sum(is.na(c_across(starts_with('txprev')))))*2 - sum(c_across(starts_with('txprev')), na.rm = TRUE))%>%
select(numtxprev) %>%
ungroup() %>%
summarise(mediana = median(numtxprev, na.rm = TRUE ),
p25 = round(quantile(numtxprev, 0.25, na.rm = TRUE),1),
p75 = round(quantile(numtxprev, 0.75, na.rm = TRUE),1))
```
The most common drugs prescribed prior to admission were acetaminophen (43.13%) and antibiotics (34.25%). A total of `r round(numtxprevglob$frec[1], 1)`% of the patients had no drugs prescribed prior to admission for Covid-19. In contrast, `r dosomastx`% of admitted patients were taking 2 or more medications. The median of number of medications employed was `r statntxprev$mediana`, IQR of `r statntxprev$p25` - `r statntxprev$p75`, polypharmacy (use of 5 or more drugs in the same individual) was present in `r polifar`% of the patients (see table 2 and figure 2 of the supplementary material).
```{r tbtxprev}
frectxprev %>%
select(-total) %>%
mutate(numporc = paste0(n, ' (', frec, ')' )) %>%
select(txprevs, numporc) %>%
flextable() %>%
# set_caption(caption = 'Drugs received before admission.',
# style = 'Table Caption') %>%
set_header_labels(txprevs = 'Medication',
numporc = 'No. (%)') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
set_table_properties(width = 0.6, layout = 'autofit')
```
```{r fnumtxprev}
# , fig.cap='Number of medications used before admission to the hospital.'
numtxprevglob %>%
ggplot(aes(x = numtxprev, y = frec)) +
labs(x = 'Number of medications received',
y = 'Percentage of patients') +
geom_col(color = 'darkolivegreen4',
fill = 'darkolivegreen2' )
```
## Clinical presentation {.unnumbered}
```{r bdvarclin}
#Base para sÃÂntomas.
# totmuestra <- bdcoving %>%
# filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
# select(sintoma1) %>%
# count %>%
# pull
bdsintprintxt <- bdcoving %>%
filter(motivoegre %in% c(2,3), rescov1 == 1) %>%
select(sintoma1) %>%
mutate(sintoma1 = as.character(sintoma1)) %>%
mutate(sintoma1 = ifelse(sintoma1 == '15', NA, sintoma1 )) %>%
mutate(sintoma1 = ifelse(sintoma1 == '11, 12', '11', sintoma1)) %>%
na.omit %>%
mutate(sintoma1 = case_when(sintoma1 == '1' ~ 'Cough',
sintoma1 == '2' ~ 'Fever',
sintoma1 == '3' ~ 'Headache',
sintoma1 == '4' ~ 'Anosmia',
sintoma1 == '5' ~ 'Malaise',
sintoma1 == '6' ~ 'Dizziness',
sintoma1 == '7' ~ 'Muscular weakness',
sintoma1 == '8' ~ 'Diarrhea',
sintoma1 == '9' ~ 'Ageusia',
sintoma1 == '10' ~ 'Rash',
sintoma1 == '11' ~ 'Dyspnea',
sintoma1 == '12' ~ 'Chest pain',
sintoma1 == '13' ~ 'Incapability to move',
sintoma1 == '14' ~ 'Sore throat') ) %>%
pivot_longer(sintoma1, names_to = 'apps', values_to = 'valor') %>%
group_by(apps, valor) %>%
summarise(n = n()) %>%
mutate(apps = 'Symptoms',
frec = round(n/sum(n)*100, 2), total = sum(n)) %>%
arrange(desc(frec))
bdsintprin <- bdsintprintxt %>%
ungroup %>%
mutate( value = paste0(n, ' (', frec, ')'),
total = as.character(total)) %>%
rename(variable = apps,
faltan = total) %>%
select(valor, value, faltan)
#Base para variables numéricas.
varclinpres <- c('fc', 'fr', 'temp', 'tas', 'tad', 'sato2', 'sato2sin', 'ltso2', 'score')
bdvarclintxt <- bdcoving %>%
filter(motivoegre %in% c(2,3), rescov1 == 1)%>%
select(all_of(varclinpres)) %>%
mutate(sato2tot = ifelse(is.na(sato2sin), sato2,
ifelse(is.na(sato2), sato2sin, sato2)),
relsatlo2 = ltso2/sato2tot *100) %>%
select(- c(sato2, ltso2, sato2sin, relsatlo2)) %>%
summarise(across(everything(), list(
faltan = ~sum(is.na(.x)),
mediana = ~ roundcond(median(.x, na.rm = TRUE)),
p25 = ~ roundcond(quantile(.x, 0.25, na.rm = TRUE)),
p75 = ~ roundcond(quantile(.x, 0.75, na.rm = TRUE)),
min = ~ roundcond(min(.x, na.rm = TRUE)),
max = ~ roundcond(max(.x, na.rm = TRUE))
)))%>%
pivot_longer(cols = everything(),
names_sep = '_',
names_to = c('valor', '.value'))%>%
unite('iqr', c(p25, p75), sep = ' - ') %>%
unite('range',c(min, max), sep = ' - ' ) %>%
mutate(valor = case_when(
valor == 'fc' ~ 'Heart rate',
valor == 'fr' ~ 'Respiratory rate',
valor == 'temp' ~ 'Temperature',
valor == 'tas' ~ 'Systolic pressure',
valor == 'tad' ~ 'Diastolic pressure',
valor == 'sato2tot' ~ 'Oxygen saturation',
valor == 'score' ~ 'Severity score'),
variable = 'Vitals')
bdvarclin <- bdvarclintxt %>%
mutate(value = paste0(mediana, ', ', '(', iqr, ') ', '[', range, ']'),
faltan = as.character(faltan)) %>%
select(valor, value, faltan)
```
All patients were admitted with clinical diagnosis of Covid-19 pneumonia and an abnormal CAT scan. The first symptom reported and vitals at the moment of admission are summarized in table \@ref(tab:tbvarclin). Fever, malaise and cough were the most frequent initial symptoms. Dyspnea was reported as the first symptom in `r bdsintprintxt$n[4]` patients (`r round(bdsintprintxt$frec[4], 1)`%).
```{r tbvarclin}
bdsintomas <- data.frame(valor = 'First symptom',
value = 'No. (%)',
faltan = as.character(totmuestra - bdsintprintxt$total[1]))
bdvitales <- data.frame(valor = 'Vitals',
value = 'Median, (IQR) [range]',
faltan = '')
bdsintprin$faltan <- NA
bdsintomas %>% bind_rows(bdsintprin,bdvitales, bdvarclin) %>%
flextable() %>%
set_caption(caption = 'Clinical features at the moment of hospital admission',
style = 'Table Caption') %>%
set_header_labels(valor = 'Variable',
value = 'Value',
faltan = 'Missing values') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
bold(i = c(1, 14), j = c(1,2)) %>%
italic(i = c(1, 14), j = c(1,2)) %>%
align(j = 3, align = 'center', part = 'body') %>%
set_table_properties(width = 0.6, layout = 'autofit')
```
```{r bdlabos}
#Base de laboratorios
#load('Rdata/labosvalref.rda')
nomvar <- bdcoving %>% select(where(is.numeric)) %>% names
nomlabos <- nomvar[-c(1:13, 39:40, 51:55)]
bdlabosglobtxt <- bdcoving %>%filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
select(all_of(nomlabos))%>%
mutate(plaq = plaq/1000) %>%
summarise(across(everything(), list(
hechos = ~sum(!is.na(.x)),
mediana = ~ round(median(.x, na.rm = TRUE),2),
p25 = ~ roundcond(quantile(.x, 0.25, na.rm = TRUE)),
p75 = ~ roundcond(quantile(.x, 0.75, na.rm = TRUE)),
min = ~ roundcond(min(.x, na.rm = TRUE)),
max = ~ roundcond(max(.x, na.rm = TRUE))
)))%>%
pivot_longer(cols = everything(),
names_sep = '_',
names_to = c('valor', '.value'))%>%
unite('iqr', c(p25, p75), sep = '-') %>%
unite('range',c(min, max), sep = '-' ) %>%
left_join(labosvalref, by = 'valor')
# Para que en la tabla final aparezcan las medianas que están fuera del rango de normalidad:
bdmedianalabos <- bdlabosglobtxt %>%
mutate(refmin = as.numeric(str_sub(ref, start = 1, end = str_locate(ref, '-')[,1]-1)),
refmax = as.numeric(str_sub(ref, start = str_locate(ref, '-')[,1]+1 )) ) %>%
rowwise() %>%
mutate(fuera = if_else(between(mediana, refmin, refmax), '', '*')) %>%
select(valor, fuera)
bdlabosglobtxt <- bdlabosglobtxt %>%
left_join(bdmedianalabos, by = 'valor')
ferrit <- bdlabosglobtxt %>%
filter(valor == 'ferrit') %>%
select(hechos) %>%
pull
vsg <- bdlabosglobtxt %>%
filter(valor == 'vsg') %>%
select(hechos) %>%
pull
```
Laboratory values on admission are in table \@ref(tab:tblabos). Most patients had a complete blood count, D-dimer, arterial blood gases and a basic metabolic panel ordered. The organ damage markers most commonly employed were aspartate aminotransferase (AST), alanine aminotransferase (ALT) and lactate dehydrogenase (LDH). Inflammation markers such as ferritin and erythrocyte sedimentation rate (ESR) were used in only `r ferrit` and `r vsg` patients respectively. Of note, the medians of monocyte, neutrophils, lymphocytes, d-dimer, fibrinogen, PaO~2~, PaCO~2~, HCO~3~, glucose, calcium, AST, ALT, LDH, gamma-glutamyltranferase, ferritin and ESR were out of the normal range.
```{r tblabos}
#Hay que repartir las bases de acuerdo con el tipo, para darle más orden
bdlabosglob <- bdlabosglobtxt %>%
mutate(value = paste0(roundcond(mediana,1), '; ', '(', iqr, ') ', '[', range, ']'),
hechos = as.character(hechos)) %>%
select(labtest, hechos, value, ref2, tipo, fuera)
bdbh <- data.frame(labtest = 'Hemogram',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Hemogram'),])
bdmetpanel <- data.frame(labtest = 'Metabolic panel',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Metabolic panel'),])
bdorgdam <- data.frame(labtest = 'Organ damage markers',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Organ damage marker'),])
bdinflam <- data.frame(labtest = 'Inflammation markers',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Inflammation marker'),])
bdgasom <- data.frame(labtest = 'Arterial blood gases',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Gasometry'),])
bdcoag <- data.frame(labtest = 'Coagulation tests',
hechos = '',
value = '',
ref2 = '',
tipo = '',
fuera = '') %>%
bind_rows(bdlabosglob[which(bdlabosglob$tipo == 'Coagulation'),])
# as_grouped_data(groups = c('tipo')) %>% Añade una columna, no conviene
bind_rows(bdbh, bdcoag, bdgasom, bdmetpanel, bdorgdam, bdinflam ) %>%
select(labtest, hechos, value, ref2, fuera) %>%
flextable(col_keys = c('labtest', 'hechos', 'value', 'ref2')) %>%
set_caption(caption = 'Laboratory tests values on admission.',
style = 'Table Caption') %>%
set_header_labels(labtest = 'Test',
hechos = 'No.',
value = 'Values',
ref2 = 'reference ranges') %>%
align(align = 'center', part = 'header') %>%
bold(part = 'header') %>%
flextable::footnote(j = 3,
part = 'header',
value = as_paragraph('Median, (IQR), [range]. The values where the median is out of the reference range are highlighted.'),
ref_symbols = 'a') %>%
bold(i = c(1, 11, 15, 20, 29, 39), j = 1) %>%
color(j = 3, i = ~ fuera == '*', color = 'red') %>%
fontsize(part = 'body', size = 10) %>%
set_table_properties( layout = c('autofit'))
```
## Clinical measures during hospitalization {.unnumbered}
```{r bdstxhosp}
txhospeng <- read_lines('bases-originales/nomtxhospeng.txt')
nomtxhospord <- bdcoving%>%select(starts_with('txhosp'))%>%names
frectxhosptxt <- bdcoving%>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
select(starts_with('txhosp')) %>%
pivot_longer(starts_with('txhosp'), names_to = 'txhosps', values_to = 'valor')%>%
group_by(txhosps, valor) %>%
na.omit %>%
mutate(txhosps = factor(txhosps, levels = nomtxhospord, labels = txhospeng),
valor = factor(valor, levels = c(1,2), labels = c('Si', 'No')))%>%
summarise(n = n())%>%
mutate(frec = round(n/sum(n)*100, 2), total = sum(n))%>%filter(valor == 'Si')%>%
arrange(desc(frec))
numtxhosp <- dim(frectxhosptxt)[1]
#facanum está codificado en tbstxprev
numtxhospglob <- bdcoving %>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
mutate(across(starts_with('txhosp'), facanum) ) %>%
rowwise()%>%
mutate(numtxhosp = (length(nomtxhospord)-sum(is.na(c_across(starts_with('txhosp')))))*2 - sum(c_across(starts_with('txhosp')), na.rm = TRUE))%>%
select(motivoegre, numtxhosp) %>%
ungroup %>%
group_by(numtxhosp)%>%
summarise(n = n()) %>%
mutate(frec = round(n/sum(n)*100, 2),
total = sum(n),
validos = sum(n)- sum(is.na(numtxhosp)))%>%
select(numtxhosp, n, frec, validos)
dosomastxh <- round(sum(numtxhospglob$frec[-(1:2)]),1)
polifarhosp <- round(sum(numtxhospglob$frec[6:14]),1)
statntxhosp <- bdcoving %>%
filter(motivoegre %in% c(2,3) & rescov1 == 1)%>%
mutate(across(starts_with('txhosp'), facanum) ) %>%
rowwise()%>%
mutate(numtxhosp = (length(nomtxhospord)-sum(is.na(c_across(starts_with('txhosp')))))*2 - sum(c_across(starts_with('txhosp')), na.rm = TRUE))%>%
select(numtxhosp) %>%
ungroup() %>%
summarise(mediana = median(numtxhosp, na.rm = TRUE ),
p25 = round(quantile(numtxhosp, 0.25, na.rm = TRUE),1),
p75 = round(quantile(numtxhosp, 0.75, na.rm = TRUE),1))
```
```{r dblabhosp, results='hide'}
#Código para obtener bdlabdiario, que es un resumen de laboratorios durante la estancia de los pacientes
# load('Rdata/bdcovdiario.rda')
#No incluimos sato2, sato2sin y ltso2
nomlabdiario <- bdcovdiario %>% select(c(21:45, 53:56, 58:61,75:76)) %>% names
nomlabdiario
#Funciones para resumir los labos de cada paciente
mymin <- function(x){
round(ifelse(sum(is.na(x)) == length(x),NA, min(x, na.rm = TRUE)), 2)
}
mymax <- function(x){
round(ifelse(all(is.na(x)),NA, max(x, na.rm = TRUE)), 2)
}
mydif <- function(x){
mimin <- ifelse(length(x)> 1,last(na.omit(x)) - first(na.omit(x)), 0)
mimin <- ifelse(all(is.na(x)), NA, mimin)
return(round(mimin, 2))
}
mydifpor <- function(x){
primero = first(na.omit(x))
dif <- ifelse(length(x)> 1,last(na.omit(x)) - first(na.omit(x)), 0)
porc <- ifelse(primero == 0, dif, dif*100/primero)
return(round(porc, 2))
}
mylast <- function(x){
last(na.omit(x))
}
bdlabos <- bdcovdiario %>%
group_by(nss) %>%arrange(fechaest)%>%
mutate(sato2tot = ifelse(is.na(sato2sin), sato2,
ifelse(is.na(sato2), sato2sin, sato2)),
plaq = plaq/1000) %>%
select(- c(sato2, ltso2, sato2sin)) %>%
summarise(numestudios = n(), across(all_of(c(nomlabdiario, 'sato2tot')),
list(prom = ~ round(mean(.x, na.rm = TRUE),2),
min = ~mymin(.x),
max = ~mymax(.x),
dif = ~mydif(.x),
difpor = ~mydifpor(.x),
ultimo = ~ mylast(.x) )))
bdporlabos <- bdlabos %>%
pivot_longer(
cols = -c(nss, numestudios),
names_to = c('analito', '.value'),
names_pattern = '(\\w+)_(\\w+)' #También funciona '(.*)_(.*)
)
#Hacemos el resumen por laboratorio
bdlabosresum <- bdporlabos %>%
select(analito, numestudios, prom, min, max, ultimo)%>%
group_by(analito) %>%
summarise(across(everything(), list(
faltan = ~sum(is.na(.x)),
mediana = ~ round(median(.x, na.rm = TRUE), 2),
p25 = ~ roundcond(quantile(.x, 0.25, na.rm = TRUE)),
p75 = ~ roundcond(quantile(.x, 0.75, na.rm = TRUE)),
min = ~ roundcond(min(.x, na.rm = TRUE),2),
max = ~ roundcond(max(.x, na.rm = TRUE))
)))
#pasamos al inglés, usando el objeto labosvalref.rda
# load('Rdata/labosvalref.rda')
# le cambiamos el nombre a analito y pegamos labosvalref.rda
bdlabosresum <- bdlabosresum %>%
rename(valor = analito) %>%
left_join(labosvalref, by = 'valor')
# Para que en la tabla final aparezcan las medianas que están fuera del rango de normalidad:
bdmedianalabosdi <- bdlabosresum %>%
mutate(refmin = as.numeric(str_sub(ref, start = 1, end = str_locate(ref, '-')[,1]-1)),
refmax = as.numeric(str_sub(ref, start = str_locate(ref, '-')[,1]+1 )) ) %>%
rowwise() %>%
mutate(fuera = if_else(between(ultimo_mediana, refmin, refmax), '', '*')) %>%
select(valor, fuera)
#añadimos el flag de que está fuera de rango y damos formato a mediana y prom_min
bdlabosresum <- bdlabosresum %>%
left_join(bdmedianalabosdi, by = 'valor') %>%
mutate(prom_mediana = roundcond(prom_mediana),
ultimo_mediana = roundcond(ultimo_mediana))
bdlabosfin <- bdlabosresum %>%
mutate(mediana = paste0(prom_mediana, '; ', '(', prom_p25, '-', prom_p75, ') ','[', prom_min, '-',
prom_max, ']'),
ultimo = paste0(ultimo_mediana, '; ', '(', ultimo_p25, '-', ultimo_p75, ') ','[', ultimo_min, '-',
ultimo_max, ']'),
prom_faltan = as.character(dim(bdlabos)[1]-prom_faltan)
) %>%
select(labtest, mediana, ultimo, prom_faltan, ref2, fuera, tipo) %>%
arrange(tipo)
#Para el texto:
medEstud <- bdlabosresum$numestudios_mediana[1]
maxEstud <- bdlabosresum$numestudios_max[1]
minEstud <- bdlabosresum$numestudios_min[1]
p25Estud <- bdlabosresum$numestudios_p25[1]
p75Estud <- bdlabosresum$numestudios_p75[1]
totdiarios <- dim(bdlabos)[1]
```
The drugs employed during hospitalization varied considerably. Enoxaparin was employed in 92.1% of patients, antibiotics in 91% and corticoids in 76.4%. A total of `r numtxhosp` different drugs were used reflecting the lack of a standard of treatment. This trend is also seen in the number of drugs administered per patient. The median of the number of drugs used to treat the disease was `r statntxhosp$mediana[1]`, IQR of `r statntxhosp$p25[1]` - `r statntxhosp$p75[1]`, polypharmacy was used in `r polifarhosp`% of cases. These results are summarised in Table 3 and figure 3 of the supplementary material.
```{r tbtxhosp}
frectxhosptxt %>%
mutate(nporc = paste0(n, ' (', frec, ')')) %>%
ungroup %>%
select(txhosps, nporc ) %>%
flextable() %>%
# set_caption('Medication used during hospital stay.',
# style = 'Table Caption') %>%
set_header_labels(txhosps = 'Medication',
nporc = 'No. (%)') %>%
bold( part = 'header') %>%
#align(align = 'center', part = 'header') # %>%
footnote(i = 2,
j = 1,
value = as_paragraph(('Other than macrolides')),
ref_symbols = 'a',
part = 'body') %>%
set_table_properties(layout = 'autofit')
# ft <- mk_par(ft, i = 2, j = 'txhosps',
# value = as_paragraph(txhosps,
# as_chunk('a',
# props = fp_text(vertical.align = 'superscript'))))
```
```{r fnumtxhosp}
# , fig.cap='Number of medications per patient for treating Covid-19 during hospitalization.'
numtxhospglob %>%
ggplot(aes(x = numtxhosp, y = frec)) +
labs(x = 'Number of medications received during hospital stay',
y = 'Percentage of patients') +
geom_col(color = 'darkolivegreen4',
fill = 'darkolivegreen2' )
```
A summary of the laboratory tests performed during hospitalization is presented in table \@ref(tab:tblabhosp). The day when a battery of tests was ordered was registered; the column "values of the mean" presents the average of repeated measurements during the whole stay, while the column "values of the last test" reports the average of the last laboratory report before outcome. The median of studies per patient was `r medEstud`, IQR (`r p25Estud`-`r p75Estud`), range [`r minEstud`- `r maxEstud`]. In the last report before outcome, lymphocytes, neutrophils, D-dimer, fibrinogen, ALT, LDH, gamma-glutamyltransferase, ferritin and ESR had median values above the normal range, while monocytes, bicarbonate, PaCO~2~, paO~2~ and calcium were below the reference values.
```{r tblabhosp}
#Hay que repartir las bases de acuerdo con el tipo, para darle más orden
bdbh <- data.frame(labtest = 'Hemogram',
mediana = '',
ultimo = '',
prom_faltan = '',
ref2 = '',
fuera = '',
tipo = '') %>%