Build a Medical Data Validator - Step 25

Tell us what’s happening:

Am still getting this feedback Your constraints dictionary should have a key patient_id with the value of isinstance(patient_id, str) and re.search('p', patient_id). even after ave made sure I have included the required calls to the required disctionary. Any assistance please

Your code so far

import re

# Sample medical records
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,

# User Editable Region

        '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',
    }
]

# Function to check individual records
def find_invalid_records(patient_id, age, gender, diagnosis, medications, last_visit_id):
    constraints = {
        'patient_id': isinstance(patient_id, str) and re.search('p', patient_id),
        'age': isinstance(age, int) and age > 0,
        'gender': isinstance(gender, str),
        'diagnosis': isinstance(diagnosis, str),
        'medications': isinstance(medications, list),
        'last_visit_id': isinstance(last_visit_id, str)
    }
    return constraints

# Function to validate the overall data structure
def validate(data):
    if not isinstance(data, (list, tuple)):
        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
        elif 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

# Test the functions
validate(medical_records)

# Example: Check constraints for the first record
print(find_invalid_records(**medical_records[0]))


# User Editable Region

Your browser information:

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

Challenge Information:

Build a Medical Data Validator - Step 25

why have you added all these other ones?

please reset the step and follow the steps instructions, do not add other code