Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Build Cohort From EMR Tables
00:00
5 left

Build Cohort From EMR Tables

HardSQL · PostgreSQL

Problem

Build a cohort of patients from multiple tables of fake EMR data provided.

Use the provided EMR tables to identify adults with a qualifying outpatient diabetes encounter in 2024 and a follow-up encounter within 30 days. Include the latest HbA1c collected by the follow-up date and medications active on that date.

Output

  1. One row per qualifying patient.
  2. Return patient_id, patient_name, index_date, followup_date, diagnosis_count, latest_hba1c, and active_medication_count.
  3. Sort by index_date, then patient_id.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
date_of_birthDATEPatient birth date
sexVARCHAR(20)Recorded sex
encounters
ColumnTypeDescription
encounter_idPKINTUnique encounter identifier
patient_idINTPatient associated with the encounter
encounter_dateDATEDate of encounter
encounter_typeVARCHAR(30)Encounter setting
statusVARCHAR(20)Encounter completion status
diagnoses
ColumnTypeDescription
diagnosis_idPKINTUnique diagnosis record identifier
encounter_idINTEncounter containing the diagnosis
diagnosis_codeVARCHAR(20)ICD diagnosis code
labs
ColumnTypeDescription
lab_idPKINTUnique laboratory result identifier
patient_idINTPatient associated with the result
lab_nameVARCHAR(50)Laboratory test name
collected_atTIMESTAMPSpecimen collection timestamp
result_valueDECIMAL(5,2)Numeric laboratory result
medications
ColumnTypeDescription
medication_idPKINTUnique medication record identifier
patient_idINTPatient receiving the medication
medication_nameVARCHAR(80)Medication name
start_dateDATEMedication start date
end_dateDATEMedication end date
Tablespatientsencountersdiagnoseslabsmedications
Interviewer

Your question is Build Cohort From EMR Tables. Start with the requirements and the five tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.