Patients With a Specific Condition
Imagine you are developing a healthcare management system. A critical feature is the ability to quickly identify and retrieve records of patients who have a specific medical condition. This challenge will help you build a function that filters a list of patient records to find those matching a given condition.
Problem Description
You need to implement a function that takes a list of patient records and a target medical condition as input. The function should return a new list containing only the patient records that include the specified condition in their list of diagnosed conditions.
-
Input:
- A list of
PatientRecordobjects. EachPatientRecordobject has at least two properties:patientId: A unique identifier for the patient (e.g., an integer or string).conditions: A list of strings, where each string represents a diagnosed medical condition.
- A string representing the
targetConditionto search for.
- A list of
-
Output:
- A new list containing
PatientRecordobjects that have thetargetConditionin theirconditionslist. - If no patients have the
targetCondition, an empty list should be returned.
- A new list containing
-
Expected Behavior:
- The function should iterate through each
PatientRecordin the input list. - For each
PatientRecord, it should check if thetargetConditionexists within itsconditionslist. - If a match is found, the entire
PatientRecordobject should be added to the result list. - The comparison of conditions should be case-sensitive.
- The function should iterate through each
-
Edge Cases:
- An empty input list of
PatientRecordobjects. - A
PatientRecordwith an emptyconditionslist. - The
targetConditionnot present in any patient'sconditionslist.
- An empty input list of
Examples
Example 1:
Input:
patients = [
{ patientId: 1, conditions: ["Diabetes", "Hypertension"] },
{ patientId: 2, conditions: ["Asthma", "Allergies"] },
{ patientId: 3, conditions: ["Hypertension", "Arthritis"] }
]
targetCondition = "Hypertension"
Output:
[
{ patientId: 1, conditions: ["Diabetes", "Hypertension"] },
{ patientId: 3, conditions: ["Hypertension", "Arthritis"] }
]
Explanation: Patients with IDs 1 and 3 have "Hypertension" in their conditions list.
Example 2:
Input:
patients = [
{ patientId: 101, conditions: ["Migraine"] },
{ patientId: 102, conditions: ["Anxiety"] }
]
targetCondition = "Depression"
Output:
[]
Explanation: No patients in the list have the condition "Depression".
Example 3:
Input:
patients = [
{ patientId: 201, conditions: [] },
{ patientId: 202, conditions: ["Fever"] }
]
targetCondition = "Fever"
Output:
[
{ patientId: 202, conditions: ["Fever"] }
]
Explanation: Patient with ID 201 has an empty conditions list, while patient 202 has "Fever".
Constraints
- The input list of
PatientRecordobjects can contain between 0 and 1000 records. - Each
PatientRecord'sconditionslist can contain between 0 and 10 conditions. patientIdwill be a non-negative integer.conditionsandtargetConditionwill be non-empty strings, containing only alphanumeric characters and spaces.- The function should complete its execution within reasonable time limits for the given constraints (e.g., typically under 1 second).
Notes
- You will need to define a
PatientRecordstructure or class to represent the patient data. - Consider how to efficiently check for the presence of an element within a list.
- The output should be a new list; you should not modify the original input list of patients.