function normalizeResearchData(rd) {
let res = {
pub: { Source: { SourceSerial: {} } },
org: Object.assign({}, rd)
}
res.pub.IdentifierScopusId = res.org.IdentifierScopusId.map(id => id.replace("2-s2.0-", ""))
if (res.org.Source && res.org.Source.SourceSerial) {
let researchScopusSourceIds = res.org.Source.SourceSerial.Identifiers
.filter(ssId => ssId.Type.Value === "SCOPUS_SOURCE_ID")
if (researchScopusSourceIds.length > 1) {
throw new Error(`${res.org.Id} got multiple Scopus Source IDs from Research.`)
}
res.scopusSourceId = researchScopusSourceIds.length === 1 ?
researchScopusSourceIds[0].Value.replace(/-/g,"").trim() : undefined
let researchIssns = res.org.Source.SourceSerial.Identifiers
.filter(ssId => ssId.Type.Value === "ISSN")
if (researchIssns.length > 1) {
throw new Error(`${res.org.Id} got multiple ISSN from Research.`)
}
res.issn = researchIssns.length === 1 ?
researchIssns[0].Value.replace(/-/g,"").trim().toLowerCase() : undefined
let researchEissns = res.org.Source.SourceSerial.Identifiers
.filter(ssId => ssId.Type.Value === "EISSN")
if (researchEissns.length > 1) {
throw new Error(`${res.org.Id} got multiple EISSN from Research.`)
}
res.eIssn = researchEissns.length === 1 ?
researchEissns[0].Value.replace(/-/g,"").trim().toLowerCase() : undefined
}
res.pub.Id = res.org.Id
res.pub.Year = res.org.Year
res.pub.Source.SourceSerial.Title = res.org.Source && res.org.Source.SourceSerial ?
res.org.Source.SourceSerial.Title : undefined
res.pub.Source.Volume = res.org.Source && res.org.Source.Volume ? res.org.Source.Volume.trim() : undefined
res.pub.Source.Issue = res.org.Source && res.org.Source.Issue ? res.org.Source.Issue.trim() : undefined
res.pub.Source.ArticleNo = res.org.Source && res.org.Source.ArticleNo ?
res.org.Source.ArticleNo.trim() : undefined
res.pub.Source.PageStart = res.org.Source && res.org.Source.PageStart ?
res.org.Source.PageStart.trim() : undefined
res.pub.Source.PageEnd = res.org.Source && res.org.Source.PageEnd ? res.org.Source.PageEnd.trim() : undefined
return res
}