Skip to content

Commit

Permalink
fix multiple base-studies
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Jun 15, 2024
1 parent 059fc21 commit e2c0d7f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions store/neurostore/ingest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def get_base_study(metadata_row):
if len(base_studies) == 1:
return base_studies[0]
elif len(base_studies) > 1:
return merge_base_studies(base_studies)
return merge_base_studies(base_studies, doi, pmid)
else:
created_bs = [
bs for bs in all_base_studies if bs.doi == doi and bs.pmid == pmid
Expand All @@ -503,11 +503,17 @@ def get_base_study(metadata_row):
return created_bs[0]
return BaseStudy.query.filter_by(pmid=pmid).one_or_none()

def merge_base_studies(base_studies):
source_base_study = next(
filter(lambda bs: bs.pmid == pmid and bs.doi == doi, base_studies),
base_studies[0],
)
def merge_base_studies(base_studies, doi, pmid):
if doi is None:
source_base_study = next(
filter(lambda bs: bs.pmid == pmid and bs.doi is not None, base_studies),
base_studies[0],
)
else:
source_base_study = next(
filter(lambda bs: bs.pmid == pmid and bs.doi == doi, base_studies),
base_studies[0],
)
other_base_studies = [
bs for bs in base_studies if bs.id != source_base_study.id
]
Expand Down

0 comments on commit e2c0d7f

Please sign in to comment.