@@ -222,7 +222,7 @@ private String buildPneuSerotypingDataCte() {
222222 " AND s.deleted = false " +
223223 " AND pt.testtype IN ('SEROGROUPING', 'GENOTYPING', 'WHOLE_GENOME_SEQUENCING') " +
224224 " AND pt.typingid IS NOT NULL " +
225- " ORDER BY COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC " +
225+ " ORDER BY COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC NULLS LAST, pt.id DESC " +
226226 " LIMIT 1) as serotype " +
227227 " FROM filtered_cases c)" ;
228228 //@formatter:on
@@ -240,7 +240,7 @@ private String buildPneuPathogenDetectionMethodCte() {
240240 " WHERE s.associatedcase_id = c.id " +
241241 " AND s.deleted = false " +
242242 " AND pt.testresultverified = true " +
243- " ORDER BY COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC " +
243+ " ORDER BY COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC NULLS LAST, pt.id DESC " +
244244 " LIMIT 1) as detection_method " +
245245 " FROM filtered_cases c)" ;
246246 //@formatter:on
@@ -341,7 +341,7 @@ private String buildPneuAstDataCte() {
341341 " LEFT JOIN pathogentest pt ON pt.sample_id = s.id " +
342342 " AND pt.testtype = 'ANTIBIOTIC_SUSCEPTIBILITY' " +
343343 " LEFT JOIN drugsusceptibility ds ON pt.drugsusceptibility_id = ds.id " +
344- " ORDER BY c.id, COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC" +
344+ " ORDER BY c.id, COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC NULLS LAST, pt.id DESC " +
345345 ")" ;
346346 //@formatter:on
347347 }
0 commit comments