Module:BiologicalAgeBiomarkers: Difference between revisions

    From Longevity Wiki
    No edit summary
    No edit summary
    Line 17: Line 17:
    local studies = {
    local studies = {
         PMID12345 = {
         PMID12345 = {
         pmid = 12345,
         pmid = "12345",
             name = "Study1",
             name = "Study1",
             method = "MLR",
             method = "MLR",
    Line 29: Line 29:
         },
         },
         PMID67890 = {
         PMID67890 = {
             pmid = 67890,
             pmid = "67890",
             method = "MLR",
             method = "MLR",
             year = "1995",
             year = "1995",
    Line 40: Line 40:
         },
         },
         PMID13579 = {
         PMID13579 = {
             pmid = 13579,
             pmid = "13579",
             method = "MLR",
             method = "MLR",
             year = "1995",
             year = "1995",

    Revision as of 01:36, 19 February 2024

    Output the biological age biomarkers table.

    Data is stored in Module:BiologicalAgeBiomarkers/Data


    local p = {}
    
    -- Define biomarkers with their long form and system
    local biomarkers = {
        SBP = {name = "Systolic Blood Pressure (SBP)", system = "Cardiovascular System"},
        DBP = {name = "Diastolic Blood Pressure (DBP)", system = "Cardiovascular System"},
        HDL = {name = "High-Density Lipoprotein (HDL)", system = "Endocrine Metabolic System"},
        LDL = {name = "Low-Density Lipoprotein (LDL)", system = "Endocrine Metabolic System"}
    }
    
    local rows = {
    	method = "Biological Age Estimation Method",
    	year = "Year"
    }
    
    -- Incorporate data directly into studies identified by PMID
    local studies = {
        PMID12345 = {
        	pmid = "12345",
            name = "Study1",
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        },
        PMID67890 = {
            pmid = "67890",
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        },
        PMID13579 = {
            pmid = "13579",
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        }
    }
    
    function p.createCrossTable()
        -- Start of the wiki table
        local wikitable = '{| class="wikitable"\n!'
    
        -- Column headers: Biomarker and System
        wikitable = wikitable .. ' System !! Biomarker'
        for _, study in pairs(studies) do
            wikitable = wikitable .. ' !! '  .. study.pmid
    	end
    	wikitable = wikitable .. '\n'
    
        for key, name in pairs(rows) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '| ' .. name .. ' || ' .. ''
            for _, study in pairs(studies) do
                local cellValue = study[key] or ""
    			wikitable = wikitable .. ' || ' .. cellValue
            end
    		wikitable = wikitable .. '\n'
    	end
    
        -- Generate rows for each biomarker
        for abbr, details in pairs(biomarkers) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. details.system .. ' || ' .. details.name
            for _, study in pairs(studies) do
                -- Retrieve data value for the current cell, using the nested structure
                local cellValue = study.data[abbr] or ""
                wikitable = wikitable .. ' || ' .. cellValue
            end
    		wikitable = wikitable .. '\n'
        end
    
        -- End of the table
        wikitable = wikitable .. '\n|}'
    
        return wikitable
    end
    
    return p