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
38 changes: 38 additions & 0 deletions src/server/routes/api/document/pubmed/fetchPubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,42 @@ const getChemicalList = MedlineCitation => {
return getElementsByName( ChemicalList, 'Chemical' ).map( getChemical );
};


const getCommentsCorrections = CommentsCorrections => {
const extractDOI = str => {
const doiRegex = /^doi: (?<DOI>10\.\d{4,9}\/[-._;()/:A-Z0-9]+)$/i;
const matches = str.match( doiRegex );
const DOI = _.get( matches, ['groups', 'DOI'], null );
return DOI;
};
// <!ELEMENT CommentsCorrections (RefSource,PMID?,Note?) >
// <!ATTLIST CommentsCorrections
// RefType (AssociatedDataset | AssociatedPublication |
// CommentIn | CommentOn |
// CorrectedandRepublishedIn | CorrectedandRepublishedFrom |
// ErratumIn | ErratumFor |
// ExpressionOfConcernIn | ExpressionOfConcernFor |
// RepublishedIn | RepublishedFrom |
// RetractedandRepublishedIn | RetractedandRepublishedFrom |
// RetractionIn | RetractionOf |
// UpdateIn | UpdateOf |
// SummaryForPatientsIn |
// OriginalReportIn |
// ReprintIn | ReprintOf |
// Cites) #REQUIRED >
const RefType = getElementAttribute( CommentsCorrections, 'RefType' );
const PMID = getElementByName( CommentsCorrections, 'PMID' ) ? getElementText( getElementByName( CommentsCorrections, 'PMID' ) ): null;
const RefSource = getElementText( getElementByName( CommentsCorrections, 'RefSource' ) );
const DOI = extractDOI( RefSource );
return { RefType, PMID, RefSource, DOI };
};

// <!ELEMENT CommentsCorrectionsList (CommentsCorrections+) >
const getCommentsCorrectionsList = MedlineCitation => {
const CommentsCorrectionsList = getElementByName( MedlineCitation, 'CommentsCorrectionsList' );
return getElementsByName( CommentsCorrectionsList, 'CommentsCorrections' ).map( getCommentsCorrections );
};

// <!ELEMENT KeywordList (Keyword+) >
// <!ATTLIST KeywordList
// Owner (NLM | NLM-AUTO | NASA | PIP | KIE | NOTNLM | HHS) "NLM" >
Expand Down Expand Up @@ -313,13 +349,15 @@ const getMedlineCitation = PubmedArticle => {

const Article = getArticle( MedlineCitation );
const ChemicalList = getElementByName( MedlineCitation, 'ChemicalList' ) ? getChemicalList( MedlineCitation ): [];
const CommentsCorrectionsList = getElementByName( MedlineCitation, 'CommentsCorrectionsList' ) ? getCommentsCorrectionsList( MedlineCitation ): [];
const KeywordList = getElementByName( MedlineCitation, 'KeywordList' ) ? getKeywordList( MedlineCitation ): [];
const MeshheadingList = getElementByName( MedlineCitation, 'MeshHeadingList' ) ? getMeshheadingList( MedlineCitation ): [];
const InvestigatorList = getElementByName( MedlineCitation, 'InvestigatorList' ) ? getInvestigatorList( MedlineCitation ): [];

return {
Article,
ChemicalList,
CommentsCorrectionsList,
KeywordList,
MeshheadingList,
InvestigatorList
Expand Down
4 changes: 3 additions & 1 deletion src/util/pubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ const getPubmedCitation = PubmedArticle => {
const doi = getArticleId( PubmedArticle, 'doi' );
const pubTypes = _.get( Article, 'PublicationTypeList' ); //required
const { ISODate } = getPubDate( _.get( Article, ['Journal', 'JournalIssue'] ) );
const relations = _.get( PubmedArticle, [ 'MedlineCitation', 'CommentsCorrectionsList'], [] );

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

/**
Expand Down Expand Up @@ -278,6 +279,7 @@ const createPubmedArticle = ({ articleTitle = null, journalName = null, publicat
PublicationTypeList: []
},
ChemicalList: [],
CommentsCorrectionsList: [],
InvestigatorList: [],
KeywordList: [],
MeshheadingList: []
Expand Down
50 changes: 47 additions & 3 deletions test/pubmed/fetchPubmed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { expect } from 'chai';
import convert from 'xml-js';

import { pubmedDataConverter } from '../../src/server/routes/api/document/pubmed/fetchPubmed';
import { isDigits, isDoi } from '../../src/util';

const TEST_PUBMED_DATA = new Map([
['151222', 'pmid_151222.xml'], // MedlineDate
['9417067', 'pmid_9417067.xml'],
['29440426', 'pmid_29440426.xml'], // PubMedData
['30078747', 'pmid_30078747.xml'], // InvestigatorList
['30115697', 'pmid_30115697.xml'], // Markup; Identifier
['31511694', 'pmid_31511694.xml']
['31511694', 'pmid_31511694.xml'],
['9500320', 'pmid_9500320.xml'], //CommentsCorrections - RetractionIn etc
['38289659', 'pmid_38289659.xml'] //CommentsCorrections RefSource: doi string
]);

const xml2jsOpts = {};
Expand Down Expand Up @@ -215,8 +218,9 @@ describe('fetchPubmed', function(){

it('Should have item with top-level attributes', () => {
if( !_.isEmpty( Identifier ) ){
expect( Identifier ).to.have.property( 'Identifier[0].Source' );
expect( Identifier ).to.have.property( 'Identifier[0].id' );
let first = _.first( Identifier );
expect( first ).to.have.property( 'Source' );
expect( first ).to.have.property( 'id' );
}
});

Expand Down Expand Up @@ -277,6 +281,46 @@ describe('fetchPubmed', function(){

});//ChemicalList

describe( 'CommentsCorrectionsList', () => {

let CommentsCorrectionsList;
before( () => {
CommentsCorrectionsList = _.get( MedlineCitation, 'CommentsCorrectionsList' );
});

it('Should be a list, when exists', () => {
if( CommentsCorrectionsList ){ // Optional
expect( CommentsCorrectionsList ).to.be.an.instanceof(Array);
}
});

it('Should have required attributes, when exists', () => {
if( CommentsCorrectionsList ){ // Optional
for (const CommentsCorrections of CommentsCorrectionsList) {
expect( CommentsCorrections ).to.have.property( 'RefSource' );
expect( CommentsCorrections ).to.have.property( 'PMID' );
expect( CommentsCorrections ).to.have.property( 'DOI' );
expect( CommentsCorrections ).to.have.property( 'RefType' );
}
}
});

it('Should have correctly formatted PMID and DOI, when not null', () => {
if( CommentsCorrectionsList ){ // Optional
for (const CommentsCorrections of CommentsCorrectionsList) {
if( CommentsCorrections.PMID !== null ){
expect( isDigits( CommentsCorrections.PMID ) ).to.be.true;
}
if( CommentsCorrections.DOI !== null ){
expect( isDoi( CommentsCorrections.DOI ) ).to.be.true;
}
}
}
});

});//CommentsCorrectionsList


describe( 'KeywordList', () => {

let KeywordList;
Expand Down
Loading