diff --git a/src/b2aiprep/dataset.py b/src/b2aiprep/dataset.py index 8de1594..992ac43 100644 --- a/src/b2aiprep/dataset.py +++ b/src/b2aiprep/dataset.py @@ -429,12 +429,14 @@ def load_and_pivot_questionnaire(self, questionnaire_name: str) -> pd.DataFrame: # concatenate all the dataframes pivoted_df = pd.concat(q_dfs) + # create a value column that merges valueString, valueBoolean, etc. # https://hl7.org/fhir/r4/questionnaireresponse-definitions.html#QuestionnaireResponse.item.answer.value_x_ # boolean|decimal|integer|date|dateTime|time|string|uri|Attachment|Coding|Quantity|Reference(Any) # currently we only support String/Boolean value_columns = ['valueString', 'valueBoolean'] pivoted_df['value'] = None + pivoted_df = pivoted_df.reset_index(drop=True) for col in value_columns: if col in pivoted_df.columns: pivoted_df['value'] = pivoted_df['value'].combine_first(pivoted_df[col])