ARS-toscana / ConcePTIONAlgorithmPregnancies

Repository of the script of the ConcePTION Algorithm for Pregnancies
GNU Affero General Public License v3.0
5 stars 3 forks source link

mo_source_value could be non-numeric #41

Closed frasansa closed 2 years ago

frasansa commented 2 years ago

Dear @GiorgioLimoncella,

Could you add to VID specification of step_02_03_T2.2_create_pregnancies_from_itemsets.R an as.numeric function in the *mo_source_value7** statement at line 33? With this fix, the algorithm runs fine for VID database, even when in mo_source_value are also text for some rows, so mo_source_value is a character column.

Current code

 if (thisdatasource=="VID"){

    # start creating pregnancy_ongoing_date
    dataset_item_sets<-dataset_item_sets[,`:=`(pregnancy_ongoing_date=date, meaning_ongoing_date=paste0("from_itemset_",item_set))]

    # then pregnancy_start_date
    dataset_item_sets<-dataset_item_sets[item_set=="GestationalAge" & mo_unit=="weeks", `:=`(pregnancy_start_date=pregnancy_ongoing_date-(mo_source_value*7), meaning_start_date=paste0("from_itemset_",item_set)) ]

Suggested Code

if (thisdatasource=="VID"){

    # start creating pregnancy_ongoing_date
    dataset_item_sets<-dataset_item_sets[,`:=`(pregnancy_ongoing_date=date, meaning_ongoing_date=paste0("from_itemset_",item_set))]

    # then pregnancy_start_date
    dataset_item_sets<-dataset_item_sets[item_set=="GestationalAge" & mo_unit=="weeks", `:=`(pregnancy_start_date=pregnancy_ongoing_date-(as.numeric(mo_source_value)*7), meaning_start_date=paste0("from_itemset_",item_set)) ]

thanks, Francisco.

GiorgioLimoncella commented 2 years ago

Hi @frasansa, thank you very much for the debug!

I added your modification to the script as you suggested