Module:MedicoInfobox: Difference between revisions
From determinar.ia.br - Determine suas informações
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:MedicoInfobox — | -- Module:MedicoInfobox v2 — links via [URL texto] (tag <a> crua NÃO é permitida no wikitext) | ||
local p = {} | local p = {} | ||
local CFG = { | local CFG = { | ||
foto = 'P1', -- localMedia | foto = 'P1', -- localMedia | ||
nome = 'P2', -- monolingualtext | nome = 'P2', -- monolingualtext | ||
registro = 'P4', -- monolingualtext | registro = 'P4', -- monolingualtext | ||
especialidade = 'P10', -- wikibase-item | especialidade = 'P10', -- wikibase-item | ||
subesp = 'P11', -- wikibase-item | subesp = 'P11', -- wikibase-item | ||
servicos = { 'P13', 'P14', 'P18', 'P19', 'P23' }, | servicos = { 'P13', 'P14', 'P18', 'P19', 'P23' }, | ||
logradouro = 'P28', | logradouro = 'P28', | ||
bairro = 'P29', | bairro = 'P29', | ||
email = 'P30', | email = 'P30', | ||
website = 'P31', | website = 'P31', | ||
agendamento = 'P32', | agendamento = 'P32', | ||
lat = 'P33', | lat = 'P33', | ||
lon = 'P34', | lon = 'P34', | ||
convenio = 'P35', | convenio = 'P35', | ||
estado = 'P36', | estado = 'P36', | ||
operadora = 'P37', | operadora = 'P37', | ||
opinioes = 'P38', | opinioes = 'P38', | ||
estrelas = 'P39', | estrelas = 'P39', | ||
duvidas = 'P40', | duvidas = 'P40', | ||
doctoralia = 'P57', | doctoralia = 'P57', | ||
municipio = 'P71', | municipio = 'P71', | ||
cep = 'P72', | cep = 'P72', | ||
bio = 'P73', | bio = 'P73', | ||
escopo_neg = 'P74', | escopo_neg = 'P74', | ||
maps_cid = 'P75', | maps_cid = 'P75', | ||
horario = 'P76', | horario = 'P76', | ||
publicacoes = 'P77', | publicacoes = 'P77', | ||
scholar_user = 'P62', | scholar_user = 'P62', | ||
fonte = 'P79', | fonte = 'P79', | ||
coleta = 'P80', | coleta = 'P80', | ||
} | } | ||
-- == | |||
-- Chips indesejados (dados misturados no Q1: operadoras e itens de endereço) | |||
local EXCLUIR_CHIPS = { 'unimed', 'vivest', 'seguros' } | |||
local function contemLixo( s ) | |||
local ls = string.lower( s or '' ) | |||
for _, pad in ipairs( EXCLUIR_CHIPS ) do | |||
if ls:find( pad, 1, true ) then return true end | |||
end | |||
return ls:find( 'rua ' ) or ls:find( 'avenida' ) or ls:find( 'av. ' ) or false | |||
end | |||
local function esc( s ) | local function esc( s ) | ||
if not s then return '' end | if not s then return '' end | ||
return mw.text.encode( tostring( s ), '<>&"' ) | return mw.text.encode( tostring( s ), '<>&"' ) | ||
end | |||
-- Link externo na sintaxe oficial do wikitext: [URL texto] | |||
local function linkExterno( url, texto ) | |||
if not url or url == '' then return '' end | |||
return '[' .. url .. ' ' .. texto .. ']' | |||
end | end | ||
local function rotulo( ent, lang ) | local function rotulo( ent, lang ) | ||
if not ent then return nil end | if not ent then return nil end | ||
for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do | for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do | ||
local lb = ent:getLabel( l ) | local lb = ent:getLabel( l ) | ||
if lb then return lb end | if lb then return lb end | ||
| Line 61: | Line 68: | ||
local function descricao( ent, lang ) | local function descricao( ent, lang ) | ||
if not ent then return '' end | if not ent then return '' end | ||
for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do | for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do | ||
local d = ent:getDescription( l ) | local d = ent:getDescription( l ) | ||
if d then return d end | if d then return d end | ||
| Line 72: | Line 75: | ||
end | end | ||
local function snakParaTexto( snak, lang ) | local function snakParaTexto( snak, lang ) | ||
if not snak or snak.snaktype ~= 'value' then return nil end | if not snak or snak.snaktype ~= 'value' then return nil end | ||
| Line 92: | Line 94: | ||
end | end | ||
local function valor( ent, pid, lang ) | local function valor( ent, pid, lang ) | ||
if not ent then return nil end | if not ent then return nil end | ||
| Line 104: | Line 105: | ||
end | end | ||
local function valores( ent, pid, lang ) | local function valores( ent, pid, lang ) | ||
local out = {} | local out = {} | ||
| Line 117: | Line 117: | ||
end | end | ||
local function qualificador( ent, pid, qpid, lang ) | local function qualificador( ent, pid, qpid, lang ) | ||
if not ent then return nil end | if not ent then return nil end | ||
| Line 136: | Line 135: | ||
local s = '' | local s = '' | ||
for _, v in ipairs( lista ) do | for _, v in ipairs( lista ) do | ||
s = s .. '<span class="chip-especialidade">' .. esc( v ) .. '</span> ' | if not contemLixo( v ) then | ||
s = s .. '<span class="chip-especialidade">' .. esc( v ) .. '</span> ' | |||
end | |||
end | end | ||
return s | return s | ||
| Line 154: | Line 155: | ||
local ent = mw.wikibase.getEntity( id ~= '' and id or nil ) | local ent = mw.wikibase.getEntity( id ~= '' and id or nil ) | ||
if not ent then | if not ent then | ||
return '<div class="infobox-medico"><div class="infobox-medico-titulo">Entidade não encontrada — informe ID=Q… | return '<div class="infobox-medico"><div class="infobox-medico-titulo">Entidade não encontrada — informe ID=Q…</div></div>' | ||
end | end | ||
| Line 196: | Line 197: | ||
if foto then | if foto then | ||
out[#out + 1] = '<div class="infobox-medico-imagem">' .. frame:preprocess( '[[File:' .. foto .. '|300px|center]]' ) .. '</div>' | out[#out + 1] = '<div class="infobox-medico-imagem">' | ||
.. frame:preprocess( '[[File:' .. foto .. '|300px|center]]' ) .. '</div>' | |||
end | end | ||
| Line 212: | Line 214: | ||
if estrelasN then | if estrelasN then | ||
local nota = '<div class="medico-avaliacao"><span class="medico-estrelas">' .. estrelas( estrelasN ) .. '</span> | local nota = '<div class="medico-avaliacao"><span class="medico-estrelas">' .. estrelas( estrelasN ) | ||
.. '</span> <span class="medico-nota">' .. esc( estrelasN ) .. '/5</span>' | |||
if opinioes then | if opinioes then | ||
nota = nota .. ' · | if doc then | ||
nota = nota .. ' · ' .. linkExterno( doc, opinioes .. ' opiniões' ) | |||
else | |||
nota = nota .. ' · ' .. esc( opinioes ) .. ' opiniões' | |||
end | |||
end | end | ||
out[#out + 1] = nota .. '</div>' | out[#out + 1] = nota .. '</div>' | ||
| Line 245: | Line 251: | ||
if convenio then out[#out + 1] = linha( 'Convênio', esc( convenio ) ) end | if convenio then out[#out + 1] = linha( 'Convênio', esc( convenio ) ) end | ||
if operadora then out[#out + 1] = linha( 'Operadora', esc( operadora ) ) end | if operadora then out[#out + 1] = linha( 'Operadora', esc( operadora ) ) end | ||
if email then out[#out + 1] = linha( 'E-mail', ' | if email then out[#out + 1] = linha( 'E-mail', linkExterno( 'mailto:' .. email, email ) ) end | ||
if website then | if website then | ||
local | local siteHref = website:match( '^https?://' ) and website or ( 'https://' .. website ) | ||
out[#out + 1] = linha( 'Site', | out[#out + 1] = linha( 'Site', linkExterno( siteHref, website ) ) | ||
end | end | ||
if doc then | if doc then | ||
out[#out + 1] = linha( 'Doctoralia', | out[#out + 1] = linha( 'Doctoralia', linkExterno( doc, 'Ver perfil' ) ) | ||
end | end | ||
out[#out + 1] = '</table>' | out[#out + 1] = '</table>' | ||
| Line 265: | Line 271: | ||
if agenda then | if agenda then | ||
out[#out + 1] = '<div class="cta-agendar"> | out[#out + 1] = '<div class="cta-agendar">' .. linkExterno( agenda, 'Agendar consulta' ) .. '</div>' | ||
end | end | ||
-- Mapa | -- Mapa: URL com q=endereço (o formato q=&cid= era rejeitado pelo Google) | ||
if cid and cid ~= '' then | if cid and cid ~= '' then | ||
local mapUrl = 'https://maps.google.com/maps?q=&cid=' .. cid .. '&output=embed&hl=pt-BR' | local endMapa = table.concat( { logradouro, bairro, municipio, estado }, ', ' ) | ||
local mapUrl | |||
if endMapa ~= '' then | |||
mapUrl = 'https://maps.google.com/maps?q=' .. mw.uri.encode( endMapa, 'QUERY' ) | |||
.. '&z=16&output=embed&hl=pt-BR' | |||
else | |||
mapUrl = 'https://maps.google.com/maps?cid=' .. cid .. '&output=embed&hl=pt-BR' | |||
end | |||
local ok, html = pcall( frame.extensionTag, frame, 'perfilexterno', '', { url = mapUrl, largura = '100%', altura = '300' } ) | local ok, html = pcall( frame.extensionTag, frame, 'perfilexterno', '', { url = mapUrl, largura = '100%', altura = '300' } ) | ||
if ok and html and html ~= '' then | if ok and html and html ~= '' then | ||
out[#out + 1] = html | out[#out + 1] = html | ||
else | else | ||
out[#out + 1] = '<div class="infobox-medico-mais"> | out[#out + 1] = '<div class="infobox-medico-mais">' | ||
.. linkExterno( 'https://maps.google.com/maps?cid=' .. cid, 'Ver no Google Maps' ) .. '</div>' | |||
end | end | ||
end | end | ||
| Line 285: | Line 299: | ||
for i = 1, n do | for i = 1, n do | ||
local u = pubs[i] | local u = pubs[i] | ||
out[#out + 1] = '<li> | out[#out + 1] = '<li>' .. linkExterno( u, u:gsub( '^https?://', '' ) ) .. '</li>' | ||
end | end | ||
out[#out + 1] = '</ul>' | out[#out + 1] = '</ul>' | ||
if #pubs > n then | if #pubs > n then | ||
local alvo = scholar and ( 'https://scholar.google.com/citations?user=' .. scholar .. '&hl=pt-BR' ) or ' | local alvo = scholar and ( 'https://scholar.google.com/citations?user=' .. scholar .. '&hl=pt-BR' ) or '' | ||
out[#out + 1] = '<div class="infobox-medico-mais"> | out[#out + 1] = '<div class="infobox-medico-mais">' | ||
.. linkExterno( alvo, '+ ' .. ( #pubs - n ) .. ' publicações' ) .. '</div>' | |||
end | end | ||
end | end | ||
| Line 309: | Line 324: | ||
out[#out + 1] = '</div>' | out[#out + 1] = '</div>' | ||
return | return table.concat( out ) -- sem frame:preprocess no HTML todo; só a imagem precisava | ||
end | end | ||
return p | return p | ||
Revision as of 16:57, 3 August 2026
Documentation for this module may be created at Module:MedicoInfobox/doc
-- Module:MedicoInfobox v2 — links via [URL texto] (tag <a> crua NÃO é permitida no wikitext)
local p = {}
local CFG = {
foto = 'P1', -- localMedia
nome = 'P2', -- monolingualtext
registro = 'P4', -- monolingualtext
especialidade = 'P10', -- wikibase-item
subesp = 'P11', -- wikibase-item
servicos = { 'P13', 'P14', 'P18', 'P19', 'P23' },
logradouro = 'P28',
bairro = 'P29',
email = 'P30',
website = 'P31',
agendamento = 'P32',
lat = 'P33',
lon = 'P34',
convenio = 'P35',
estado = 'P36',
operadora = 'P37',
opinioes = 'P38',
estrelas = 'P39',
duvidas = 'P40',
doctoralia = 'P57',
municipio = 'P71',
cep = 'P72',
bio = 'P73',
escopo_neg = 'P74',
maps_cid = 'P75',
horario = 'P76',
publicacoes = 'P77',
scholar_user = 'P62',
fonte = 'P79',
coleta = 'P80',
}
-- Chips indesejados (dados misturados no Q1: operadoras e itens de endereço)
local EXCLUIR_CHIPS = { 'unimed', 'vivest', 'seguros' }
local function contemLixo( s )
local ls = string.lower( s or '' )
for _, pad in ipairs( EXCLUIR_CHIPS ) do
if ls:find( pad, 1, true ) then return true end
end
return ls:find( 'rua ' ) or ls:find( 'avenida' ) or ls:find( 'av. ' ) or false
end
local function esc( s )
if not s then return '' end
return mw.text.encode( tostring( s ), '<>&"' )
end
-- Link externo na sintaxe oficial do wikitext: [URL texto]
local function linkExterno( url, texto )
if not url or url == '' then return '' end
return '[' .. url .. ' ' .. texto .. ']'
end
local function rotulo( ent, lang )
if not ent then return nil end
for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do
local lb = ent:getLabel( l )
if lb then return lb end
end
return nil
end
local function descricao( ent, lang )
if not ent then return '' end
for _, l in ipairs( { 'pt-br', 'pt', 'mul', lang, 'en' } ) do
local d = ent:getDescription( l )
if d then return d end
end
return ''
end
local function snakParaTexto( snak, lang )
if not snak or snak.snaktype ~= 'value' then return nil end
local dv = snak.datavalue
if not dv then return nil end
if dv.type == 'string' or dv.type == 'url' or dv.type == 'external-id' then
return dv.value
elseif dv.type == 'monolingualtext' then
return dv.value.text
elseif dv.type == 'quantity' then
return tostring( dv.value.amount ):gsub( '^%+', '' )
elseif dv.type == 'time' then
return ( dv.value.time or '' ):match( '(%d+%-%d+%-%d+)' )
elseif dv.type == 'wikibase-entityid' then
local alvo = mw.wikibase.getEntity( dv.value.id )
return rotulo( alvo, lang ) or dv.value.id
end
return nil
end
local function valor( ent, pid, lang )
if not ent then return nil end
local sts = ent:getBestStatements( pid )
if not sts then return nil end
for _, st in ipairs( sts ) do
local v = snakParaTexto( st.mainsnak, lang )
if v and v ~= '' then return v end
end
return nil
end
local function valores( ent, pid, lang )
local out = {}
if not ent then return out end
local sts = ent:getBestStatements( pid )
if not sts then return out end
for _, st in ipairs( sts ) do
local v = snakParaTexto( st.mainsnak, lang )
if v and v ~= '' then out[#out + 1] = v end
end
return out
end
local function qualificador( ent, pid, qpid, lang )
if not ent then return nil end
local sts = ent:getBestStatements( pid )
if not sts or not sts[1] then return nil end
local qs = sts[1].qualifiers
if not qs then return nil end
local lista = qs[qpid]
if not lista then return nil end
for _, q in ipairs( lista ) do
local v = snakParaTexto( q, lang )
if v then return v end
end
return nil
end
local function chips( lista )
local s = ''
for _, v in ipairs( lista ) do
if not contemLixo( v ) then
s = s .. '<span class="chip-especialidade">' .. esc( v ) .. '</span> '
end
end
return s
end
local function estrelas( n )
n = math.floor( tonumber( n ) or 0 )
n = math.max( 0, math.min( 5, n ) )
return string.rep( '★', n ) .. string.rep( '☆', 5 - n )
end
function p.main( frame )
local args = frame.args
local id = ( args.ID or args[1] or '' ):match( '^%s*(.-)%s*$' )
local lang = mw.getContentLanguage():getCode()
local ent = mw.wikibase.getEntity( id ~= '' and id or nil )
if not ent then
return '<div class="infobox-medico"><div class="infobox-medico-titulo">Entidade não encontrada — informe ID=Q…</div></div>'
end
local nome = valor( ent, CFG.nome, lang ) or rotulo( ent, lang ) or '—'
local desc = descricao( ent, lang )
local foto = valor( ent, CFG.foto, lang )
local regs = valores( ent, CFG.registro, lang )
local esp = valor( ent, CFG.especialidade, lang )
local sub = valor( ent, CFG.subesp, lang )
local logradouro = valor( ent, CFG.logradouro, lang )
local bairro = valor( ent, CFG.bairro, lang )
local municipio = valor( ent, CFG.municipio, lang )
local estado = valor( ent, CFG.estado, lang )
local cep = valor( ent, CFG.cep, lang )
local horario = valor( ent, CFG.horario, lang )
local convenio = valor( ent, CFG.convenio, lang )
local operadora = valor( ent, CFG.operadora, lang )
local email = valor( ent, CFG.email, lang )
local website = valor( ent, CFG.website, lang )
local agenda = valor( ent, CFG.agendamento, lang )
local doc = valor( ent, CFG.doctoralia, lang )
local estrelasN = valor( ent, CFG.estrelas, lang )
local opinioes = valor( ent, CFG.opinioes, lang )
local bio = valor( ent, CFG.bio, lang )
local cid = valor( ent, CFG.maps_cid, lang )
local pubs = valores( ent, CFG.publicacoes, lang )
local scholar = valor( ent, CFG.scholar_user, lang )
local escopoNeg = valores( ent, CFG.escopo_neg, lang )
local fonteTxt = qualificador( ent, CFG.registro, CFG.fonte, lang ) or qualificador( ent, CFG.bio, CFG.fonte, lang )
local coletaTxt = qualificador( ent, CFG.registro, CFG.coleta, lang ) or qualificador( ent, CFG.bio, CFG.coleta, lang )
local servicos = {}
for _, spid in ipairs( CFG.servicos ) do
for _, v in ipairs( valores( ent, spid, lang ) ) do
servicos[#servicos + 1] = v
end
end
local out = {}
out[#out + 1] = '<div class="infobox-medico">'
if foto then
out[#out + 1] = '<div class="infobox-medico-imagem">'
.. frame:preprocess( '[[File:' .. foto .. '|300px|center]]' ) .. '</div>'
end
out[#out + 1] = '<div class="infobox-medico-titulo">' .. esc( nome ) .. '</div>'
if desc and desc ~= '' then
out[#out + 1] = '<div class="infobox-medico-descricao">' .. esc( desc ) .. '</div>'
end
local espChips = {}
if esp then espChips[#espChips + 1] = esp end
if sub then espChips[#espChips + 1] = sub end
if #espChips > 0 then
out[#out + 1] = '<div class="infobox-medico-chips">' .. chips( espChips ) .. '</div>'
end
if estrelasN then
local nota = '<div class="medico-avaliacao"><span class="medico-estrelas">' .. estrelas( estrelasN )
.. '</span> <span class="medico-nota">' .. esc( estrelasN ) .. '/5</span>'
if opinioes then
if doc then
nota = nota .. ' · ' .. linkExterno( doc, opinioes .. ' opiniões' )
else
nota = nota .. ' · ' .. esc( opinioes ) .. ' opiniões'
end
end
out[#out + 1] = nota .. '</div>'
end
out[#out + 1] = '<table class="infobox-medico-tabela">'
local function linha( r, v )
if v and v ~= '' then
return '<tr><th>' .. esc( r ) .. '</th><td>' .. v .. '</td></tr>'
end
return ''
end
if #regs > 0 then
local regHtml = {}
for _, r in ipairs( regs ) do regHtml[#regHtml + 1] = esc( r ) end
out[#out + 1] = linha( 'Registro', table.concat( regHtml, '<br>' ) )
end
local partesEnd = {}
for _, v in ipairs( { logradouro, bairro, municipio, estado, cep } ) do
if v and v ~= '' then partesEnd[#partesEnd + 1] = v end
end
if #partesEnd > 0 then
out[#out + 1] = linha( 'Endereço', esc( table.concat( partesEnd, ', ' ) ) )
end
if horario then out[#out + 1] = linha( 'Horário', esc( horario ) ) end
if convenio then out[#out + 1] = linha( 'Convênio', esc( convenio ) ) end
if operadora then out[#out + 1] = linha( 'Operadora', esc( operadora ) ) end
if email then out[#out + 1] = linha( 'E-mail', linkExterno( 'mailto:' .. email, email ) ) end
if website then
local siteHref = website:match( '^https?://' ) and website or ( 'https://' .. website )
out[#out + 1] = linha( 'Site', linkExterno( siteHref, website ) )
end
if doc then
out[#out + 1] = linha( 'Doctoralia', linkExterno( doc, 'Ver perfil' ) )
end
out[#out + 1] = '</table>'
if bio and bio ~= '' then
out[#out + 1] = '<div class="infobox-medico-bio">' .. esc( bio ) .. '</div>'
end
if #servicos > 0 then
out[#out + 1] = '<div class="infobox-medico-secao">Procedimentos e serviços</div>'
out[#out + 1] = '<div class="infobox-medico-chips">' .. chips( servicos ) .. '</div>'
end
if agenda then
out[#out + 1] = '<div class="cta-agendar">' .. linkExterno( agenda, 'Agendar consulta' ) .. '</div>'
end
-- Mapa: URL com q=endereço (o formato q=&cid= era rejeitado pelo Google)
if cid and cid ~= '' then
local endMapa = table.concat( { logradouro, bairro, municipio, estado }, ', ' )
local mapUrl
if endMapa ~= '' then
mapUrl = 'https://maps.google.com/maps?q=' .. mw.uri.encode( endMapa, 'QUERY' )
.. '&z=16&output=embed&hl=pt-BR'
else
mapUrl = 'https://maps.google.com/maps?cid=' .. cid .. '&output=embed&hl=pt-BR'
end
local ok, html = pcall( frame.extensionTag, frame, 'perfilexterno', '', { url = mapUrl, largura = '100%', altura = '300' } )
if ok and html and html ~= '' then
out[#out + 1] = html
else
out[#out + 1] = '<div class="infobox-medico-mais">'
.. linkExterno( 'https://maps.google.com/maps?cid=' .. cid, 'Ver no Google Maps' ) .. '</div>'
end
end
if #pubs > 0 then
out[#out + 1] = '<div class="infobox-medico-secao">Publicações científicas</div>'
out[#out + 1] = '<ul class="infobox-medico-pubs">'
local n = math.min( 5, #pubs )
for i = 1, n do
local u = pubs[i]
out[#out + 1] = '<li>' .. linkExterno( u, u:gsub( '^https?://', '' ) ) .. '</li>'
end
out[#out + 1] = '</ul>'
if #pubs > n then
local alvo = scholar and ( 'https://scholar.google.com/citations?user=' .. scholar .. '&hl=pt-BR' ) or ''
out[#out + 1] = '<div class="infobox-medico-mais">'
.. linkExterno( alvo, '+ ' .. ( #pubs - n ) .. ' publicações' ) .. '</div>'
end
end
if #escopoNeg > 0 then
out[#out + 1] = '<details class="medico-detalhes"><summary>Desambiguação — o que este perfil <b>não</b> é</summary><ul>'
for _, v in ipairs( escopoNeg ) do
out[#out + 1] = '<li>' .. esc( v ) .. '</li>'
end
out[#out + 1] = '</ul></details>'
end
if fonteTxt or coletaTxt then
out[#out + 1] = '<div class="infobox-medico-rodape">Dados curados · fonte: ' .. esc( fonteTxt or '—' )
if coletaTxt then out[#out + 1] = ' · verificado em ' .. esc( coletaTxt ) end
out[#out + 1] = '</div>'
end
out[#out + 1] = '</div>'
return table.concat( out ) -- sem frame:preprocess no HTML todo; só a imagem precisava
end
return p
