-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnlm-citation-machine.html
More file actions
166 lines (153 loc) · 5.94 KB
/
nlm-citation-machine.html
File metadata and controls
166 lines (153 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
layout: default
title: Team Nexus - NLM Citation Machine
---
<link rel="stylesheet" href="/css/citation.css"/>
<meta name="description" content="Automagically generate an NLM citation using a PubMed ID or an ISBN."/>
</head>
<body>
<!-- Facebook Like Script -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Google +1 Script -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- background tint-->
<div class="overlay"></div>
<!-- awesome zoom box navbar! -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div id="projects-btn" class="box">
Projects
<span class="top"></span>
<span class="right"></span>
<span class="bottom"></span>
<span class="left"></span>
<a href="http://teamnex.us/#projects" class="boxlink"></a>
</div>
</div>
</nav>
<!-- Google +1 and Facebook Like buttons -->
<div class="social">
<span class="fb-like" data-href="http://teamnex.us/nlm-citation-machine" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false" style="vertical-align:top !important"></span>
<span class="g-plusone" data-size="medium" data-annotation="bubble"></span>
</div>
<!-- citation form -->
<div id="citation-container">
<div id="nlm-description">
<h2>NLM Citation Machine</h2>
<p>Generate NLM style citations for articles in <a href="http://www.ncbi.nlm.nih.gov/pubmed">PubMed</a> and books in <a href="https://books.google.com">Google Books</a>.</p>
<p>Enter PubMed ID or ISBN. Click generate. Simple.</p>
<p>Useful references:</p>
<ul>
<li>DiPiro: 1259587495</li>
<li>ACC/AHA Hypertension: 29146535</li>
<li>AACE Diabetes: 25877012</li>
<li>CHEST: 22315268</li>
<li>ACC/AHA Cholesterol: 24239923</li>
<li>NLA Dyslipidemia Part 1: 25911072</li>
<li>Beer's Criteria: 26446832</li>
</ul>
<p>Recommendations for the website? Email me at: <a href="mailto:alec@teamnex.us">alec@teamnex.us</a></p>
</div>
<form id="citation-form">
<div class="search-form row">
<div class="form-group col-md-9">
<input type="text" id="query" class="form-control" placeholder="Enter PubMed ID or ISBN here:">
</div>
<div class="col-md-3">
<button type="button" id="generate-btn" class="btn" onclick="generateCitation()">Generate!</button>
</div>
</div>
<textarea readonly id="citation" rows="5"></textarea>
</form>
</div>
<script>
$('#citation-form').submit(function() {
generateCitation();
return false;
})
function Get(yourUrl){
var Httpreq = new XMLHttpRequest();
Httpreq.open("GET",yourUrl,false);
Httpreq.send(null);
return Httpreq.responseText;
}
function generateCitation() {
var search = document.getElementById('query').value;
function isInteger(num) {
return (num ^ 0) === num;
}
// determines if input is ISBN or PubMedID
if (isInteger(parseInt(search))) { // ISBN citation
var search_length = search.length;
if (search_length === 10 || search_length === 13) {
// parse JSON into js object
var json_obj = JSON.parse(Get('https://www.googleapis.com/books/v1/volumes?q=isbn:' + search));
// isolate nested book object
var book = json_obj.items[0].volumeInfo;
// arrange author names
var author_count = 0;
var name_nlm = "";
for (name in book.authors) {
var name_array = book.authors[name].split(" ");
// if (author_count < 3) {
name_nlm = name_nlm.concat(name_array[name_array.length - 1] + ' ' + name_array[0].charAt(0));
// } else if(author_count === 4){
// name_nlm = name_nlm.concat('et al');
// }
author_count++;
if (author_count === book.authors.length) {
name_nlm = name_nlm.concat('. ')
} else if (author_count < book.authors.length) {
name_nlm = name_nlm.concat(', ')
}
}
// generate NLM book citation
var citation = name_nlm + book.title + '. ' + book.publisher + '; ' + book.publishedDate + '. ' + book.pageCount + ' p.';
} else { // PubMed citation
// parse JSON into js object
var json_obj = JSON.parse(Get('https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&rettype=abstract&id=' + search));
// isolate nested article object
var article = json_obj.result[search];
// arrange author names
var author_count = 0;
var name_nlm = "";
var next_author;
for (name in article.authors) {
name_nlm = name_nlm.concat(article.authors[name].name);
if (article.authors[author_count].authtype === 'CollectiveName' && author_count+1 === article.authors.length) {
name_nlm = name_nlm.concat(' ')
} else if (article.authors[author_count].authtype !== 'CollectiveName' && author_count+1 === article.authors.length) {
name_nlm = name_nlm.concat('. ')
} else if (article.authors[author_count+1].authtype === 'CollectiveName') {
name_nlm = name_nlm.concat('; ')
} else {
name_nlm = name_nlm.concat(', ')
}
author_count++;
}
// generate NLM article citation depending if volume and issue are variables
var citation = name_nlm + article.title + ' ' + article.source + '. ' + article.pubdate;
if (article.volume !== '') {
citation += ';' + article.volume;
}
if (article.issue != '') {
citation += '(' + article.issue + ')';
}
if (article.pages != '') {
citation += ':' + article.pages;
}
citation += '.';
}
}
// print citation
// console.log(citation);
document.getElementById('citation').value = citation;
}
</script>