From a0c9279449b1378c021813b805813e44dbf60da2 Mon Sep 17 00:00:00 2001 From: Devika Date: Fri, 23 Feb 2024 17:54:32 +0530 Subject: [PATCH 1/8] Corrected the properties variable name for ANC fetosense test --- .../iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index 7a3bbab7..c021b13b 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -278,7 +278,7 @@ public String sendFoetalMonitorTestDetails(FoetalMonitor request, String auth) t // Invoking foetalMonitor API - Sending mother data and test details to // fetosense result = httpUtils.postWithResponseEntity( - ConfigProperties.getPropertyByName("foetalMonitor-api-url-ANCTestDetails"), requestObj, header); + ConfigProperties.getPropertyByName("fetosense-api-url-ANCTestDetails"), requestObj, header); logger.info("Foetal monitor register mother API response : " + result.toString()); // check foetalMonitor API response code From 044382f6f2e33f3a87988a739eb371155181b116 Mon Sep 17 00:00:00 2001 From: Devika Date: Thu, 7 Mar 2024 09:39:50 +0530 Subject: [PATCH 2/8] Corrected partner fetosense Id variable name in FeotalMonitorData --- .../iemr/tm/data/foetalmonitor/FoetalMonitorData.java | 10 +++++----- .../foetalmonitor/FoetalMonitorServiceImpl.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/iemr/tm/data/foetalmonitor/FoetalMonitorData.java b/src/main/java/com/iemr/tm/data/foetalmonitor/FoetalMonitorData.java index 2a1d30f9..7697d348 100644 --- a/src/main/java/com/iemr/tm/data/foetalmonitor/FoetalMonitorData.java +++ b/src/main/java/com/iemr/tm/data/foetalmonitor/FoetalMonitorData.java @@ -23,18 +23,18 @@ public class FoetalMonitorData { - private Long partnerFoetalMonitorId; + private Long partnerFetosenseId; private Long beneficiaryRegID; private String motherLMPDate; private String motherName; private String testName; private String deviceId; - public Long getPartnerFoetalMonitorID() { - return partnerFoetalMonitorId; + public Long getPartnerFetosenseID() { + return partnerFetosenseId; } - public void setPartnerFoetalMonitorID(Long partnerFoetalMonitorID) { - this.partnerFoetalMonitorId = partnerFoetalMonitorID; + public void setPartnerFetosenseID(Long partnerFetosenseID) { + this.partnerFetosenseId = partnerFetosenseID; } public String getMotherLMPDate() { return motherLMPDate; diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index c021b13b..a3550de2 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -245,7 +245,7 @@ public String sendFoetalMonitorTestDetails(FoetalMonitor request, String auth) t if (request != null && request.getFoetalMonitorID() > 0) { FoetalMonitorData foetalMonitorTestDetails = new FoetalMonitorData(); - foetalMonitorTestDetails.setPartnerFoetalMonitorID(request.getFoetalMonitorID()); + foetalMonitorTestDetails.setPartnerFetosenseID(request.getFoetalMonitorID()); // send benid in place of benregid to foetalMonitor foetalMonitorTestDetails.setBeneficiaryRegID(benID); From 71faeab67f74aa7c7c3ed334557af5a766ec444a Mon Sep 17 00:00:00 2001 From: Devika Date: Thu, 7 Mar 2024 16:42:21 +0530 Subject: [PATCH 3/8] Corrected GeneratePDF from reportPath --- .../FoetalMonitorServiceImpl.java | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index a3550de2..64283e34 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -176,40 +176,64 @@ public int updateFoetalMonitorData(FoetalMonitor foetalMonitorDataOutside) throw } // generate report file in file storage + private String generatePDF(String filePath) throws IEMRException { - + String filePathLocal = ""; + Long timeStamp = System.currentTimeMillis(); try { - URI tempFilePath1 = URI.create(filePath).normalize(); - String tempFilePath2 = tempFilePath1.toString(); - String sanitizedPath = Paths.get(UriComponentsBuilder.fromPath(tempFilePath2).build().getPath()).toString(); - - URL url = new URL(sanitizedPath); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); + URL url = new URL(filePath); + con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); + con.setDoInput(true); + filePathLocal = foetalMonitorFilePath + "/" + timeStamp.toString() + ".pdf"; + Path path = Paths.get(filePathLocal); + Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); - // "Best Practice": Set headers as needed for the specific API - /* - * con.addRequestProperty("User-Agent", "Your-User-Agent"); - * con.addRequestProperty("Authorization", "Bearer Your-AccessToken"); - * con.setDoInput(true); - */ - - String fileName = System.currentTimeMillis() + ".pdf"; - Path filePathLocal = Paths.get(foetalMonitorFilePath, fileName); - try (InputStream inputStream = con.getInputStream()) { - Files.copy(inputStream, filePathLocal, StandardCopyOption.REPLACE_EXISTING); - } - return filePathLocal.toString(); + // base64 = readPDFANDGetBase64(filePathLocal); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } finally { - if (con != null) { - con.disconnect(); // Close the HTTP connection in the finally block - } + con.disconnect(); } + return filePathLocal; } + +// private String generatePDF(String filePath) throws IEMRException { +// +// try { +// URI tempFilePath1 = URI.create(filePath).normalize(); +// String tempFilePath2 = tempFilePath1.toString(); +// String sanitizedPath = Paths.get(UriComponentsBuilder.fromPath(tempFilePath2).build().getPath()).toString(); +// +// URL url = new URL(sanitizedPath); +// HttpURLConnection con = (HttpURLConnection) url.openConnection(); +// con.setRequestMethod("GET"); +// +// // "Best Practice": Set headers as needed for the specific API +// /* +// * con.addRequestProperty("User-Agent", "Your-User-Agent"); +// * con.addRequestProperty("Authorization", "Bearer Your-AccessToken"); +// * con.setDoInput(true); +// */ +// +// String fileName = System.currentTimeMillis() + ".pdf"; +// Path filePathLocal = Paths.get(foetalMonitorFilePath, fileName); +// try (InputStream inputStream = con.getInputStream()) { +// Files.copy(inputStream, filePathLocal, StandardCopyOption.REPLACE_EXISTING); +// } +// return filePathLocal.toString(); +// +// } catch (IOException e) { +// throw new RuntimeException(e.getMessage()); +// } finally { +// if (con != null) { +// con.disconnect(); // Close the HTTP connection in the finally block +// } +// } +// +// } // generate report file in file storage @Override From 7487ca266cb4fb707aa6d0aadcb0d006a55b886d Mon Sep 17 00:00:00 2001 From: Devika Date: Thu, 7 Mar 2024 17:30:21 +0530 Subject: [PATCH 4/8] Added protocol check condition to identify invalid protocol --- .../tm/service/foetalmonitor/FoetalMonitorServiceImpl.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index 64283e34..a8212e67 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -182,6 +182,11 @@ private String generatePDF(String filePath) throws IEMRException { Long timeStamp = System.currentTimeMillis(); try { URL url = new URL(filePath); + + String protocol = url.getProtocol(); + if(!protocol.equalsIgnoreCase("http") && !protocol.equalsIgnoreCase("https")) { + throw new IllegalArgumentException("Invalid protocol: " + protocol); + } con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); From 692043e987336e1e56762c4d150ebc08e4571499 Mon Sep 17 00:00:00 2001 From: Devika Date: Mon, 11 Mar 2024 17:50:20 +0530 Subject: [PATCH 5/8] Added condition to check filepath --- .../foetalmonitor/FoetalMonitorServiceImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index a8212e67..5d563ed5 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -78,6 +78,8 @@ public class FoetalMonitorServiceImpl implements FoetalMonitorService { private static HttpUtils httpUtils = new HttpUtils(); private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); + + private static final String fetosenseURI = "https://asia-south1-amrit-fetosense.cloudfunctions.net/getGraph"; @Autowired private FoetalMonitorRepo foetalMonitorRepo; @@ -183,17 +185,15 @@ private String generatePDF(String filePath) throws IEMRException { try { URL url = new URL(filePath); - String protocol = url.getProtocol(); - if(!protocol.equalsIgnoreCase("http") && !protocol.equalsIgnoreCase("https")) { - throw new IllegalArgumentException("Invalid protocol: " + protocol); - } + + if(filePath.contains(fetosenseURI)) { con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); filePathLocal = foetalMonitorFilePath + "/" + timeStamp.toString() + ".pdf"; Path path = Paths.get(filePathLocal); Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); - + } // base64 = readPDFANDGetBase64(filePathLocal); } catch (IOException e) { From 7d198311700b691a2362a09e11a09ace5e47632a Mon Sep 17 00:00:00 2001 From: Devika Date: Mon, 11 Mar 2024 18:01:07 +0530 Subject: [PATCH 6/8] Added new URL inside condition check --- .../tm/service/foetalmonitor/FoetalMonitorServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index 5d563ed5..0278dd9d 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -183,10 +183,9 @@ private String generatePDF(String filePath) throws IEMRException { String filePathLocal = ""; Long timeStamp = System.currentTimeMillis(); try { - URL url = new URL(filePath); - - if(filePath.contains(fetosenseURI)) { + + URL url = new URL(filePath); con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); From 0051d32cbb181dd2e46f94e704066bb14698c29b Mon Sep 17 00:00:00 2001 From: Devika Date: Wed, 13 Mar 2024 13:45:47 +0530 Subject: [PATCH 7/8] Added hostname comparison in foetalMonitor update --- .../foetalmonitor/FoetalMonitorServiceImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index 0278dd9d..eb0825e6 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -79,7 +79,7 @@ public class FoetalMonitorServiceImpl implements FoetalMonitorService { private static HttpUtils httpUtils = new HttpUtils(); private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); - private static final String fetosenseURI = "https://asia-south1-amrit-fetosense.cloudfunctions.net/getGraph"; + private static final String fetosenseURI = "asia-south1-amrit-fetosense.cloudfunctions.net"; @Autowired private FoetalMonitorRepo foetalMonitorRepo; @@ -183,17 +183,21 @@ private String generatePDF(String filePath) throws IEMRException { String filePathLocal = ""; Long timeStamp = System.currentTimeMillis(); try { - if(filePath.contains(fetosenseURI)) { - + + URL url = new URL(filePath); + String urlHost= url.getHost(); + logger.info("Fetosense hostname: " + urlHost); + if(urlHost !=null && urlHost.equals(fetosenseURI)) { con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); filePathLocal = foetalMonitorFilePath + "/" + timeStamp.toString() + ".pdf"; Path path = Paths.get(filePathLocal); Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); - } + // base64 = readPDFANDGetBase64(filePathLocal); + } } catch (IOException e) { throw new RuntimeException(e.getMessage()); From 2a9a9e0be0a47aaf7027989266e9f9f647f402ed Mon Sep 17 00:00:00 2001 From: Devika Date: Wed, 13 Mar 2024 14:27:50 +0530 Subject: [PATCH 8/8] fetosense update api - generate pdf changes --- .../service/foetalmonitor/FoetalMonitorServiceImpl.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java index eb0825e6..155a40fa 100644 --- a/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/foetalmonitor/FoetalMonitorServiceImpl.java @@ -79,7 +79,6 @@ public class FoetalMonitorServiceImpl implements FoetalMonitorService { private static HttpUtils httpUtils = new HttpUtils(); private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); - private static final String fetosenseURI = "asia-south1-amrit-fetosense.cloudfunctions.net"; @Autowired private FoetalMonitorRepo foetalMonitorRepo; @@ -186,9 +185,7 @@ private String generatePDF(String filePath) throws IEMRException { URL url = new URL(filePath); - String urlHost= url.getHost(); - logger.info("Fetosense hostname: " + urlHost); - if(urlHost !=null && urlHost.equals(fetosenseURI)) { + con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); @@ -196,8 +193,8 @@ private String generatePDF(String filePath) throws IEMRException { Path path = Paths.get(filePathLocal); Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); - // base64 = readPDFANDGetBase64(filePathLocal); - } + + } catch (IOException e) { throw new RuntimeException(e.getMessage());