Build a Medical Data Validator - Step 23

Tell us what’s happening:

I’m stuck on Step 23.

My function creates the constraints dictionary and assigns:
def find_invalid_records(patient_id, age, gender, diagnosis, medications, last_visit_id):
constraints = {

}
constraints['patient_id'] = isinstance(patient_id, str)
return constraints

However, the test still fails with the message:

Your constraints dictionary should have a key patient_id with the value of isinstance(patient_id, str).

Your code so far

medical_records = [
    {
        'patient_id': 'P1001',
        'age': 34,
        'gender': 'Female',
        'diagnosis': 'Hypertension',
        'medications': ['Lisinopril'],
        'last_visit_id': 'V2301',
    },
    {
        'patient_id': 'p1002',
        'age': 47,
        'gender': 'male',
        'diagnosis': 'Type 2 Diabetes',
        'medications': ['Metformin', 'Insulin'],
        'last_visit_id': 'v2302',
    },
    {
        'patient_id': 'P1003',
        'age': 29,
        'gender': 'female',
        'diagnosis': 'Asthma',
        'medications': ['Albuterol'],
        'last_visit_id': 'v2303',
    },
    {
        'patient_id': 'p1004',
        'age': 56,
        'gender': 'Male',
        'diagnosis': 'Chronic Back Pain',
        'medications': ['Ibuprofen', 'Physical Therapy'],
        'last_visit_id': 'V2304',
    }
]


# User Editable Region

def find_invalid_records(patient_id, age, gender, diagnosis, medications, last_visit_id):
    constraints = { 
        
    }
    constraints['patient_id'] = isinstance(patient_id, str)
    return constraints
    

# User Editable Region

def validate(data):
    is_sequence = isinstance(data, (list, tuple))

    if not is_sequence:
        print('Invalid format: expected a list or tuple.')
        return False
        
    is_invalid = False
    key_set = set(
        ['patient_id', 'age', 'gender', 'diagnosis', 'medications', 'last_visit_id']
    )

    for index, dictionary in enumerate(data):
        if not isinstance(dictionary, dict):
            print(f'Invalid format: expected a dictionary at position {index}.')
            is_invalid = True

        if set(dictionary.keys()) != key_set:
            print(
                f'Invalid format: {dictionary} at position {index} has missing and/or invalid keys.'
            )
            is_invalid = True

    if is_invalid:
        return False
    print('Valid format.')
    return True

validate(medical_records)
print(find_invalid_records(**medical_records[0]))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0

Challenge Information:

Build a Medical Data Validator - Step 23

Welcome to the forum @mauriciopgsantos !

In this step, you already have a constraints dictionary available to write key-value pairs into. Look at your dictionary objects in medical_records and pattern your key-value syntax off of one of those.

1 Like

Thanks my friend!
You solved for me

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.