00001 <?php
00002
00015
00016
00017
00018 import('xml.XMLCustomWriter');
00019
00020 define('PUBMED_DTD_URL', 'http://www.ncbi.nlm.nih.gov:80/entrez/query/static/PubMed.dtd');
00021 define('PUBMED_DTD_ID', '-//NLM//DTD PubMed 2.0//EN');
00022
00023 class PubMedExportDom {
00024
00034 function &generatePubMedDom() {
00035
00036 $doc = &XMLCustomWriter::createDocument('ArticleSet', PUBMED_DTD_ID, PUBMED_DTD_URL);
00037
00038 return $doc;
00039 }
00040
00041 function &generateArticleSetDom(&$doc) {
00042 $root = &XMLCustomWriter::createElement($doc, 'ArticleSet');
00043 XMLCustomWriter::appendChild($doc, $root);
00044
00045 return $root;
00046 }
00047
00048 function &generateArticleDom(&$doc, &$journal, &$issue, &$section, &$article) {
00049
00050
00051 $editorSubmissionDao = &DAORegistry::getDAO('EditorSubmissionDAO');
00052
00053
00054 $root = &XMLCustomWriter::createElement($doc, 'Article');
00055
00056
00057 $journalNode = &XMLCustomWriter::createElement($doc, 'Journal');
00058 XMLCustomWriter::appendChild($root, $journalNode);
00059
00060 $publisherInstitution = $journal->getSetting('publisherInstitution');
00061 $publisherNode = XMLCustomWriter::createChildWithText($doc, $journalNode, 'PublisherName', $publisherInstitution);
00062
00063 XMLCustomWriter::createChildWithText($doc, $journalNode, 'JournalTitle', $journal->getJournalTitle());
00064
00065
00066 if ($journal->getSetting('printIssn') != '') $ISSN = $journal->getSetting('printIssn');
00067 elseif ($journal->getSetting('issn') != '') $ISSN = $journal->getSetting('issn');
00068 elseif ($journal->getSetting('onlineIssn') != '') $ISSN = $journal->getSetting('onlineIssn');
00069 else $ISSN = '';
00070
00071 if ($ISSN != '') XMLCustomWriter::createChildWithText($doc, $journalNode, 'Issn', $ISSN);
00072
00073 XMLCustomWriter::createChildWithText($doc, $journalNode, 'Volume', $issue->getVolume());
00074 XMLCustomWriter::createChildWithText($doc, $journalNode, 'Issue', $issue->getNumber(), false);
00075
00076 $pubDateNode =& PubMedExportDom::generatePubDateDom($doc, $article->getDatePublished(), 'epublish');
00077 XMLCustomWriter::appendChild($journalNode, $pubDateNode);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 $language = $article->getLanguage();
00088 if ($language == 'en' || $language == '' ) {
00089 XMLCustomWriter::createChildWithText($doc, $root, 'ArticleTitle', $article->getArticleTitle());
00090 } else {
00091 XMLCustomWriter::createChildWithText($doc, $root, 'VernacularTitle', $article->getArticleTitle());
00092 }
00093
00094
00095
00096
00097
00098 $pages = $article->getPages();
00099 if (preg_match("/([0-9]+)\s*-\s*([0-9]+)/i", $pages, $matches)) {
00100
00101 XMLCustomWriter::createChildWithText($doc, $root, 'FirstPage', $matches[1]);
00102 XMLCustomWriter::createChildWithText($doc, $root, 'LastPage', $matches[2]);
00103 }elseif (preg_match("/(e[0-9]+)/i", $pages, $matches)) {
00104
00105 XMLCustomWriter::createChildWithText($doc, $root, 'FirstPage', $matches[1]);
00106 XMLCustomWriter::createChildWithText($doc, $root, 'LastPage', $matches[1]);
00107 } else {
00108
00109 XMLCustomWriter::createChildWithText($doc, $root, 'FirstPage', $article->getBestArticleId($journal));
00110 XMLCustomWriter::createChildWithText($doc, $root, 'LastPage', $article->getBestArticleId($journal));
00111 }
00112
00113
00114 XMLCustomWriter::createChildWithText($doc, $root, 'Language', strtoupper($article->getLanguage()), false);
00115
00116
00117 $authorListNode = &XMLCustomWriter::createElement($doc, 'AuthorList');
00118 XMLCustomWriter::appendChild($root, $authorListNode);
00119
00120 foreach ($article->getAuthors() as $author) {
00121 $authorNode =& PubMedExportDom::generateAuthorDom($doc, $author);
00122 XMLCustomWriter::appendChild($authorListNode, $authorNode);
00123 }
00124
00125
00126
00127
00128
00129
00130 if ($article->getPublicArticleId()) {
00131 $articleIdListNode = &XMLCustomWriter::createElement($doc, 'ArticleIdList');
00132 XMLCustomWriter::appendChild($root, $articleIdListNode);
00133
00134 $articleIdNode = &XMLCustomWriter::createChildWithText($doc, $articleIdListNode, 'ArticleId', $article->getPublicArticleId());
00135 XMLCustomWriter::setAttribute($articleIdNode, 'IdType', 'pii');
00136 }
00137
00138
00139 $historyNode = &XMLCustomWriter::createElement($doc, 'History');
00140 XMLCustomWriter::appendChild($root, $historyNode);
00141
00142
00143 $receivedNode =& PubMedExportDom::generatePubDateDom($doc, $article->getDateSubmitted(), 'received');
00144 XMLCustomWriter::appendChild($historyNode, $receivedNode);
00145
00146
00147 $editordecisions = $editorSubmissionDao->getEditorDecisions($article->getArticleId());
00148
00149
00150 $editordecision = array_pop($editordecisions);
00151 while ($editordecision['decision'] != SUBMISSION_EDITOR_DECISION_ACCEPT && count($editordecisions) > 0) $editordecision = array_pop($editordecisions);
00152
00153 if ($editordecision != '') {
00154 $acceptedNode =& PubMedExportDom::generatePubDateDom($doc, $editordecision['dateDecided'], 'accepted');
00155 XMLCustomWriter::appendChild($historyNode, $acceptedNode);
00156 }
00157
00158
00159
00160 $revisedFileID = $article->getRevisedFileId();
00161 if (!empty($revisedFileID)) {
00162 $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00163 $articleFile = &$articleFileDao->getArticleFile($revisedFileID);
00164
00165 $revisedNode =& PubMedExportDom::generatePubDateDom($doc, $articleFile->getDateModified(), 'revised');
00166 XMLCustomWriter::appendChild($historyNode, $revisedNode);
00167 }
00168
00169
00170 if ($article->getArticleAbstract()) {
00171 $abstractNode = XMLCustomWriter::createChildWithText($doc, $root, 'Abstract', strip_tags($article->getArticleAbstract()), false);
00172 }
00173
00174 return $root;
00175 }
00176
00177 function &generateAuthorDom(&$doc, &$author) {
00178 $root = &XMLCustomWriter::createElement($doc, 'Author');
00179
00180 XMLCustomWriter::createChildWithText($doc, $root, 'FirstName', ucfirst($author->getFirstName()));
00181 XMLCustomWriter::createChildWithText($doc, $root, 'MiddleName', ucfirst($author->getMiddleName()), false);
00182 XMLCustomWriter::createChildWithText($doc, $root, 'LastName', ucfirst($author->getLastName()));
00183
00184 if ($author->getPrimaryContact()) {
00185 XMLCustomWriter::createChildWithText($doc, $root, 'Affiliation', $author->getAffiliation() . '. ' . $author->getEmail(), false);
00186 }
00187
00188 return $root;
00189 }
00190
00191 function &generatePubDateDom(&$doc, $pubdate, $pubstatus) {
00192 $root = &XMLCustomWriter::createElement($doc, 'PubDate');
00193
00194 XMLCustomWriter::setAttribute($root, 'PubStatus', $pubstatus);
00195
00196 XMLCustomWriter::createChildWithText($doc, $root, 'Year', date('Y', strtotime($pubdate)) );
00197 XMLCustomWriter::createChildWithText($doc, $root, 'Month', date('m', strtotime($pubdate)), false );
00198 XMLCustomWriter::createChildWithText($doc, $root, 'Day', date('d', strtotime($pubdate)), false );
00199
00200 return $root;
00201 }
00202
00203 }
00204
00205 ?>