Skip to content

Commit

Permalink
Add person_id to doi model
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhoads committed Nov 30, 2023
1 parent 78f867e commit 1a6578a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
33 changes: 25 additions & 8 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1649,21 +1649,38 @@ def sponsor_contributors
end


def person_id
(Array.wrap(creators) + Array.wrap(contributors)).reduce([]) do |sum, c|
Array.wrap(c.fetch("nameIdentifiers", nil)).each do |name_identifier|
if name_identifier.is_a?(Hash) && name_identifier.fetch("nameIdentifierScheme", nil) == "ORCID" && name_identifier.fetch("nameIdentifier", nil).present?
sum << orcid_as_url(
orcid_from_url(name_identifier.fetch("nameIdentifier", nil))
)
end
end
sum.uniq
end
end

def organization_id
(Array.wrap(creators) + Array.wrap(contributors)).reduce([]) do |sum, c|
Array.wrap(c.fetch("nameIdentifiers", nil)).each do |name_identifier|
sum << ror_from_url(name_identifier.fetch("nameIdentifier", nil)) if name_identifier.is_a?(Hash) && name_identifier.fetch("nameIdentifierScheme", nil) == "ROR" && name_identifier.fetch("nameIdentifier", nil).present?
if name_identifier.is_a?(Hash) && name_identifier.fetch("nameIdentifierScheme", nil) == "ROR" && name_identifier.fetch("nameIdentifier", nil).present?
sum << ror_from_url(name_identifier.fetch("nameIdentifier", nil))
end
end
sum
sum.uniq
end
end

def fair_organization_id
(Array.wrap(creators) + sponsor_contributors).reduce([]) do |sum, c|
Array.wrap(c.fetch("nameIdentifiers", nil)).each do |name_identifier|
sum << ror_from_url(name_identifier.fetch("nameIdentifier", nil)) if name_identifier.is_a?(Hash) && name_identifier.fetch("nameIdentifierScheme", nil) == "ROR" && name_identifier.fetch("nameIdentifier", nil).present?
if name_identifier.is_a?(Hash) && name_identifier.fetch("nameIdentifierScheme", nil) == "ROR" && name_identifier.fetch("nameIdentifier", nil).present?
sum << ror_from_url(name_identifier.fetch("nameIdentifier", nil))
end
end
sum
sum.uniq
end
end

Expand All @@ -1672,7 +1689,7 @@ def affiliation_id
Array.wrap(c.fetch("affiliation", nil)).each do |affiliation|
sum << ror_from_url(affiliation.fetch("affiliationIdentifier", nil)) if affiliation.is_a?(Hash) && affiliation.fetch("affiliationIdentifierScheme", nil) == "ROR" && affiliation.fetch("affiliationIdentifier", nil).present?
end
sum
sum.uniq
end
end

Expand All @@ -1681,7 +1698,7 @@ def fair_affiliation_id
Array.wrap(c.fetch("affiliation", nil)).each do |affiliation|
sum << ror_from_url(affiliation.fetch("affiliationIdentifier", nil)) if affiliation.is_a?(Hash) && affiliation.fetch("affiliationIdentifierScheme", nil) == "ROR" && affiliation.fetch("affiliationIdentifier", nil).present?
end
sum
sum.uniq
end
end

Expand All @@ -1690,7 +1707,7 @@ def affiliation_id_and_name
Array.wrap(c.fetch("affiliation", nil)).each do |affiliation|
sum << "#{ror_from_url(affiliation.fetch('affiliationIdentifier', nil))}:#{affiliation.fetch('name', nil)}" if affiliation.is_a?(Hash) && affiliation.fetch("affiliationIdentifierScheme", nil) == "ROR" && affiliation.fetch("affiliationIdentifier", nil).present?
end
sum
sum.uniq
end
end

Expand All @@ -1699,7 +1716,7 @@ def fair_affiliation_id_and_name
Array.wrap(c.fetch("affiliation", nil)).each do |affiliation|
sum << "#{ror_from_url(affiliation.fetch('affiliationIdentifier', nil))}:#{affiliation.fetch('name', nil)}" if affiliation.is_a?(Hash) && affiliation.fetch("affiliationIdentifierScheme", nil) == "ROR" && affiliation.fetch("affiliationIdentifier", nil).present?
end
sum
sum.uniq
end
end

Expand Down
61 changes: 61 additions & 0 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,67 @@
end
end

describe "person_ids" do
it "from creators and contributors" do
subject = build(
:doi,
creators: [
{
"familyName" => "Garza",
"givenName" => "Kristian",
"name" => "Garza, Kristian",
"nameIdentifiers" => [
{
"nameIdentifier" => "https://orcid.org/0000-0003-3484-6875",
"nameIdentifierScheme" => "ORCID",
"schemeUri" => "https://orcid.org",
},
],
"nameType" => "Personal",
"affiliation" => [
{
"name" => "University of Cambridge",
"affiliationIdentifier" => "https://ror.org/013meh722",
"affiliationIdentifierScheme" => "ROR",
},
],
},
],
contributors: [
{
"contributorType" => "Sponsor",
"familyName" => "Bob",
"givenName" => "Jones",
"name" => "Jones, Bob",
"nameIdentifiers" => [
{
"nameIdentifier" => "https://orcid.org/0000-0003-3484-0000",
"nameIdentifierScheme" => "ORCID",
"schemeUri" => "https://orcid.org",
},
],
"nameType" => "Personal",
"affiliation" => [
{
"name" => "University of Examples",
"affiliationIdentifier" => "https://ror.org/013meh8888",
"affiliationIdentifierScheme" => "ROR",
},
],
},
]
)
expect(subject).to be_valid
expect(subject.person_id).to eq(
[
"https://orcid.org/0000-0003-3484-6875",
"https://orcid.org/0000-0003-3484-0000",
]
)

end
end

describe "related_identifiers" do
it "has part" do
subject = build(:doi, related_identifiers: [
Expand Down

0 comments on commit 1a6578a

Please sign in to comment.