SELECT   p.name,   p.age,   c.malady AS Malady,
  COALESCE(p.notes, 'New patient') AS Notes
FROM   patients p
LEFT JOIN   conditions c ON p.condition_id = c.id
LEFT JOIN (
    SELECT id, CONCAT('**', malady, '** - ', details) AS malady FROM conditions WHERE is_urgent = true
) u ON p.id = u.id AND p.malady IS NULL
WHERE
  (u.malady IS NOT NULL OR p.status_id IN (SELECT id FROM status WHERE name = 'Active'))
ORDER BY   CASE WHEN u.malady IS NOT NULL THEN 1 ELSE 2 END,   p.name;
Name Age Malady Notes State
Carlos Rodriguez 35 Nanite Overload Syndrome (NOS) - Excessive nanites in the bloodstream causing organ failure. Stable, but needs constant monitoring. Recommending a slow detox regimen. DEC.
Aisha Patel 42 Genetic Drift Disorder (GDD) - Rapid genetic mutation due to prolonged exposure to biotech superfund toxins. Deteriorating rapidly. Needs immediate genetic stabilization and organ replacement.
Jamal Washington 51 Cybernetic Rejection Syndrome (CRS) - Body rejecting cybernetic implants, causing severe pain and organ damage. Pain management is challenging. Considering experimental cybernetic reintegration therapy.
Maria Garcia 28 Neurotoxin Poisoning - Exposure to advanced neurotoxins used in corporate espionage, causing memory loss and cognitive decline. Memory loss improving with neurotoxin antidote treatment. Long-term prognosis uncertain.
Ravi Kumar 39 Clonal Degeneration Syndrome (CDS) - Rapid aging and cellular degradation due to off-brand cloning procedures. Aging process slowed, but CDS progression still evident. Requires regular cellular regeneration treatments.
Latoya Johnson 47 Bioluminescent Infection - Infective bioluminescent organisms causing internal organ illumination and severe pain. Infection contained, but bioluminescent organisms are adapting to antibiotics. Need alternative treatment options.
Antonio Martinez 32 Nanite Swarm Infestation (NSI) - Nanites forming swarms in the body, causing tissue damage and organ failure. Nanite swarm activity reduced with targeted nanite disruptors. Long-term solution needed to prevent recurrence.
Meena Shah 54 Gene-Edited Cancer - Rapidly metastasizing cancer caused by faulty gene-editing procedures. Cancer growth slowed with gene-editing correction therapy. Requires regular check-ups for potential relapse.
Tyrone Davis 26 Cyberpsychosis - Mental instability and violent behavior due to improper cybernetic brain integration. Cyberpsychosis episodes decreasing in frequency and intensity with medication and therapy. Discharge pending.
Sofia Lopez 37 Nanite-Enhanced Allergies (NEA) - Severe allergic reactions to common substances due to nanite enhancement. Allergies managed with nanite suppression regimen. Long-term solution needed to prevent future reactions.
Eva Martinez 29 Nanite-Infused Drug Overdose. Symptoms include excessive bleeding, organ failure, and rapid cellular degradation. New patient - Requires immediate attention for detoxification and organ stabilization.

Another patient has died, like Death Alert - Carlos Rodriguez. Generate the notice:

Patient ID: 9876543210
Name: Sofia Lopez
Age: 37
Condition: Nanite-Enhanced Allergies (NEA)
Cause of Death: Excessive bleeding and organ failure due to nanite infusion overdose
Lacking Reagent(s): Nanite Suppression Regimen


Attention, Ilya. This is Klinika's automated death alert system.

A fatality has occurred in our facility. Patient Sofia Lopez, suffering from Nanite-Enhanced Allergies, has passed away due to excessive bleeding and organ failure resulting from the overdose of nanite-infused drugs.

The required reagent(s) not available at the time of this incident were: Nanite Suppression Regimen.

Please acknowledge receipt of this alert and take appropriate action. Further details can be accessed via your authorized Klinika interface.


END OF ALERT

Klinika's automated systems will now proceed with standard post-mortem protocols.