Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions vertex/getREDCapData.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_records(redcap_url, redcap_api_key, data_access_groups=None, user_assign
}
response = requests.post(redcap_url, data=conex)
logger.debug("HTTP Status: " + str(response.status_code))
df = pd.read_csv(io.StringIO(response.text), keep_default_na=False)
df = pd.read_csv(io.StringIO(response.text), dtype={"subjid": "str"}, keep_default_na=False)
if data_access_groups is not None:
ind = df["redcap_data_access_group"].isin(data_access_groups)
df = df.loc[ind].reset_index(drop=True)
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_records(redcap_url, redcap_api_key, data_access_groups=None, user_assign
}
try:
response = requests.post(redcap_url, data=conex)
df_new = pd.read_csv(io.StringIO(response.text), keep_default_na=False)
df_new = pd.read_csv(io.StringIO(response.text), dtype={"subjid": "str"}, keep_default_na=False)
df_new["redcap_data_access_group"] = dag
df_list.append(df_new)
logger.debug(f"Data access group ID: {dag}, HTTP Status: {response.status_code}")
Expand Down Expand Up @@ -721,7 +721,10 @@ def get_redcap_data(redcap_url, redcap_api_key, data_access_groups=None, user_as
df_map, new_dictionary, quality_report = get_df_map(data, new_dictionary)
df_forms_dict = get_df_forms(data, new_dictionary)

if country_mapping is None:
if "demog_country" in dictionary["field_name"].values:
countries = pd.read_csv("assets/countries.csv", encoding="latin-1")
df_map["country_iso"] = df_map["demog_country"].replace(dict(zip(countries["Country"], countries["Code"])))
elif country_mapping is None:
dag = data[["subjid", "redcap_data_access_group"]].drop_duplicates()
dag = dag.rename(columns={"redcap_data_access_group": "site"})
dag["country_iso"] = dag["site"].apply(lambda x: x.split("-")[1])
Expand Down
4 changes: 3 additions & 1 deletion vertex/layout/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ def get_filter_options(df_map):

outcome_options = [{"label": v, "value": v} for v in df_map["filters_outcome"].dropna().unique()]

country_options = [{"label": c, "value": c} for c in sorted(df_map["filters_country"].dropna().unique())]
countries = pd.read_csv("assets/countries.csv", encoding="latin-1")
country_dict = dict(zip(countries["Code"], countries["Country"]))
country_options = [{"label": country_dict.get(c, None), "value": c} for c in df_map["filters_country"].dropna().unique()]

sex_options = [{"label": c, "value": c} for c in sorted(df_map["filters_sex"].dropna().unique())]

Expand Down
2 changes: 1 addition & 1 deletion vertex/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ def filter_df_map(df_map, sex_value, age_value, country_value, admdate_value, ad
& ((df_map["filters_admdate"] >= admdate_min) | df_map["filters_admdate"].isna())
& ((df_map["filters_admdate"] <= admdate_max) | df_map["filters_admdate"].isna())
& (df_map["filters_outcome"].isin(outcome_value))
& (df_map["filters_country"].isin(country_value))
& (df_map["filters_country"].isin(country_value) | df_map["filters_country"].isna())
]
return df_map_filtered.reset_index(drop=True)