Модуль:MedResources (Bk;rl,&MedResources)

Перейти к навигации Перейти к поиску
Документация

Примеры

[править код]



См. также

[править код]
local p = {}
local formatter = require('Модуль:WDFormat')
local f = formatter.f
local wikidata = require('Модуль:WDCommon')
local source = require('Модуль:MedResources/WDMedResources')

local function formatItemLang(source, processedData, result)
	local components = processedData.fieldTable.components
	if not components then
		return
	end
	local langTable = components.lang
	if not langTable then
		return
	end
	if table.getn(langTable) > 0 then
		local lang = wikidata.abbr(langTable[1].entity, 'ru')
		result.text = result.text .. ' [' .. lang  .. ' и др.]'
		local langTag = mw.html.create('small'):addClass('ref-info'):attr('title', langTable[1].value)
				:wikitext('[' .. lang  .. ' и др.]')
		result.wikitext = result.wikitext .. ' ' .. tostring(langTag)
	else
		local lang = wikidata.abbr(langTable.entity, 'ru')
		result.text = result.text .. ' [' .. lang  .. ']'
		local langTag = mw.html.create('small'):addClass('ref-info'):attr('title', langTable.value)
				:wikitext('[' .. lang  .. ']')
		result.wikitext = result.wikitext .. ' ' .. tostring(langTag)
	end
end

local function linkIcd11(source, processedData, result)
	if mw.ustring.match(result.wikitext, '%[') then
		return
	end
	result.wikitext = '[https://icd.who.int/browse11/l-m/en#/http://id.who.int/icd/entity/' .. source.icd11Foundation.value .. ' ' .. result.wikitext .. ']'
end

local function formatResourceTitle(source, processedData, result)
	local components = processedData.fieldTable.components
	if not components or not components.resourceName then
		return
	end

	result.text = components.resourceName.value
	result.wikitext = result.text
end

local function formatResourceTitleWithArticleTitle(source, processedData, result)
	local components = processedData.fieldTable.components
	if not components or not components.resourceName then
		return
	end

	result.text = components.resourceName.value
	if components.title then
		result.text = result.text .. ' (' .. components.title.value .. ')'
	end
	result.wikitext = result.text
end

local rowTag = {
	name = 'tr',
}

local captionTab = {
	name = 'th',
	classes = { 'navbox-group' },
	css = {
		-- make the cell the minimum width
		width = '0',
	},
}

local itemsTag = {
	name = 'td',
	classes = { 'navbox-list', 'navbox-odd' },
	tag = {
		name = 'ul',
	},
}

local itemTag = {
	name = 'li'
}

local profile = {
	tag = {
		name = 'div',
		classes = { 'navbox' },
		attr = { role = 'navigation' },
		tag = {
			name = 'table',
			classes = { 'nowraplinks', 'hlist', 'navbox-inner' },
			css = {
				['border-spacing'] = '0'
			},
		},
	},
	{
		tag = rowTag,
		{
			tag = captionTab,
			value = 'Классификация',
			isStatic = true,
		},
		{
			tag = itemsTag,
			{
				tag = itemTag,
				{
					depends = 'mesh',
					value = 'MeSH',
					entity = 'Q199897',
					forceLang = 'en',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'mesh',
					urlMaskProp = 'P486',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'diseasesDb',
					value = 'Diseases DB',
					entity = 'Q213103',
					forceLang = 'en',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'diseasesDb',
					urlMaskProp = 'P557',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'icd9',
					value = 'МКБ-9',
					entity = 'Q14067712',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'icd9',
					urlMaskProp = 'P493',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'icd10',
					value = 'МКБ-10',
					entity = 'Q45127',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'icd10',
					urlMaskProp = 'P494',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'icd11',
					value = 'МКБ-11',
					entity = 'Q55695727',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'icd11',
					urlMaskProp = 'P7329',
					format = { linkIcd11, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'icd11Foundation',
					value = 'СМК-ВОЗ',
				},
				{
					delimiter = ': ',
					field = 'icd11Foundation',
					urlMaskProp = 'P7807',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'snomedCt',
					value = 'SNOMED CT',
					entity = 'Q1753883',
					forceLang = 'en',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'snomedCt',
					urlMaskProp = 'P5806',
					format = { f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					depends = 'whoEml',
					value = 'eEML',
					entity = 'Q106981966',
					forceLang = 'en',
					format = { f.short, f.wikilink },
				},
				{
					delimiter = ': ',
					field = 'whoEml',
					urlMaskProp = 'P9635',
					format = { f.safeLink, formatItemLang },
				},
			},
		},
	},
	{
		tag = rowTag,
		{
			tag = captionTab,
			value = 'Медицинские ресурсы',
			isStatic = true,
		},
		{
			tag = itemsTag,
			{
				tag = itemTag,
				{
					field = 'medlinePlus',
					urlMaskProp = 'P604',
					format = { formatResourceTitle, f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					field = 'patientUK',
					urlMaskProp = 'P1461',
					format = { formatResourceTitle, f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					field = 'eMedicine',
					urlMaskProp = 'P673',
					format = { formatResourceTitleWithArticleTitle, f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					field = 'omim',
					urlMaskProp = 'P492',
					format = { formatResourceTitleWithArticleTitle, f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					field = 'orphanet',
					urlMaskProp = 'P1550',
					format = { formatResourceTitle, f.safeLink, formatItemLang },
				},
			},
			{
				tag = itemTag,
				{
					field = 'geneReviews',
					urlMaskProp = 'P668',
					format = { formatResourceTitleWithArticleTitle, f.safeLink, formatItemLang },
				},
			},
		},
	},
}

local function argIsEmpty(s)
	return (not s or s == '')
end

local function argIsSet(s)
	return (s and s ~= '')
end

local function valueToTable(value)
	if argIsEmpty(value)then
		return nil
	end
	return { value = value }
end

function p.gen(frame)
	local args = frame.args

	local qid = args.qid
	if not qid or qid == '' then
		qid = mw.wikibase.getEntityIdForCurrentPage()
	end
	
	local s = {
		mesh = valueToTable(args.mesh),
		diseasesDb = valueToTable(args.diseasesDb),
		icd9 = valueToTable(args.icd9),
		icd10 = valueToTable(args.icd10),
		icd11 = valueToTable(args.icd11),
		icd11Foundation = valueToTable(args.icd11Foundation),
		eMedicine = valueToTable(args.eMedicine),
		snomedCt = valueToTable(args.snomedCt),
		medlinePlus = valueToTable(args.medlinePlus),
		patientUK = valueToTable(args.patientUK),
		omim = valueToTable(args.omim),
		orphanet = valueToTable(args.orphanet),
		geneReviews = valueToTable(args.geneReviews),
	}
	if s.geneReviews and argIsSet(args.geneReviewsTitle) then
		s.geneReviews.components = {
			title = { value = args.geneReviewsTitle },
		}
	end
	s = source.fetch(qid, s)

	return formatter.format(profile, s)
end

return p