Mòdul:Medical infotable items

De Viquipèdia
Salta a la navegació Salta a la cerca
local p = {}
local SA = require "Module:SimpleArgs"
local WD = require 'Module:Wikidata'
local SD = require 'Module:SimpleDebug'

p.i18n = {
	["ArgMesh"] = {
		["MeshName"]	= "MeshName",
		["MeshNumber"]	= "MeshNumber",
		["MeSH1"]		= {"MeshID","MeSH","MeSH1"},
		["MeshYear1"]	= {"MeshYear","MeshYear1"},
		["MeSH"]		= "MeSH",
		["MeshYear"]	= "MeshYear",
	},
	["ArgeMed"] = {
		["eMedicineSubj"]  = "eMedicineSubj",
		["eMedicineTopic"] = "eMedicineTopic",
		["eMedicine_mult"] = "eMedicine_mult",
	},	
	["ArgGene"] = {
		["GeneReviewsID"]	= "GeneReviewsID",
		["GeneReviewsNBK"]	= "GeneReviewsNBK",
		["GeneReviewsName"]	= "GeneReviewsName",
	},	
	["Labels"] = {
		["Mesh"]		= "[[Medical Subject Headings|MeSH]]",
		["eMedicine"]	= "[[eMedicine]]",
		["GeneReviews"]	= "[[GeneReviews]]",
	},
}
p.i18n = SA.loadI18n ('Medical infotable items', p.i18n)
for i = 2, 9 do
	p.i18n["ArgMesh"]["MeSH"..i] = p.i18n["ArgMesh"]["MeSH"]..i
	p.i18n["ArgMesh"]["MeshYear"..i] = p.i18n["ArgMesh"]["MeshYear"]..i
end	
for i = 2, 9 do
	p.i18n["ArgGene"]["GeneReviewsNBK"..i] = p.i18n["ArgGene"]["GeneReviewsNBK"]..i
	p.i18n["ArgGene"]["GeneReviewsName"..i] = p.i18n["ArgGene"]["GeneReviewsName"]..i
end	

local function I18nArgMesh (S)
	return SA.CheckIsStrOrTab (p.i18n["ArgMesh"][S], S)
end

local function I18nArgeMed (S)
	return SA.CheckIsStrOrTab (p.i18n["ArgeMed"][S], S)
end

local function I18nArgGene (S)
	return SA.CheckIsStrOrTab (p.i18n["ArgGene"][S], S)
end

local function I18nLabel (S)
	return SA.CheckIsStr (p.i18n["Labels"][S], S)
end

function p.eMedicine (frame, args, tab, DataLabelN)
	local Subj = SA.Str_Par (args, I18nArgeMed('eMedicineSubj'))
	if Subj == nil then
		res = WD.claim ({property='P673', formatting='[http://emedicine.medscape.com/article/$1 $1]'})
	else	
		local Topic = SA.Str_Par (args, I18nArgeMed('eMedicineTopic'))
		local mult = SA.Str_Par (args, I18nArgeMed('eMedicine_mult'))
		if Subj == 'search' then
			res = '[http://search.medscape.com/emedicine-search?queryText='..Topic..' topic list]'
		else
			if Subj == 'article' then
				res = '[http://emedicine.medscape.com/article/'..Topic..'-overview'
			else
				res = '[http://www.emedicine.com/'..Subj..'/topic'..Topic..'.htm'
			end	
			res = res..' '..Subj..'/'..Topic..']'
		end
		res = res..' '..mult
	end
	if (res ~= nil) and (res ~= '') then
		tab['label'..DataLabelN] = I18nLabel('eMedicine')
		tab['data'..DataLabelN] = res
	end	
	return tab
end --eMedicine	

function p.mesh (frame, args, tab, DataLabelN)
	local t = {}
	function meshNYear (N, Year)
		table.insert (t, frame:expandTemplate {
		    title = 'mesh2',
		    args = {N, year=Year}})
	end	
	function meshNNum (N, Num)
		table.insert (t, "''"..frame:expandTemplate {
		    title = 'mesh2',
		    args = {name=N, number=Num}}.."''")
	end	
	for i = 1, 9 do
		local MeshId = SA.Str_Par (args, I18nArgMesh('MeSH'..i), nil)
		local MeshYear = SA.Str_Par (args, I18nArgMesh('MeshYear'..i), nil)
		if MeshId == nil then
			break
		else	
			meshNYear (MeshId, MeshYear)	
		end	
	end	
	local MeshName = SA.Str_Par (args, I18nArgMesh('MeshName'), nil)
	local MeshNumber = SA.Str_Par (args, I18nArgMesh('MeshNumber'), nil)
	if MeshName ~= nil then
		meshNNum (MeshName, MeshNumber)	
	end	
	if #t == 0 then
		local res = ''
		res = WD.claim ({property='P486', formatting='[https://www.nlm.nih.gov/cgi/mesh/'..os.date('%Y')..'/MB_cgi?field=uid&term=$1 $1]'})
		if res ~= '' then
			table.insert (t, res)
		end	
	end
	if #t ~= 0 then
		tab['label'..DataLabelN] = I18nLabel('Mesh')
		tab['data'..DataLabelN] = table.concat (t, ', ')
	end	
	return tab
end --mesh

function p.gene (frame, args, tab, DataLabelN)
	local t = {}
	local ID = SA.Str_Par (args, I18nArgGene('GeneReviewsID'), nil)
	local NBK = SA.Str_Par (args, I18nArgGene('GeneReviewsNBK'), nil)
	local Name = SA.Str_Par (args, I18nArgGene('GeneReviewsName'), nil)
	function NCBIBook2 (ANBK, AName)
		table.insert (t, "* "..frame:expandTemplate {
		    title = 'NCBIBook2',
		    args = {ANBK, AName}})
	end	
	if NBK ~= nil then
		NCBIBook2 (NBK, Name)
		if ID ~= nil then
			table.insert (t, "* "..'[http://www.ncbi.nlm.nih.gov/books/n/gene/'..ID..']')
		end	
		for i = 2, 9 do
			local NBK = SA.Str_Par (args, I18nArgGene('GeneReviewsNBK'..i), nil)
			local Name = SA.Str_Par (args, I18nArgGene('GeneReviewsName'..i), nil)
			if NBK == nil then
				break
			else	
				NCBIBook2 (NBK, Name)	
			end	
		end	
	end	
	if #t == 0 then
		local res = ''
		res = WD.claim ({property='P668', formatting='[https://www.ncbi.nlm.nih.gov/books/$1 Panoramica]'})
		if res ~= '' then
			table.insert (t, res)
		end	
	end
	if #t ~= 0 then
		tab['label'..DataLabelN] = I18nLabel('GeneReviews')
		tab['class'..DataLabelN] = 'plainlist'
		tab['data'..DataLabelN] = table.concat (t, ', ')
	end	
	return tab
end --gene

return p