Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion src/server/routes/api/document/pubmed/fetchPubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ const getJournal = Article => {
};
};

const getPublicationType = Article => {
const PublicationTypeList = getElementByName( Article, 'PublicationTypeList' );
const PublicationType = getElementsByName( PublicationTypeList, 'PublicationType' );
return PublicationType.map( elt => {
const UI = getElementAttribute( elt, 'UI' );
const value = getElementText( elt );
return { UI, value };
});
};

const getArticle = MedlineCitation => {
// <!ELEMENT Article (Journal,ArticleTitle,((Pagination, ELocationID*) | ELocationID+),
// Abstract?,AuthorList?, Language+, DataBankList?, GrantList?,
Expand All @@ -196,11 +206,18 @@ const getArticle = MedlineCitation => {
const AuthorList = getElementByName( Article, 'AuthorList' ) ? getAuthorList( Article ): null;
const Journal = getJournal( Article );

// <!ELEMENT PublicationType (#PCDATA) >
// <!ATTLIST PublicationType
// UI CDATA #REQUIRED >
// <!ELEMENT PublicationTypeList (PublicationType+) >
const PublicationTypeList = getPublicationType( Article );

return {
Journal,
ArticleTitle,
Abstract,
AuthorList
AuthorList,
PublicationTypeList
};
};

Expand Down
31 changes: 20 additions & 11 deletions src/server/routes/api/document/pubmed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const ID_TYPE = Object.freeze({
TITLE: 'title'
});

const pubTypeToExclude = [
{ UI: 'D016425', value: 'Published Erratum' }
];

const paperId2Type = paperId => {
// 99.3% of CrossRef DOIs (https://www.crossref.org/blog/dois-and-matching-regular-expressions/)
const doiRegex = /^10\.\d{4,9}\/[-._;()/:A-Z0-9]+$/i;
Expand Down Expand Up @@ -44,18 +48,23 @@ const findMatchingPubmedArticle = async ( paperId, IdType, uids ) => {

// Try to match: Could be responsibility of user in future
const articleMatchesPaperId = article => {
const { title, pmid, doi } = getPubmedCitation( article );
const { title, pmid, doi, pubTypes } = getPubmedCitation( article );
let hasMatch = false;
switch ( IdType ) {
case ID_TYPE.DOI:
if( doi === paperId ) hasMatch = true;
break;
case ID_TYPE.PMID:
if( pmid === paperId ) hasMatch = true;
break;
case ID_TYPE.TITLE:
if( santitize( title ).includes( santitize( paperId ) ) ) hasMatch = true;
break;

// Ignore if this article contains an invalid PublicationType entry
const isValidType = _.isEmpty( _.intersectionBy( pubTypes, pubTypeToExclude, 'UI' ) );
if( isValidType ){
switch ( IdType ) {
case ID_TYPE.DOI:
if( doi === paperId ) hasMatch = true;
break;
case ID_TYPE.PMID:
if( pmid === paperId ) hasMatch = true;
break;
case ID_TYPE.TITLE:
if( santitize( title ).includes( santitize( paperId ) ) ) hasMatch = true;
break;
}
}
return hasMatch;
};
Expand Down
4 changes: 3 additions & 1 deletion src/util/pubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const getArticleId = ( PubmedArticle, IdType ) => _.get( _.find( _.get( PubmedAr
* @return {String} result.reference (<ISOAbbreviation> | <Title>) <Year>; <Volume>
* @return {String} result.pmid
* @return {String} result.doi
* @return {String} result.pubTypes
*/
const getPubmedCitation = PubmedArticle => {
const Article = _.get( PubmedArticle, ['MedlineCitation','Article'] ); //required
Expand All @@ -162,8 +163,9 @@ const getPubmedCitation = PubmedArticle => {
const abstract = _.get( Article, 'Abstract', null );
const pmid = getArticleId( PubmedArticle, 'pubmed' );
const doi = getArticleId( PubmedArticle, 'doi' );
const pubTypes = _.get( Article, 'PublicationTypeList' ); //required

return { title, authors, reference, abstract, pmid, doi };
return { title, authors, reference, abstract, pmid, doi, pubTypes };
};

/**
Expand Down
16 changes: 16 additions & 0 deletions test/pubmed/fetchPubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ describe('fetchPubmed', function(){

}); //AuthorList

describe( 'PublicationTypeList', () => {

let PublicationTypeList;
before( () => {
PublicationTypeList = _.get( Article, 'PublicationTypeList' );
});

it('Should be a list of UI/text objects', () => {
expect( PublicationTypeList ).to.be.an.instanceof(Array);
PublicationTypeList.forEach( PublicationType => {
expect( PublicationType ).to.have.property('UI');
expect( PublicationType ).to.have.property('value');
});
});
});

}); //Article

describe( 'ChemicalList', () => {
Expand Down