X-Git-Url: http://git.kpe.io/?p=pubmed.git;a=blobdiff_plain;f=pubmed.lisp;h=1cdd1f6956fdca2b77fa92a57dd3e6ce524e1878;hp=88dcb611b4c13a41cb415fc7c9699759506101c7;hb=b83e11568554b44f6ef128655db363d180eb58c0;hpb=37a3c5ac3af60506f670d838f1f3616a3d6a8203 diff --git a/pubmed.lisp b/pubmed.lisp index 88dcb61..1cdd1f6 100644 --- a/pubmed.lisp +++ b/pubmed.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Jun 2001 ;;;; -;;;; $Id: pubmed.lisp,v 1.4 2002/10/31 20:53:03 kevin Exp $ +;;;; $Id: pubmed.lisp,v 1.7 2002/11/06 19:36:53 kevin Exp $ ;;;; ;;;; This file, part of cl-pubmed, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -26,6 +26,7 @@ ;; Conditions #:pubmed-condition + #:pubmed-query-error #:pubmed-server-error ;; Query functions @@ -81,6 +82,15 @@ (format stream "A PubMed server error occurred.") (awhen (pubmed-server-error-response c) (format stream " The server response was:~&~S" it))))) + +(define-condition pubmed-query-error (error pubmed-condition) + ((response :initarg :response + :initform nil + :reader pubmed-query-error-response)) + (:report (lambda (c stream) + (format stream "A PubMed server error occurred.") + (awhen (pubmed-query-error-response c) + (format stream " The server response was:~&~S" it))))) ;;; Article-Set and Article Classes @@ -145,44 +155,47 @@ "Display an article set to specified stream in specified format" (dotimes (i (articles-count artset)) (print-article (nth i (articles artset)) :os os :format format - :complete complete :print-link print-link))) + :complete complete :print-link print-link)) + artset) (defmethod print-article ((art pm-article) &key (os *standard-output*) (format :text) (complete nil) (print-link t)) "Display an article" - (if (eql format :text) - (format os "~a~%~a~%~a~a ~a~%~a~%" - (article-title art) - (list-to-delimited-string (article-authors art) ", ") - (aif (article-affiliation art) - (format nil "~a~%" it) "") - (article-journal art) (article-ref art) - (aif (article-abstract art) + (ecase format + (:text + (format os "~a~%~a~%~a~a ~a~%~a~%" + (article-title art) + (list-to-delimited-string (article-authors art) ", ") + (aif (article-affiliation art) + (format nil "~a~%" it) "") + (article-journal art) (article-ref art) + (aif (article-abstract art) (if complete it "Abstract available") - "No abstract available") - (when complete - (format os "~a~%" (article-mesh-headings art)))) - - (let ((has-link (or (article-abstract art) (article-mesh-headings art)))) - (when (and print-link has-link) - (format os "" (make-url "print-article") (article-pmid art))) - (format os "
~a
~%" (article-title art)) - (when (and print-link has-link) - (format os "
")) - (format os "
~a
~%" - (list-to-delimited-string (article-authors art) ", ")) - (format os "
~a ~a
~%" - (article-journal art) (article-ref art)) - (when (and complete (article-abstract art)) - (format os "
~a
~%" - (article-abstract art))) - (when (and complete (article-mesh-headings art)) - (format os "
Mesh Headings:
") - (dolist (mh (article-mesh-headings art)) - (format os "
~a
~%" mh))) - (format os "

~%")))) + "No abstract available") + (when complete + (format os "~a~%" (article-mesh-headings art))))) + (:html + (let ((has-link (or (article-abstract art) (article-mesh-headings art)))) + (when (and print-link has-link) + (format os "" (make-url "print-article") (article-pmid art))) + (format os "

~a
~%" (article-title art)) + (when (and print-link has-link) + (format os "")) + (format os "
~a
~%" + (list-to-delimited-string (article-authors art) ", ")) + (format os "
~a ~a
~%" + (article-journal art) (article-ref art)) + (when (and complete (article-abstract art)) + (format os "
~a
~%" + (article-abstract art))) + (when (and complete (article-mesh-headings art)) + (format os "
Mesh Headings:
") + (dolist (mh (article-mesh-headings art)) + (format os "
~a
~%" mh))) + (format os "

~%")))) + art) ;;; PubMed Query Functions @@ -368,11 +381,14 @@ XML string of PubMed search results and XML search status" (defun extract-pmid-list (results) "Returns list of PubMed ID's from XML result string" - (if (or (search "" results) - (search "

Server Error

" results)) - (error 'pubmed-server-error :response results) + (cond + ((search "" results) + (error 'pubmed-query-error :response results)) + ((search "

Server Error

" results) + (error 'pubmed-server-error :response results)) + (t (awhen (xml-tag-contents "Id" results) - (delimited-string-to-list it #\space)))) + (delimited-string-to-list it #\space)))))