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

add duplicate reference check #965

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Changes from 2 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
32 changes: 32 additions & 0 deletions hawc/apps/lit/managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging

import numpy as np
import pandas as pd
from django.apps import apps
from django.contrib.postgres.aggregates import ArrayAgg
Expand Down Expand Up @@ -346,6 +347,37 @@ def validate_hero_ids(self, ids: list[int]) -> dict:
if len(fetched_content["failure"]) > 0:
failed_join = ", ".join(str(el) for el in fetched_content["failure"])
raise ValidationError(f"The following HERO ID(s) could not be imported: {failed_join}")
if len(fetched_content["success"]) > 0:
df = (
pd.DataFrame(
[
{
"ref_id": ref["json"]["REFERENCE_ID"],
"HEROID": ref["json"]["HEROID"],
"PMID": ref["json"].get("PMID", ""),
"doi": ref["json"].get("doi", ""),
"wosid": ref["json"].get("wosid", ""),
}
for ref in fetched_content["success"]
]
)
.replace("", np.nan)
.set_index("ref_id")
)
hero_dupes = df[df.HEROID.notna() & df.HEROID.duplicated(keep=False)]
pubmed_dupes = df[df.PMID.notna() & df.PMID.duplicated(keep=False)]
doi_dupes = df[df.doi.notna() & df.doi.duplicated(keep=False)]
wos_dupes = df[df.wosid.notna() & df.wosid.duplicated(keep=False)]
for dupes, id_type in [
(hero_dupes, "HERO IDs"),
(pubmed_dupes, "PubMed IDs"),
(doi_dupes, "DOIs"),
(wos_dupes, "WoS IDs"),
]:
if dupes.shape[0] > 0:
raise ValidationError(
f"The following HERO IDs have duplicate {id_type}: {dupes.HEROID.tolist()}"
)
return fetched_content

def bulk_create_hero_ids(self, content):
Expand Down