Exemple #1
0
def get_sensibility_percentages(df):
    microorganisms = dict()
    antibiotics = helper.get_all_antibiotics(df)

    for index, row in df.iterrows():
        if helper.get(row, 'microorganismo') in microorganisms:
            microorganism_record = microorganisms.get(
                helper.get(row, 'microorganismo'))
        else:
            microorganism_record = initialize_microorganism_record(
                row, antibiotics)
            microorganisms[helper.get(row,
                                      'microorganismo')] = microorganism_record

        for antibiotic in antibiotics:
            antibiotic_resistance = helper.get(row, antibiotic)
            if antibiotic_resistance != 'nan':
                microorganism_record.sensibility[antibiotic].total += 1
            if antibiotic_resistance == 'sensible' or antibiotic_resistance == 'intermedio':
                microorganism_record.sensibility[antibiotic].sensible += 1
            if microorganism_record.sensibility[antibiotic].total != 0:
                microorganism_record.sensibility[antibiotic].percentage = \
                    microorganism_record.sensibility[antibiotic].sensible / microorganism_record.sensibility[antibiotic].total
        microorganism_record.frequency += 1

    return microorganisms
Exemple #2
0
def initialize_microorganism_record(row, antibiotics):
    microorganism_record = Microorganism(helper.get(row, 'microorganismo'))
    microorganism_sensibility = dict()
    for antibiotic in antibiotics:
        microorganism_sensibility[antibiotic] = SensibilityRecord()
    microorganism_record.sensibility = microorganism_sensibility
    return microorganism_record
def is_fqr(row):
    microorganismo_name = helper.get(row, "microorganismo")
    if helper.get_key_matches(['pseudomonas aeruginosa'], microorganismo_name):
        return helper.is_resistant_to_all(
            row, pseudomonas_aeruginosa_fqr_antibiotics)
    if helper.get_key_matches(watched_microorganisms, microorganismo_name):
        return helper.is_resistant_to_all(row, enterobacter_fqr_antibiotics)
def fourth_criteria(df):
    """
    DTR > CR > ECR > FQR
    :param df:
    :return:
    """
    microorganisms = dict()
    for index, row in df.iterrows():
        microorganism = Microorganismo()
        microorganism.last_register = helper.get(row, 'fechapeticion')
        microorganism.last_nhc = helper.get(row, 'nhc')

        if is_dtr(row):
            microorganism.last_fenotype = ('dtr', 3)
            microorganism.dtr_frequency += 1
        elif is_cr(row):
            microorganism.last_fenotype = ('cr', 2)
            microorganism.cr_frequency += 1
        elif is_ecr(row):
            microorganism.last_fenotype = ('ecr', 1)
            microorganism.ecr_frequency += 1
        elif is_fqr(row):
            microorganism.last_fenotype = ('fqr', 0)
            microorganism.fqr_frequency += 1
        else:
            microorganism.last_fenotype = ('none', -1)

        if helper.get(row, 'microorganismo') in microorganisms:
            saved_record = microorganisms.get(helper.get(row, 'microorganismo'))
            current_date = pd.to_datetime(microorganism.last_register, dayfirst=True)
            last_date = pd.to_datetime(saved_record.last_register, dayfirst=True)
            if (current_date - last_date).days < 30 and saved_record.last_nhc == microorganism.last_nhc:
                if microorganism.last_fenotype[1] >= saved_record.last_fenotype[1]:
                    helper.decrement_frequency(saved_record, saved_record.last_fenotype[0])
                    helper.increment_frequency(saved_record, microorganism.last_fenotype[0])
                    saved_record.last_fenotype = microorganism.last_fenotype
            else:
                helper.increment_frequency(saved_record, microorganism.last_fenotype[0])
                saved_record.frequency += 1
                saved_record.last_nhc = microorganism.last_nhc
                saved_record.last_fenotype = microorganism.last_fenotype
            saved_record.last_register = microorganism.last_register
        else:
            microorganism.frequency = 1
            microorganisms[helper.get(row, 'microorganismo')] = microorganism
    return microorganisms
def is_dtr(row):
    microorganismo_name = helper.get(row, "microorganismo")
    if helper.get_key_matches(acinetobacter_baumannii_complex,
                              microorganismo_name):
        return helper.is_resistant_to_all(
            row, acinetobacter_baumannii_complex_dtr_antibiotics)
    if helper.get_key_matches(watched_microorganisms, microorganismo_name):
        return helper.is_resistant_to_all(row, dtr_antibiotics)
def is_cr(row):
    microorganismo_name = helper.get(row, "microorganismo")
    if helper.get_key_matches(
            acinetobacter_baumannii_complex + ['pseudomonas aeruginosa'],
            microorganismo_name):
        return helper.is_resistant_to_all(
            row, pseudomonas_aeruginosa_cr_antibiotics)
    if helper.get_key_matches(watched_microorganisms, microorganismo_name):
        return helper.is_resistant_to_all(row, enterobacter_cr_antibiotics)
Exemple #7
0
def matches_criteria(dataframe, antibiotics, excluded=None, included=None):
    microorganismos = dict()
    for index, row in dataframe.iterrows():
        microorganismo_name = helper.get(row, "microorganismo")
        if (excluded is not None) and helper.get_key_matches(
                excluded, microorganismo_name):
            continue
        if (included is not None) and not helper.get_key_matches(
                included, microorganismo_name):
            continue

        if helper.is_resistant_to_all(row, antibiotics):
            if microorganismo_name in microorganismos:
                microorganismo = microorganismos.get(microorganismo_name)
                microorganismo.frequency += 1
            else:
                microorganismo = Microorganism(resistant_to=antibiotics)
                microorganismo.frequency += 1
                microorganismos[microorganismo_name] = microorganismo
    return microorganismos