about summary refs log tree commit diff
path: root/uploader/templates
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-04-28 12:01:35 -0500
committerFrederick Muriuki Muriithi2025-04-28 12:23:22 -0500
commitd0f6576021d9d6e5b077a736618a8681bb26d42d (patch)
treeef736c8fc5166be37a1aecf1acbd856a9f9ef20e /uploader/templates
parent1695e07c1de3ed806311b3ebc9ed93f8c8833458 (diff)
downloadgn-uploader-d0f6576021d9d6e5b077a736618a8681bb26d42d.tar.gz
Move functions to fetch pubmed data out into a separate js file.
Diffstat (limited to 'uploader/templates')
-rw-r--r--uploader/templates/phenotypes/add-phenotypes-base.html129
1 files changed, 0 insertions, 129 deletions
diff --git a/uploader/templates/phenotypes/add-phenotypes-base.html b/uploader/templates/phenotypes/add-phenotypes-base.html
index 6be9cb0..8f50882 100644
--- a/uploader/templates/phenotypes/add-phenotypes-base.html
+++ b/uploader/templates/phenotypes/add-phenotypes-base.html
@@ -177,135 +177,6 @@
       }
   });
 
-  var extract_details = (pubmed_id, details) => {
-      var months = {
-          "jan": "January",
-          "feb": "February",
-          "mar": "March",
-          "apr": "April",
-          "may": "May",
-          "jun": "June",
-          "jul": "July",
-          "aug": "August",
-          "sep": "September",
-          "oct": "October",
-          "nov": "November",
-          "dec": "December"
-      };
-      var _date = details[pubmed_id].pubdate.split(" ");
-      return {
-          "authors": details[pubmed_id].authors.map((authobj) => {
-              return authobj.name;
-          }),
-          "title": details[pubmed_id].title,
-          "journal": details[pubmed_id].fulljournalname,
-          "volume": details[pubmed_id].volume,
-          "pages": details[pubmed_id].pages,
-          "month": _date.length > 1 ? months[_date[1].toLowerCase()] : "jan",
-          "year": _date[0],
-      };
-  };
-
-  var update_publication_details = (details) => {
-      Object.entries(details).forEach((entry) => {;
-          switch(entry[0]) {
-          case "authors":
-              $("#txt-publication-authors").val(entry[1].join(", "));
-              break;
-          case "month":
-              $("#select-publication-month")
-                  .children("option")
-                  .each((index, child) => {
-                      child.selected = child.value == entry[1].toLowerCase();
-                  });
-          default:
-              $("#txt-publication-" + entry[0]).val(entry[1]);
-              break;
-          }
-      });
-  };
-
-  var fetch_publication_abstract = (pubmed_id, pub_details) => {
-      $.ajax("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi",
-             {
-                 "method": "GET",
-                 "data": {
-                     "db": "pubmed",
-                     "id": pubmed_id,
-                     "rettype": "abstract",
-                     "retmode": "xml"
-                 },
-                 "success": (data, textStatus, jqXHR) => {
-                     update_publication_details({
-                         ...pub_details,
-                         ...{
-                             "abstract": Array.from(data
-                                                    .getElementsByTagName(
-                                                        "Abstract")[0]
-                                                    .children)
-                                 .map((elt) => {return elt.textContent.trim();})
-                                 .join("\r\n")
-                         }});
-                 },
-                 "error": (jqXHR, textStatus, errorThrown) => {},
-                 "complete": (jqXHR, textStatus) => {},
-                 "dataType": "xml"
-             });
-  };
-
-  var fetch_publication_details = (pubmed_id, complete_thunks) => {
-      error_display = $("#search-pubmed-id-error");
-      error_display.text("");
-      add_class(error_display, "visually-hidden");
-      $.ajax("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi",
-             {
-                 "method": "GET",
-                 "data": {"db": "pubmed", "id": pubmed_id, "format": "json"},
-                 "success": (data, textStatus, jqXHR) => {
-                     // process and update publication details
-                     hasError = (
-                         Object.hasOwn(data, "error") ||
-                             Object.hasOwn(data.result[pubmed_id], "error"));
-                     if(hasError) {
-                         error_display.text(
-                             "There was an error fetching a publication with " +
-                                 "the given PubMed ID! The error received " +
-                                 "was: '" + (
-                                     data.error ||
-                                         data.result[pubmed_id].error) +
-                                 "'. Please check ID you provided and try " +
-                                 "again.");
-                         remove_class(error_display, "visually-hidden");
-                     } else {
-                         fetch_publication_abstract(
-                             pubmed_id,
-                             extract_details(pubmed_id, data.result));
-                     }
-                 },
-                 "error": (jqXHR, textStatus, errorThrown) => {},
-                 "complete": () => {
-                     complete_thunks.forEach((thunk) => {thunk()});
-                 },
-                 "dataType": "json"
-             });
-  };
-
-  $("#btn-search-pubmed-id").on("click", (event) => {
-      event.preventDefault();
-      var search_button = event.target;
-      var pubmed_id = $("#txt-pubmed-id").val().trim();
-      remove_class($("#txt-pubmed-id").parent(), "has-error");
-      if(pubmed_id == "") {
-          add_class($("#txt-pubmed-id").parent(), "has-error");
-          return false;
-      }
-
-      search_button.disabled = true;
-      // Fetch publication details
-      fetch_publication_details(pubmed_id,
-                                [() => {search_button.disabled = false;}]);
-      return false;
-  });
 </script>
 
 {%block more_javascript%}{%endblock%}