def compute_scores(data, demographics): # Get rid of all records that don't have YR2 data.dropna(axis=1, subset=['youth_report_2_complete']) data = data[data['youth_report_2_complete'] > 0] data = data[~(data['youthreport2_missing'] > 0)] # If no records to score, return empty DF if len(data) == 0: return pandas.DataFrame() # Replace all column labels with the original LimeSurvey names data.columns = Rwrapper.map_labels(data.columns, rc2lime) # Call the scoring function for all table rows scores = data.apply(Rwrapper.runscript, axis=1, Rscript='casq/CASQ.R', scores_key='CASQ.ary') # Replace all score columns with REDCap field names scores.columns = Rwrapper.map_labels(scores.columns, R2rc) # Simply copy completion status from the input surveys scores['casq_complete'] = data['youth_report_2_complete'].map(int) # Make a proper multi-index for the scores table scores.index = pandas.MultiIndex.from_tuples(scores.index) scores.index.names = ['study_id', 'redcap_event_name'] # Return the computed scores - this is what will be imported back into REDCap outfield_list = ['casq_complete'] + R2rc.values() return scores[outfield_list]
def compute_scores(data, demographics): # Get rid of all records that don't have YR2 data.dropna(axis=1, subset=["youth_report_2_complete"]) data = data[data["youth_report_2_complete"] > 0] data = data[~(data["youthreport2_missing"] > 0)] # If no records to score, return empty DF if len(data) == 0: return pandas.DataFrame() # Replace all column labels with the original LimeSurvey names data.columns = Rwrapper.map_labels(data.columns, rc2lime) # Call the scoring function for all table rows scores = data.apply(Rwrapper.runscript, axis=1, Rscript="casq/CASQ.R", scores_key="CASQ.ary") # Replace all score columns with REDCap field names scores.columns = Rwrapper.map_labels(scores.columns, R2rc) # Simply copy completion status from the input surveys scores["casq_complete"] = data["youth_report_2_complete"].map(int) # Make a proper multi-index for the scores table scores.index = pandas.MultiIndex.from_tuples(scores.index) scores.index.names = ["study_id", "redcap_event_name"] # Return the computed scores - this is what will be imported back into REDCap outfield_list = ["casq_complete"] + R2rc.values() return scores[outfield_list]
"casq_set2 [casq7]", "casq_set2 [casq8]", "casq_set2 [casq9]", "casq_set2 [casq10]", "casq_set2 [casq11]", "casq_set2 [casq12]", "casq_set3 [casq13]", "casq_set3 [casq14]", "casq_set3 [casq15]", "casq_set3 [casq16]", ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[Rwrapper.label_to_sri("youthreport2", field)] = field # REDCap fields names input_fields = {"mrireport": ["youth_report_2_complete", "youthreport2_missing"] + rc2lime.keys()} # # This determines the name of the form in REDCap where the results are posted. # output_form = "clinical" # # CES-D field names mapping from R to REDCap # R2rc = {"Cleveland Adolescent Sleepiness Score": "casq_score"} #
# # LimeSurvey field names lime_fields = [ "casq_set1 [casq1]", "casq_set1 [casq2]", "casq_set1 [casq3]", "casq_set1 [casq4]", "casq_set1 [casq5]", "casq_set1 [casq6]", "casq_set2 [casq7]", "casq_set2 [casq8]", "casq_set2 [casq9]", "casq_set2 [casq10]", "casq_set2 [casq11]", "casq_set2 [casq12]", "casq_set3 [casq13]", "casq_set3 [casq14]", "casq_set3 [casq15]", "casq_set3 [casq16]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[Rwrapper.label_to_sri('youthreport2', field)] = field # REDCap fields names input_fields = { 'mrireport': ['youth_report_2_complete', 'youthreport2_missing'] + rc2lime.keys() } # # This determines the name of the form in REDCap where the results are posted. # output_form = 'clinical' # # CES-D field names mapping from R to REDCap #
# LimeSurvey field names lime_fields = [ "cesd_sec1 [cesd1]", "cesd_sec1 [cesd2]", "cesd_sec1 [cesd3]", "cesd_sec1 [cesd4]", "cesd_sec1 [cesd5]", "cesd_sec1 [cesd6]", "cesd_sec2 [cesd7]", "cesd_sec2 [cesd8]", "cesd_sec2 [cesd9]", "cesd_sec2 [ces10]", "cesd_sec2 [ces11]", "cesd_sec2 [ces12]", "cesd_sec3 [ces13]", "cesd_sec3 [ces14]", "cesd_sec3 [ces15]", "cesd_sec3 [ces16]", "cesd_sec3 [ces17]", "cesd_sec3 [ces18]", "cesd_sec3 [ces19]", "cesd_sec3 [ces20]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[Rwrapper.label_to_sri('mrireport', field)] = field # REDCap fields names input_fields = { 'mrireport': ['mri_report_complete', 'mrireport_missing'] + rc2lime.keys() } # # This determines the name of the form in REDCap where the results are posted. # output_form = 'clinical' # # CES-D field names mapping from R to REDCap # R2rc = {'CES Symptomatology Score': 'cesd_score'}
import Rwrapper # # Variables from surveys needed for CTQ # # LimeSurvey field names lime_fields = [ "ctq_set1 [ctq1]", "ctq_set1 [ctq2]", "ctq_set1 [ctq3]", "ctq_set1 [ctq4]", "ctq_set1 [ctq5]", "ctq_set1 [ctq6]", "ctq_set1 [ctq7]", "ctq_set2 [ctq8]", "ctq_set2 [ctq9]", "ctq_set2 [ct10]", "ctq_set2 [ct11]", "ctq_set2 [ct12]", "ctq_set2 [ct13]", "ctq_set2 [ct14]", "ctq_set3 [ctq15]", "ctq_set3 [ctq16]", "ctq_set3 [ctq17]", "ctq_set3 [ctq18]", "ctq_set3 [ctq19]", "ctq_set3 [ctq20]", "ctq_set3 [ctq21]", "ctq_set4 [ctq22]", "ctq_set4 [ctq23]", "ctq_set4 [ctq24]", "ctq_set4 [ctq25]", "ctq_set4 [ctq26]", "ctq_set4 [ctq27]", "ctq_set4 [ctq28]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[Rwrapper.label_to_sri( 'youthreport2', field )] = field # REDCap fields names input_fields = { 'mrireport' : [ 'youth_report_2_complete', 'youthreport2_missing' ] + rc2lime.keys() } # # This determines the name of the form in REDCap where the results are posted. # output_form = 'clinical' # # CTQ field names mapping from R to REDCap # R2rc = { 'Emotional Abuse Scale Total Score' : 'ctq_ea', 'Physical Abuse Scale Total Score' : 'ctq_pa', 'Sexual Abuse Scale Total Score' : 'ctq_sa',
import pandas import Rwrapper # # Variables from surveys needed for CES-D # # LimeSurvey field names lime_fields = [ "cesd_sec1 [cesd1]", "cesd_sec1 [cesd2]", "cesd_sec1 [cesd3]", "cesd_sec1 [cesd4]", "cesd_sec1 [cesd5]", "cesd_sec1 [cesd6]", "cesd_sec2 [cesd7]", "cesd_sec2 [cesd8]", "cesd_sec2 [cesd9]", "cesd_sec2 [ces10]", "cesd_sec2 [ces11]", "cesd_sec2 [ces12]", "cesd_sec3 [ces13]", "cesd_sec3 [ces14]", "cesd_sec3 [ces15]", "cesd_sec3 [ces16]", "cesd_sec3 [ces17]", "cesd_sec3 [ces18]", "cesd_sec3 [ces19]", "cesd_sec3 [ces20]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[Rwrapper.label_to_sri( 'mrireport', field )] = field # REDCap fields names input_fields = { 'mrireport' : [ 'mri_report_complete', 'mrireport_missing' ] + rc2lime.keys() } # # This determines the name of the form in REDCap where the results are posted. # output_form = 'clinical' # # CES-D field names mapping from R to REDCap # R2rc = { 'CES Symptomatology Score' : 'cesd_score' } #