Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing program and studies #365

Merged
merged 3 commits into from
Aug 9, 2024
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
6 changes: 5 additions & 1 deletion src/dug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Config:
program_sort_list: str = ""
program_description: dict=field(default_factory=lambda:{})
consent_id_path: str= ""
missing_studies_path: str=""
missing_program_path: str=""


# Preprocessor config that will be passed to annotate.Preprocessor constructor
Expand Down Expand Up @@ -143,7 +145,9 @@ def from_env(cls):
"redis_port": "REDIS_PORT",
"redis_password": "REDIS_PASSWORD",
"program_description": "PROGRAM_DESCRIPTION",
"consent_id_path": "CONSENT_ID_PATH"
"consent_id_path": "CONSENT_ID_PATH",
"missing_studies_path": "MISSING_STUDIES_PATH",
"missing_program_path": "MISSING_PROGRAM_PATH"
}

kwargs = {}
Expand Down
30 changes: 25 additions & 5 deletions src/dug/core/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ async def search_program(self, program_name=None, offset=0, size=None):
# Append the details to the list in the desired format
collection_details_list.append(collection_details)





#Adding consent to the studies
with open(self._cfg.consent_id_path, 'r') as file:
consent_id_mappings = json.load(file)
# Add consent_id to the study
Expand All @@ -539,11 +542,19 @@ async def search_program(self, program_name=None, offset=0, size=None):
updated_studies.append(updated_study)
else:
updated_studies.append(study)


return updated_studies

#Adding missing studies

with open(self._cfg.missing_studies_path, 'r') as file:
missing_studies = json.load(file)
for program in missing_studies:
if program_name.lower() == program['program_name'].lower():
updated_studies.append(program['collections'])



return updated_studies


async def search_program_list(self):
Expand Down Expand Up @@ -573,9 +584,18 @@ async def search_program_list(self):
# The unique data_types and their counts of unique collection_ids will be in the 'aggregations' field of the response
unique_data_types = search_results['aggregations']['unique_program_names']['buckets']
data=unique_data_types
print(data)

#Remove Parent program and add Training program

data = [item for item in data if item['key'] != 'Parent']

with open(self._cfg.missing_program_path, 'r') as file:
missing_programs = json.load(file)
data.extend(missing_programs)


# Sorting the data alphabetically based on 'key'
sorted_data = sorted(data, key=lambda x: x['key'])
sorted_data = sorted(data, key=lambda x: (x['key'].casefold(), x['key'][1:]))

#Add description as another field in exisiting data based on the program name
descriptions_json = self._cfg.program_description
Expand Down
Loading