Help:Hubmed/extension

From Ganfyd

Jump to: navigation, search

Contents

Introduction

The Hubmed extension aims to bring the power of the Hubmed search engine to mediawiki. It is a bit clumsy, but thats because it is written by a medical microbiologist and not a PHP expert! Anybody who wishes to refine/tidy/embellish/rewrite is most welcome to do so. --A.l.brown 11:02, 30 March 2006 (CEST)

Syntax

<hubmed search="(optional)" label="(optional)" free="yes(optional)" terms="(used when search=custom)">Subject to search for</hubmed>

  • All attributes are optional, apart from the <hubmed> and <hubmed> tags, and what goes in between them.

A very basic search

  • <hubmed>Myocardial Infarction</hubmed> = A straight search of Hubmed for Myocardial Infarction:

The 'label' attribute

Allows for custom text to be returned for the link.

  • <hubmed>Myocardial Infarction</hubmed> returns:
  • Research into <hubmed label="heart attacks">Myocardial Infarction</hubmed> can be found here! returns:

The 'free' attribute

free="yes" Allows you to list only those papers which are freely available on the internet. Can of course be combined with other attributes (except search="custom").

  • <hubmed free="yes">Diabetes insipidus</hubmed> returns:

The 'search' attribute

Allows specific search types (search 'recipes' cooked up by User:Jb) but based, principally on the work of Haynes at McMaster - see PubMed's Clinical Queries

  • <hubmed search="rct"> - Looks for randomised controlled trials.
  • <hubmed search="systematic"> - Looks for systematic reviews.
  • <hubmed search="prognosis"> - Looks for papers regarding prognosis.
  • <hubmed search="diagnosis"> - Looks for papers focussing on diagnosis.
  • <hubmed search="aetiology"> or <hubmed search="etiology"> - Looks for papers concentrating on aetiology.
  • <hubmed search="big4"> - Looks for papers from the BMJ, the Lancet, JAMA and the New England Journal of Medicine only.
  • <hubmed search="cochrane"> - Looks for Cochrane reviews only.
  • <hubmed search="none"> - The same as not having the search attribute, i.e. just a plain search.
  • <hubmed search="custom" terms="custom search terms here" label="the text that will appear on screen">.
  • e.g. <hubmed search="rct">Aspirin</hubmed> = A search for randomised controlled trials on Aspirin:
    • For RCTs regarding Aspirin, click here. - NOTE you do not need to do this as for any drug with a PharmacologyBox this link exists automatically, but not coded using this extension for technical reasons.
  • This can be combined with the 'label' attribute, e.g. There have been many <hubmed search="rct" label="Randomised Controlled Trials">Aspirin</hubmed> on one cure for headaches.:

The 'terms' attribute, and 'search="custom"'

To set up a custom search, using your own terms and conditions, use the search="custom" attribute. This must be used in conjunction with the 'terms' condition, which is where you specify your conditions, and with 'label' to give the reader some idea of what you have done.

  • e.g. if you wished to search for Myocardial Infarction AND Aspirin, you could use Here is a list of studies looking at the use of <hubmed search="custom" terms="AND (Aspirin)" label="aspirin in myocardial infarction">Myocardial Infarction</hubmed>.

Templates

{{Hubmed-search|Myocardial Infarction}}

If I can get these to work, then great!

To come

  • Further search types in addition to 'rct', 'systematic', 'custom', 'diagnosis', 'aetiology', 'prognosis', 'big3' and 'none'.
  • Tidying up the code - This needs doing - lots of 'elseif's = sloppy. Needs terms and searchtypes in an array.
  • Maybe the option of using it with things other than Hubmed.
  • What little text there is could do with becoming language-independant.

Code


<?php

/**
 * This file contains all the bumf for the Hubmed extension of 
 * MediaWiki. 
 *
 * Usage: require_once("path/to/hubmed.php"); in LocalSettings.php
 *
 * This extension requires MediaWiki 1.5 or higher.
 *
 * @author Adam Brown <admin{at}_!NOSPAM!_ganfyd.org>
 * @copyright Public domain
 * @license Public domain
 * @package MediaWikiExtensions
 * @version 0.2.3
 */

 /**
 * Register the Hubmed extension with MediaWiki
 */ 
$wgExtensionFunctions[] = 'registerHubmed';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Hubmed',
'author' => 'Adam Brown',
'description' => 'Allows the use of hubmed searches with ease (not simple to do with templates)',
'url' => 'http://ganfyd.org/index.php?title=Help:Hubmed/extension',
);

/**
 * Sets the tags that this extension looks for and the function by which they
 * operate
 */

function registerHubmed()
{

    global $wgParser;
    $wgParser->setHook('hubmed', 'renderHubmed');
}

/**
 * Render the search based on the <hubmed search="type of search" {terms="search terms" label="search term label"}>Search subject</hubmed> tag (terms &label optional and used if search="custom")
 */
 function renderHubmed($input, $argv) {

	$hubmed_output = ''; //Just to make sure it is set.
		
	$hubmed_searchtype = $argv["search"];
	$hubmed_searchtype = strtolower($hubmed_searchtype); //Well _somebody_ will use upper case!
	$hubmed_searchterms = $argv["terms"];
	$hubmed_searchterms = strtolower($hubmed_searchterms); //Ditto!
	$hubmed_searchterms_plus = str_replace(" ", "+", $hubmed_searchterms); //Hubmed uses '+' instead of ' ' in searches
	$hubmed_searchlabel = $argv["label"];
	$hubmed_subject = $input;
	$hubmed_subject_plus = str_replace(" ", "+", $hubmed_subject);
	$hubmed_free = $argv["free"];
	$hubmed_free = strtolower($hubmed_free);

	if ($hubmed_free != '') {
		$free_terms = '+AND+free+full+text[filter]';
	} else { 
		$free_terms = '';
	}
	
	//Define the root of out hubmed searches:
	$hubmed_root = 'http://www.hubmed.org/search.cgi?q=%28';

	//Define our searches (could probably be done more neatly with an array, but I can't be arsed):
	$rct_terms = '%29+AND+%28randomized+controlled+trial%5BPublication+Type%5D+OR+%28randomized%5BTitle%2FAbstract%5D+AND+controlled%5BTitle%2FAbstract%5D+AND+trial%5BTitle%2FAbstract%5D%29%29&sort=date';
	$systematic_terms = '%29+AND+systematic%5Bsb%5D';
	$prognosis_terms = '%29+AND+%28prognos*%5BTitle%2FAbstract%5D+OR+%28first%5BTitle%2FAbstract%5D+AND+episode%5BTitle%2FAbstract%5D%29+OR+cohort%5BTitle%2FAbstract%5D%29&sort=date';
	$diagnosis_terms = '%29+AND+%28specificity%5BTitle%2FAbstract%5D%29';
	$aetiology_terms ='%29+AND+%28%28relative%5BTitle%2FAbstract%5D+AND+risk*%5BTitle%2FAbstract%5D%29+OR+%28relative+risk%5BText+Word%5D%29+OR+risks%5BText+Word%5D+OR+cohort+studies%5BMeSH%3Anoexp%5D+OR+%28cohort%5BTitle%2FAbstract%5D+AND+stud*%5BTitle%2FAbstract%5D%29%29';
	$big4_terms = '%29+AND+%28%28JAMA%5Bta%5D%29+OR+%28N+Engl+J+Med%5Bta%5D%29+OR+%28Lancet%5Bta%5D%29+OR+%28BMJ%5Bta%5D%29%29';
	$cochrane_terms = '%29+AND+%28Cochrane+Database+Syst+Rev%5Bta%5D%29';
	$none_terms = '%29';
	
	//Check to see if there is a label:
	if ($hubmed_searchlabel != '') {
		
		//If there is, go through the options:
		
		if ($hubmed_searchtype == 'rct') { 
			//1. RCT search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $rct_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'systematic') { 
			//2. Systematic review
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $systematic_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'none' || $hubmed_searchtype == '') { 
			//3. No extras, just a straight search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $none_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'custom') {
			//4. Custom defined search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . '%29+' . $hubmed_searchterms_plus . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'prognosis') {
			//5. Prognosis search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $prognosis_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'diagnosis') {
			//6. Diagnosis search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $diagnosis_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'aetiology' || $hubmed_searchtype  == 'etiology') {
			//7. Aetiology search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $aetiology_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'big4') {
			//8. BMJ + Lancet + NEJM + JAMA search
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $big4_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} elseif ($hubmed_searchtype == 'cochrane') {
			//9. Cochrane reviews
			$hubmed_output = '<a href="' . $hubmed_root . $hubmed_subject_plus . $cochrane_terms . $free_terms . '" target="_blank">' . $hubmed_searchlabel . '</a>';

		} else {
			//10. An unknown search type was specified, so return an error to make this obvious
			$hubmed_output ='<b>Unknown search option, please check your spelling</b>';
		}

	} else {

		//If there isn't a label, go through the options with the standard text:

		if ($hubmed_searchtype == 'rct') {
			//1. RCT search
			$hubmed_output = 'For RCTs regarding ' . $hubmed_subject . ', <a href="' . $hubmed_root . $hubmed_subject_plus . $rct_terms . $free_terms . '" target="_blank">click here</a>.';

		} elseif ($hubmed_searchtype == 'systematic') {
			//2. Systematic review
			$hubmed_output = 'For systematic reviews regarding ' . $hubmed_subject . ', <a href="' . $hubmed_root . $hubmed_subject_plus . $systematic_terms . $free_terms . '" target="_blank">click here</a>.';

		} elseif ($hubmed_searchtype == 'none' || $hubmed_searchtype == '') { 
			//3. No extras, just a straight search
			$hubmed_output = 'Search hubmed for <a href="' . $hubmed_root . $hubmed_subject_plus . $none_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} elseif ($hubmed_searchtype == 'custom') {
			//4. Custom defined search
			$hubmed_output = 'For ' . $hubmed_searchlabel . 's regarding ' . $hubmed_subject . ', <a href="' . $hubmed_root . $hubmed_subject_plus . '%29+' . $hubmed_searchterms_plus . '" target="_blank">click here</a>.';

		} elseif ($hubmed_searchtype == 'prognosis') {
			//5. Prognosis search
			$hubmed_output = 'Search hubmed for prognosis-related data on <a href="' . $hubmed_root . $hubmed_subject_plus . $prognosis_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} elseif ($hubmed_searchtype == 'diagnosis') {
			//6. Diagnosis search
			$hubmed_output = 'Search hubmed for diagnosis-related data on <a href="' . $hubmed_root . $hubmed_subject_plus . $diagnosis_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} elseif ($hubmed_searchtype == 'aetiology' || $hubmed_searchtype == 'etiology') {
			//7. Aetiology search
			$hubmed_output = 'Search hubmed for aetiology-related data on <a href="' . $hubmed_root . $hubmed_subject_plus . $aetiology_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} elseif ($hubmed_searchtype == 'big4') {
			//8. BMJ + Lancet + NEJM + JAMA
			$hubmed_output = 'Search hubmed for papers from the BMJ/Lancet/NEJM/JAMA on <a href="' . $hubmed_root . $hubmed_subject_plus . $big4_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} elseif ($hubmed_searchtype == 'cochrane') {
			//9. Cochrane search
			$hubmed_output = 'Search hubmed for Cochrane reviews on <a href="' . $hubmed_root . $hubmed_subject_plus . $cochrane_terms . $free_terms . '" target="_blank">' . $hubmed_subject . '</a>';

		} else {
			//10. An unknown search type was specified, so return an error to make this obvious
			$hubmed_output ='<b>Unknown search option, please check your spelling</b>';
		}

	}
		
	//Finally, return our output:
	return $hubmed_output;
	
 }

//And thats it. Further hooks with very similar logic could be added for (for example), pubmed.
?>