Template:Infobox Médico: Difference between revisions

From determinar.ia.br - Determine suas informações
Created page with "local p = {} function p.main(frame) local id = frame.args.ID or frame.args[1] local entity = mw.wikibase.getEntity(id) if not entity then return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>' end local label = entity:getLabel('pt-br') or entity:getLabel('pt') or entity:getLabel('en') or id local description = entity:getDescription('pt-br') or entity:getDescription('pt') or '' local html = mw.html.create('table')..."
 
Replaced content with "{{#invoke:MedicoInfobox|main}}"
Tag: Replaced
Line 1: Line 1:
local p = {}
{{#invoke:MedicoInfobox|main}}
 
function p.main(frame)
    local id = frame.args.ID or frame.args[1]
    local entity = mw.wikibase.getEntity(id)
 
    if not entity then
        return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>'
    end
 
    local label = entity:getLabel('pt-br') or entity:getLabel('pt') or entity:getLabel('en') or id
    local description = entity:getDescription('pt-br') or entity:getDescription('pt') or ''
 
    local html = mw.html.create('table')
        :addClass('infobox-medico')
 
    html:tag('tr')
        :tag('th'):attr('colspan', '2'):css('text-align', 'center'):wikitext(label)
 
    if description ~= '' then
        html:tag('tr')
            :tag('td'):attr('colspan', '2'):css('font-style', 'italic'):wikitext(description)
    end
 
    if entity.claims then
        for propertyId, claims in pairs(entity.claims) do
            local propLabel = mw.wikibase.label(propertyId) or propertyId
            local valores = {}
 
            for _, claim in ipairs(claims) do
                local snak = claim.mainsnak
                if snak and snak.datavalue then
                    local dv = snak.datavalue
                    local val
 
                    if dv.type == 'string' then
                        val = dv.value
                    elseif dv.type == 'monolingualtext' then
                        val = dv.value.text
                    elseif dv.type == 'wikibase-entityid' then
                        val = mw.wikibase.label(dv.value.id) or dv.value.id
                    elseif dv.type == 'quantity' then
                        val = dv.value.amount
                    elseif dv.type == 'time' then
                        val = dv.value.time
                    else
                        val = tostring(dv.value)
                    end
 
                    table.insert(valores, val)
                end
            end
 
            if #valores > 0 then
                local row = html:tag('tr')
                row:tag('th'):wikitext(propLabel)
                row:tag('td'):wikitext(table.concat(valores, ', '))
            end
        end
    end
 
    return tostring(html)
end
 
return p

Revision as of 11:21, 1 August 2026

Entidade não encontrada — informe ID=Q…