Skip to content

Commit

Permalink
Attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ieuans committed Oct 9, 2023
1 parent 9f32914 commit 84ee945
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
18 changes: 10 additions & 8 deletions assets/definition_file_create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ collections:
- 18
definition: "ABCDEFGHIJKLMNOPQRSTUVXYZ"
concept_information:
- name: COVID-19 infection - Primary Care:
- name: COVID-19 infection - Primary Care
type: existing_concept
concept_id: 714
concept_history_id: 2567
- name: COVID-19 infection - Hospitalizations:
type: existing_concept
concept_id: 715
concept_history_id: 2569
concept_version_id: 2567
- name: COVID-19 infection - Hospitalizations
type: csv
coding_system: 4
code_column: Code
description_column: Description
filepath: "./path/to/file.csv"
world_access: 1
group_access: 1
template:
- id: 1
- version_id: 1
id: 1
version_id: 1
15 changes: 6 additions & 9 deletions assets/definition_file_update.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
phenotype_id: PH1
phenotype_version_id: 2
name: COVID-19 infection
author: BHF CVD COVID UK Consortium
type: '2'
Expand All @@ -15,19 +13,18 @@ coding_system:
collections:
- 20
- 18
definition: Update PH1576
definition: "ABCDEFGHIJKLMNOPQRSTUVXYZ"
concept_information:
- name: COVID-19 infection - Primary Care:
- name: COVID-19 infection - Primary Care
type: existing_concept
concept_id: 714
concept_history_id: 2567
- name: COVID-19 infection - Hospitalizations:
concept_version_id: 2567
- name: COVID-19 infection - Hospitalizations
type: existing_concept
concept_id: 715
concept_history_id: 2569
world_access: 1
group_access: 1
owner: ieuan.scanlon
template:
- id: 1
- version_id: 1
id: 1
version_id: 1
31 changes: 23 additions & 8 deletions pyconceptlibraryclient/phenotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def __format_concepts_for_upload(self, data: list | None) -> list:
'details': {
'name': concept['name'],
'coding_system': concept['coding_system'],
'internal_type': concept['type']
'internal_type': concept['type'],
'code_attribute_header': []
},
'components': []
}
Expand All @@ -265,7 +266,9 @@ def __format_concepts_for_upload(self, data: list | None) -> list:
else:
new_concept['is_new'] = True

new_concept['components'].append(self.__build_concept_components(concept, new_concept))
new_component, attribute_headers = self.__build_concept_components(concept, new_concept)
new_concept['components'].append(new_component)
new_concept['details']['code_attribute_header'] = attribute_headers

result.append(new_concept)
continue
Expand All @@ -277,9 +280,20 @@ def __build_concept_components(self, concept: dict, new_concept: dict) -> dict:
'''
codelist = pd.read_csv(concept['filepath'])
code_column, description_column = concept['code_column'], concept['description_column']
has_description = description_column in codelist.columns

column_list = codelist.columns

code_column = concept.get('code_column')
if not code_column or code_column not in column_list:
print(f'{concept["name"]} missing \'code_column\', returns no codes')
return {}, []

description_column = concept.get('description_column')
has_description = description_column and description_column in column_list

attribute_headers = [
header for header in column_list if header not in [code_column, description_column]
]

new_component = {
'is_new': True,
'name': 'CODES - %s' % new_concept['details']['name'],
Expand All @@ -290,10 +304,11 @@ def __build_concept_components(self, concept: dict, new_concept: dict) -> dict:
for _, row in codelist.iterrows():
new_component['codes'].append({
'code': row[code_column],
'description': '' if not has_description else row[description_column]
'description': '' if not has_description else row[description_column],
'attributes': list(row[attribute_headers].values)
})

return new_component
return new_component, attribute_headers

def __format_for_download(self, data: dict | None) -> list | None:
'''
Expand All @@ -310,7 +325,7 @@ def __format_for_download(self, data: dict | None) -> list | None:
if not isinstance(value, list) and not isinstance(value, dict):
result[key] = value
continue

if key == 'concept_information':
result[key] = []
for concept in value:
Expand Down

0 comments on commit 84ee945

Please sign in to comment.