Describe how you would design a database and write the SQL queries needed to support the use cases described in the prompt.
Use the provided patient, encounter, and diagnosis entities. The report must include patients without completed encounters and count diagnoses associated only with each patient's latest completed encounter.
Output
- One row per patient with
patient_id, patient_name, latest_completed_encounter, diagnosis_count, and encounter_status.
- Include all patients, use
No completed encounter when applicable, and sort by patient_id ascending.