From aeae08ea886e233dd3b101e2669d3ff9e9dca702 Mon Sep 17 00:00:00 2001 From: ra247362 Date: Thu, 26 Dec 2024 11:44:39 -0300 Subject: [PATCH] Refactor one of the LabBrowsingModel to streamline overall logic. --- src/main/java/org/isf/lab/gui/LabBrowser.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/isf/lab/gui/LabBrowser.java b/src/main/java/org/isf/lab/gui/LabBrowser.java index 1869e57fa2..fa0ce50628 100644 --- a/src/main/java/org/isf/lab/gui/LabBrowser.java +++ b/src/main/java/org/isf/lab/gui/LabBrowser.java @@ -515,29 +515,24 @@ class LabBrowsingModel extends DefaultTableModel { private static final long serialVersionUID = 1L; public LabBrowsingModel(String exam, LocalDate dateFrom, LocalDate dateTo, String patid) { - boolean exists = true; try { - Patient pat; - if (patid.isEmpty()) { - pat = null; - } else { - try { - pat = patManager.getPatientById(Integer.parseInt(patid)); - exists = pat == null ? false : true; - } catch (NumberFormatException e) { - MessageDialog.error(null, "angal.lab.insertvalidpatientid.msg"); - pat = null; - } - } - if (exists) { - pLabs = labManager.getLaboratory(exam, dateFrom.atStartOfDay(), dateTo.atStartOfDay(), pat); + if (!patid.isEmpty()) { + Patient pat = patManager.getPatientById(Integer.parseInt(patid)); + if (pat == null) { + pLabs = new ArrayList<>();; + } else { + pLabs = labManager.getLaboratory(exam, dateFrom.atStartOfDay(), dateTo.atStartOfDay(), pat); + } } else { - pLabs = new ArrayList<>(); + pLabs = labManager.getLaboratory(exam, dateFrom.atStartOfDay(), dateTo.atStartOfDay(), null); } } catch (OHServiceException e) { pLabs = new ArrayList<>(); OHServiceExceptionUtil.showMessages(e); - } + } catch (NumberFormatException e) { + pLabs = new ArrayList<>(); + MessageDialog.error(null, "angal.lab.insertvalidpatientid.msg"); + } } public LabBrowsingModel(String patid) { @@ -644,4 +639,4 @@ public void laboratoryInserted() { } } -} +} \ No newline at end of file