Limour

Limour

临床医学在读。

【Respiration】Simple Interpretation of Arterial Blood Gas & Pulmonary Function Report

Arterial Blood Gas#

def arterialBloodGasAnalysis(pH:float, PaCO2:float, SB:float, AB:float, PaO2:float, age:int):
    '''
    pH: acidity or alkalinity, normal range 7.35~7.45
    PaCO2: arterial carbon dioxide partial pressure, normal range 35~45 mmHg
    HCO3-: SB standard bicarbonate, AB actual bicarbonate, normal range SB = AB 22~27 mmol/L
    PaO2: arterial oxygen partial pressure, normal range 100 - 0.33 * age ± 5 mmHg
    age: age
    '''
    
    result = ''
    
    # Hypoxemia
    goal_PaO2 = 100 - 0.33 * age - 5
    if PaO2 > goal_PaO2:
        pass
    elif PaO2 <= 40:
        result += 'Severe hypoxemia;'
    elif PaO2 <= 60:
        result += 'Moderate hypoxemia;'
    elif PaO2 <= 95:
        result += 'Mild hypoxemia;'
    
    if PaO2 < 60:
        if PaCO2 <= 45:
            result += 'Type I respiratory failure;'
        elif PaCO2 > 50:
            result += 'Type II respiratory failure;'
        else:
            result += 'Respiratory failure;'

    # Acid-base balance
    goal_pH = 7.4 + (40 - PaCO2) / 10 * 0.08
    if pH > 7.45:
        if PaCO2 > 40:
            result += 'Metabolic alkalosis;'
        else:
            if goal_pH + 0.02 < pH:
                result += 'Respiratory alkalosis combined with metabolic alkalosis;'
            elif goal_pH - 0.02 <= pH:
                result += 'Simple respiratory alkalosis;'
            else:
                result += 'Respiratory alkalosis combined with metabolic acidosis;'
    elif pH < 7.35:
        if PaCO2 < 40:
            result += 'Metabolic acidosis;'
        else:
            if goal_pH + 0.02 < pH:
                result += 'Respiratory acidosis combined with metabolic alkalosis;'
            elif goal_pH - 0.02 <= pH:
                result += 'Simple respiratory acidosis;'
            else:
                result += 'Respiratory acidosis combined with metabolic acidosis;'
    else:
        if SB > 27:
            if PaCO2 - 40 > 0.7 * (AB - 24) + 5:
                result += 'Metabolic alkalosis combined with respiratory acidosis;'
            else:
                result += 'Compensatory metabolic alkalosis;'
        elif SB < 22:
            if 40 - PaCO2 < 1.2 * (24 - AB) + 2:
                result += 'Metabolic acidosis combined with respiratory alkalosis;'
            else:
                result += 'Compensatory metabolic acidosis;'
        else:
            if (22 < AB < 27) and (35 < PaCO2 < 45):
                result += 'Metabolic alkalosis combined with metabolic acidosis or normal;'
        
    
    return result if result else 'Normal result'

Pulmonary Function#

def pulmonaryFunctionTest(FEV1_R_VC:float, FEV1_R_VC_R:float, FEV1_R:float, 
                          FEF25_R:float, FEF50_R:float, FEF75_R:float, 
                          FVC_R:float, 
                          DLNO_SB_R:float, 
                          FEV1_CHG:float, FEV1_CHG_R:float):
    '''
    FEV1_R_VC: FEV1/VC percentage
    FEV1_R_VC_R: FEV1/VC % Pred percentage
    FEV1_R: forced expiratory volume in 1 second FEV1 % Pred percentage
    FEF25_R: FEF25 % Pred percentage
    FEF50_R: FEF50 % Pred percentage
    FEF75_R: FEF75 % Pred percentage
    FVC_R: forced vital capacity FVC % Pred percentage
    DLNOc_SB_R: corrected single breath DLNO % Pred percentage
    FEV1_CHG: bronchial dilation test FEV1 increase value L
    FEV1_CHG_R: FEV1_CHG % Pred percentage
    '''
    if FEV1_R >= 80:
        Ventilation_grade = 'Normal'
    elif FEV1_R >= 70:
        Ventilation_grade = 'Mild'
    elif FEV1_R >= 60:
        Ventilation_grade = 'Moderate'
    elif FEV1_R >= 50:
        Ventilation_grade = 'Moderate to severe'
    elif FEV1_R >= 35:
        Ventilation_grade = 'Severe'
    else:
        Ventilation_grade = 'Very severe'
    
    Obstructive_ventilatory_dysfunction = (FEV1_R_VC < 70) or (FEV1_R_VC_R < 92)
    if not Obstructive_ventilatory_dysfunction:
        Small_airway_dysfunction = ((FEF25_R < 65) + (FEF50_R < 65) + (FEF75_R < 65)) >= 2
    else:
        Small_airway_dysfunction = 0 # Meaningless
    
    Restrictive_ventilatory_dysfunction = FVC_R < 80
    
    Diffusion_dysfunction = DLNO_SB_R < 80
    if Diffusion_dysfunction:
        if DLNO_SB_R >= 60:
            Diffusion_grade = 'Mild'
        elif DLNO_SB_R >= 40:
            Diffusion_grade = 'Moderate'
        else:
            Diffusion_grade = 'Severe'
    
    if (FEV1_CHG_R >= 12) and (FEV1_CHG >= 0.2):
        Bronchial_dilation_test = 'Positive'
    elif (FEV1_CHG_R >= 12) or (FEV1_CHG >= 0.2):
        Bronchial_dilation_test = 'Suspicious positive'
    else:
        Bronchial_dilation_test = 'Negative'
    
    result = Ventilation_grade
    if Obstructive_ventilatory_dysfunction and Restrictive_ventilatory_dysfunction:
        result += 'Mixed ventilatory dysfunction'
    elif Obstructive_ventilatory_dysfunction:
        result += 'Obstructive ventilatory dysfunction'
    elif Restrictive_ventilatory_dysfunction:
        result += 'Restrictive ventilatory dysfunction'
    else:
        result = ''
    
    if (Small_airway_dysfunction or Diffusion_dysfunction) and result:
        result += ' with'
    if Small_airway_dysfunction and Diffusion_dysfunction:
        result += f' small airway dysfunction, {Diffusion_grade} diffusion dysfunction'
    elif Small_airway_dysfunction:
        result += ' small airway dysfunction'
    elif Diffusion_dysfunction:
        result += f' {Diffusion_grade} diffusion dysfunction'
    
    if not result:
        result = "Normal pulmonary ventilation and diffusion function"
    
    return result + f'; Bronchial dilation test {Bronchial_dilation_test}'
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.