Hone logo
Hone
Problems

Patients With a Condition

This challenge asks you to analyze patient data to identify those who have been diagnosed with a specific medical condition. Accurately identifying patients with a condition is crucial for epidemiological studies, targeted treatment programs, and resource allocation within healthcare systems. You will be provided with patient records and a condition name, and your task is to return a list of patient IDs who have been diagnosed with that condition.

Problem Description

You are given a list of patient records and a target condition name. Each patient record contains a unique patient ID and a list of diagnosed conditions. Your task is to identify all patients who have been diagnosed with the target condition and return a list of their patient IDs.

What needs to be achieved:

  • Process a list of patient records.
  • Identify patients diagnosed with a specific condition.
  • Return a list of patient IDs for those patients.

Key Requirements:

  • The input will be a list of patient records. Each record will be a dictionary/map/object with two keys: "patient_id" (a unique identifier) and "conditions" (a list of strings representing diagnosed conditions).
  • The input will also include a single string representing the target condition to search for.
  • The output should be a list of patient IDs (strings) of patients diagnosed with the target condition.
  • The order of patient IDs in the output list does not matter.
  • If no patients are diagnosed with the target condition, return an empty list.
  • Patient IDs and condition names are case-sensitive.

Expected Behavior:

The function/program should iterate through the patient records, check if the target condition exists in the patient's list of conditions, and if it does, add the patient's ID to the output list.

Edge Cases to Consider:

  • Empty list of patient records.
  • Target condition not found in any patient records.
  • Patient records with empty condition lists.
  • Duplicate patient IDs (though this should ideally be prevented in the input data, handle it gracefully - only include the ID once in the output).
  • Case sensitivity of condition names.

Examples

Example 1:

Input:
patient_records = [
    {"patient_id": "P123", "conditions": ["Diabetes", "Hypertension"]},
    {"patient_id": "P456", "conditions": ["Asthma"]},
    {"patient_id": "P789", "conditions": ["Diabetes", "Arthritis"]},
]
target_condition = "Diabetes"
Output: ["P123", "P789"]
Explanation: Patients P123 and P789 have been diagnosed with Diabetes.

Example 2:

Input:
patient_records = [
    {"patient_id": "P101", "conditions": ["Flu"]},
    {"patient_id": "P202", "conditions": ["Cold"]},
    {"patient_id": "P303", "conditions": []}
]
target_condition = "COVID-19"
Output: []
Explanation: No patients have been diagnosed with COVID-19.

Example 3:

Input:
patient_records = [
    {"patient_id": "P001", "conditions": ["diabetes"]},
    {"patient_id": "P002", "conditions": ["Hypertension"]},
    {"patient_id": "P003", "conditions": ["Diabetes"]}
]
target_condition = "Diabetes"
Output: ["P003"]
Explanation:  The condition name is case-sensitive. Only P003 has "Diabetes" (not "diabetes").

Constraints

  • The number of patient records will be between 0 and 1000.
  • Each patient record will have a "patient_id" which is a string of length between 3 and 10 characters.
  • The "conditions" list in each patient record will contain between 0 and 20 strings.
  • Each condition name will be a string of length between 3 and 20 characters.
  • The target condition will be a string of length between 3 and 20 characters.
  • The solution should complete within 1 second for the given constraints.

Notes

Consider using a loop to iterate through the patient records. A simple if statement within the loop can check if the target condition is present in the patient's conditions list. Remember to handle the edge case where no patients are diagnosed with the target condition. Think about how to efficiently build the output list of patient IDs. The problem emphasizes clarity and correctness over extreme optimization, but efficient code is always appreciated.

Loading editor...
plaintext