Challenge: Populate the ClusterGroup by determining the patients CareCluster at the point of inpatient admittance.
The objective of the report is to measure inpatient admissions i.e. patients that stay in a hospital bed overnight, for each care cluster.
A care cluster is a needs-based grouping. A patient is assessed and assigned a care cluster based on severity.
Patient 10000003 has 3 Inpatient Admission (IPAdmissions)
Patient 10000003 was reassessed and downgraded from CareCluster P17 to CareCluster P12 on 13th March 2013 (ClusterAssessmentDate)
So, was Patient 10000003 in CareCluster P12 or P17 at point of inpatient admission?
InitialApproach retrieves the hour difference between ClusterAssessmentDate and IPAdmissionDate using:
DATEDIFF(HOUR, ClusterAssessmentDate, IPAdmissionDate)
My assumption is that the smallest number ABOVE zero will be the CareCluster that should be assigned to the ClusterGroup.
How do I write a query to return the smallest number ABOVE Zero and populate ClusterGroup with correct CareCluster?
Is there a more eloquent way of solving the smallest number above zero challenge?
Any alternative solutions?