Hone logo
Hone
Problems

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 PatientRecord objects. Each PatientRecord object 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 targetCondition to search for.
  • Output:

    • A new list containing PatientRecord objects that have the targetCondition in their conditions list.
    • If no patients have the targetCondition, an empty list should be returned.
  • Expected Behavior:

    • The function should iterate through each PatientRecord in the input list.
    • For each PatientRecord, it should check if the targetCondition exists within its conditions list.
    • If a match is found, the entire PatientRecord object should be added to the result list.
    • The comparison of conditions should be case-sensitive.
  • Edge Cases:

    • An empty input list of PatientRecord objects.
    • A PatientRecord with an empty conditions list.
    • The targetCondition not present in any patient's conditions list.

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 PatientRecord objects can contain between 0 and 1000 records.
  • Each PatientRecord's conditions list can contain between 0 and 10 conditions.
  • patientId will be a non-negative integer.
  • conditions and targetCondition will 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 PatientRecord structure 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.
Loading editor...
plaintext