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 = RwrapperNew.map_labels( data.columns, rc2lime ) # Call the scoring function for all table rows scores = data.apply( RwrapperNew.runscript, axis=1, Rscript='pgd/PGD.R' ) # Replace all score columns with REDCap field names scores.columns = RwrapperNew.map_labels( scores.columns, R2rc ) # Simply copy completion status from the input surveys scores['pgd_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 = [ 'pgd_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 = RwrapperNew.map_labels(data.columns, rc2lime) # Call the scoring function for all table rows scores = data.apply(RwrapperNew.runscript, axis=1, Rscript='aeq/AEQ.R') # Replace all score columns with REDCap field names scores.columns = RwrapperNew.map_labels(scores.columns, R2rc) # Simply copy completion status from the input surveys scores['aeq_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 = ['aeq_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=0, 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 = RwrapperNew.map_labels( data.columns, rc2lime ) # Call the scoring function for all table rows scores = data.apply( RwrapperNew.runscript, axis=1, Rscript='psqi/PSQI.R' ) # Replace all score columns with REDCap field names scores.columns = RwrapperNew.map_labels( scores.columns, R2rc ) # Simply copy completion status from the input surveys scores['psqi_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 = [ 'psqi_complete' ] + R2rc.values() returnDF= scores[ outfield_list ] # remove nan entries as they corrupt data ingest (REDCAP cannot handle it correctly) and superfluous zeros as these should all be integer scores return returnDF.applymap(lambda x: '' if math.isnan(x) else '{0:g}'.format(float(x)))
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() # Set "ydi2" ("sex" field in LimeSurvey) based on what is in REDCap - this is chacked against subject ID and should avoid mis-entered data data["ydi2"] = data.index.map(lambda key: demographics["sex"][key[0]]) # Replace all column labels with the original LimeSurvey names data.columns = RwrapperNew.map_labels(data.columns, rc2lime) # Call the scoring function for all table rows scores = data.apply(RwrapperNew.runscript, axis=1, Rscript="pds/PDS.R") # Replace all score columns with REDCap field names scores.columns = RwrapperNew.map_labels(scores.columns, R2rc) # Simply copy completion status from the input surveys scores["pds_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 = ["pds_complete"] + R2rc.values() return scores[outfield_list]
import pandas import RwrapperNew # # Variables from surveys needed for PGD # # LimeSurvey field names lime_fields = [ "PGD_sec1 [pgd1]", "PGD_sec1 [pgd2]", "PGD_sec1 [pgd3]", "PGD_sec1 [pgd4]", "PGD_sec1 [pgd5]", "PGD_sec1 [pgd6]", "PGD_sec2 [pgd7]", "PGD_sec2 [pgd8]", "PGD_sec2 [pgd9]", "PGD_sec2 [pgd10]", "PGD_sec2 [pgd11]", "PGD_sec2 [pgd12]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[RwrapperNew.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' # # PGD field names mapping from R to REDCap # R2rc = { 'PGD.SUM' : 'pgd_score' } #
# LimeSurvey field names lime_fields = [ "AEQ_sec1 [aeq1]", "AEQ_sec1 [aeq2]", "AEQ_sec1 [aeq3]", "AEQ_sec1 [aeq4]", "AEQ_sec1 [aeq5]", "AEQ_sec1 [aeq6]", "AEQ_sec1 [aeq7]", "AEQ_sec2 [aeq8]", "AEQ_sec2 [aeq9]", "AEQ_sec2 [aeq10]", "AEQ_sec2 [aeq11]", "AEQ_sec2 [aeq12]", "AEQ_sec2 [aeq13]", "AEQ_sec2 [aeq14]", "AEQ_sec3 [aeq15]", "AEQ_sec3 [aeq16]", "AEQ_sec3 [aeq17]", "AEQ_sec3 [aeq18]", "AEQ_sec3 [aeq19]", "AEQ_sec3 [aeq20]", "AEQ_sec3 [aeq21]" ] # Dictionary to recover LimeSurvey field names from REDCap names rc2lime = dict() for field in lime_fields: rc2lime[RwrapperNew.label_to_sri('youthreport2', field)] = field # REDCap fields names input_fields = { 'youthreport2': ['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' # # AEQ field names mapping from R to REDCap #