From 013f6c27cf52b7c6bfc19d52b2d184921fe74812 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Wed, 27 Sep 2023 14:56:25 +0530
Subject: [PATCH 1/6] Biometric changes

---
 pom.xml                                       |  12 +
 src/main/environment/common_test.properties   |   4 +
 .../biometric/BiometricController.java        |  42 ++++
 .../service/biometric/BiometricService.java   |   7 +
 .../biometric/BiometricServiceImpl.java       | 229 ++++++++++++++++++
 5 files changed, 294 insertions(+)
 create mode 100644 src/main/java/com/iemr/common/controller/biometric/BiometricController.java
 create mode 100644 src/main/java/com/iemr/common/service/biometric/BiometricService.java
 create mode 100644 src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java

diff --git a/pom.xml b/pom.xml
index 8ff8d6e6..131f6f11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,18 @@
 	</repositories>
 	<dependencies>
 
+		<dependency>
+		<groupId>org.apache.httpcomponents</groupId>
+		<artifactId>httpclient</artifactId>
+		
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/xmlpull/xmlpull -->
+<dependency>
+    <groupId>xmlpull</groupId>
+    <artifactId>xmlpull</artifactId>
+    <version>1.1.3.1</version>
+</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter</artifactId>
diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties
index 57e182b6..dba62e8b 100644
--- a/src/main/environment/common_test.properties
+++ b/src/main/environment/common_test.properties
@@ -97,3 +97,7 @@ avniRegistrationLimit=7
 nhm.agent.real.time.data.url= http://175.101.1.83/apps/utility/alive_api.php
 nhm.agent.real.time.data.cron.scheduler=0 */2 * ? * *
 nhm.agent.real.time.data.cron.flag=true
+
+biometric.discover.url = http://127.0.0.1:port/
+biometric.deviceInfo.url = https://127.0.0.1:port/rd/info
+biometric.capture.url = https://127.0.0.1:port/rd/capture
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
new file mode 100644
index 00000000..fa41e914
--- /dev/null
+++ b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
@@ -0,0 +1,42 @@
+package com.iemr.common.controller.biometric;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+ 
+
+import com.iemr.common.service.biometric.BiometricService;
+import com.iemr.common.utils.response.OutputResponse;
+
+ 
+
+import io.swagger.annotations.ApiOperation;
+
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/biometric")
+public class BiometricController {
+	private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
+	@Autowired
+	private BiometricService biometricService;
+	@CrossOrigin
+	@RequestMapping(value = { "/getBiometricData/{pid}" }, method = { RequestMethod.GET })
+	public OutputResponse saveBenNurseDataCAC(@RequestParam String pid) {
+		OutputResponse response = new OutputResponse();
+		try {
+			String pidResponse = biometricService.getBioData(pid);
+			response.setResponse(pidResponse);
+		}catch (Exception e) {
+			logger.error("Error while fetching Biometric data : "+e.getMessage());
+		}
+		return response;
+	}
+}
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricService.java b/src/main/java/com/iemr/common/service/biometric/BiometricService.java
new file mode 100644
index 00000000..af3d400d
--- /dev/null
+++ b/src/main/java/com/iemr/common/service/biometric/BiometricService.java
@@ -0,0 +1,7 @@
+package com.iemr.common.service.biometric;
+
+public interface BiometricService {
+
+	String getBioData(String pid);
+
+}
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
new file mode 100644
index 00000000..422f396a
--- /dev/null
+++ b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
@@ -0,0 +1,229 @@
+package com.iemr.common.service.biometric;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+import java.util.stream.Collectors;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONObject;
+import org.json.XML;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+@Service
+public class BiometricServiceImpl implements BiometricService {
+	private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
+
+	@Value("${biometric.discover.url}")
+	String discoverUrl;
+
+	@Value("${biometric.deviceInfo.url}")
+	private String deviceInfoUrl;
+
+	@Value("${biometric.capture.url}")
+	private String captureUrl;
+	
+	@Override
+	public String getBioData(String env) {
+		String pidRes = null;
+		try {
+			String portNumber = null;
+			for (int i = 11100; i <= 11120; i++) {
+				String port = String.valueOf(i);
+				String apiUrl = discoverUrl.replace("port", port);
+
+				String httpMethod = "RDSERVICE";
+				HttpClient httpClient = HttpClientBuilder.create().build();
+
+				HttpRequestBase request = new HttpRequestBase() {
+					@Override
+					public String getMethod() {
+						return httpMethod;
+					}
+				};
+				request.setURI(URI.create(apiUrl));
+				request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
+				try {
+					HttpResponse response = httpClient.execute((HttpUriRequest) request);
+
+					HttpEntity entity = response.getEntity();
+					String responseString = EntityUtils.toString(entity, "UTF-8");
+					if (!responseString.contains("NOTREADY")) {
+						portNumber = port;
+						break;
+					}
+				} catch (Exception e) {
+					logger.error("Error while checking biometric status: " + e.getMessage());
+				}
+			}
+			String xmlResponse = getDeviceInfo(portNumber, env);
+			if(xmlResponse != null) {
+				JSONObject xmlJSONObj = XML.toJSONObject(xmlResponse);
+				String pidData = xmlJSONObj.get("PidData").toString();
+				JSONObject obj = new JSONObject(pidData);
+				String content = obj.get("Data").toString();
+				JSONObject obj1 = new JSONObject(content);
+				pidRes = obj1.get("content").toString();
+			}
+		} catch (Exception e) {
+			logger.error("Error while getting biometric data: " + e.getMessage());
+		}
+		return pidRes;
+	}
+
+	private String getDeviceInfo(String portNumber, String env) {
+		String deviceRes = null;
+		String deviceInforURL = deviceInfoUrl.replace("port", portNumber);
+
+		String httpMethod = "DEVICEINFO";
+		HttpClient httpClient = HttpClientBuilder.create().build();
+
+		HttpRequestBase request = new HttpRequestBase() {
+			@Override
+			public String getMethod() {
+				return httpMethod;
+			}
+		};
+		request.setURI(URI.create(deviceInforURL));
+		request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
+		try {
+			HttpResponse response = httpClient.execute((HttpUriRequest) request);
+
+			HttpEntity entity = response.getEntity();
+			String responseString = EntityUtils.toString(entity, "UTF-8");
+
+			if (null != response && response.getStatusLine().getStatusCode() == 200) {
+				deviceRes = getCaptureInfo(portNumber, env);
+			}
+		} catch (Exception e) {
+			logger.error("Error while getting biometric device info : " + e.getMessage());
+		}
+		return deviceRes;
+	}
+
+	private String getCaptureInfo(String portNumber, String env) throws Exception {
+		String captureRes = null;
+		if (null != portNumber) {
+			try {
+				// Create a new DocumentBuilder
+				DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+				DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
+
+				// Create a new Document
+				Document doc = docBuilder.newDocument();
+
+				// Create the root element <PidOptions>
+				Element pidOptionsElement = doc.createElement("PidOptions");
+				pidOptionsElement.setAttribute("ver", "1.0");
+				doc.appendChild(pidOptionsElement);
+
+				// Create the <Opts> element and its attributes
+				Element optsElement = doc.createElement("Opts");
+				optsElement.setAttribute("fCount", "1");
+				optsElement.setAttribute("fType", "0");
+				optsElement.setAttribute("iCount", "0");
+				optsElement.setAttribute("pCount", "0");
+				optsElement.setAttribute("pgCount", "2");
+				optsElement.setAttribute("format", "0");
+				optsElement.setAttribute("pidVer", "2.0");
+				optsElement.setAttribute("timeout", "10000");
+				optsElement.setAttribute("pTimeout", "20000");
+				optsElement.setAttribute("posh", "UNKNOWN");
+				optsElement.setAttribute("env", env);
+				pidOptionsElement.appendChild(optsElement);
+
+				// Create the <CustOpts> element
+				Element custOptsElement = doc.createElement("CustOpts");
+				pidOptionsElement.appendChild(custOptsElement);
+
+				// Create the <Param> element inside <CustOpts> with its attributes
+				Element paramElement = doc.createElement("Param");
+				paramElement.setAttribute("name", "mantrakey");
+				paramElement.setAttribute("value", "");
+				custOptsElement.appendChild(paramElement);
+
+				// Create a text node for indentation
+				Text text = doc.createTextNode("\n");
+				pidOptionsElement.insertBefore(text, optsElement);
+
+				// Print the XML content to the console
+				String xml = XMLToString(doc);
+				
+				String captureUrl = "http://127.0.0.1:port/rd/capture";
+				String capturingURL = captureUrl.replace("port", portNumber);
+				URL url = new URL(capturingURL);
+
+				System.out.println(capturingURL);
+
+				String httpMethod = "CAPTURE";
+				HttpClient httpClient = HttpClients.createDefault();
+
+				HttpEntityEnclosingRequestBase request = new HttpEntityEnclosingRequestBase() {
+					@Override
+					public String getMethod() {
+						return httpMethod;
+					}
+				};
+				request.setURI(URI.create(capturingURL));
+				StringEntity entity2 = new StringEntity(xml);
+				request.setEntity(entity2);
+				request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
+				
+				HttpResponse response = httpClient.execute(request);
+				response.setHeader("Content-Type", "TEXT/XML");
+				InputStream entity1 = response.getEntity().getContent();
+				String result = new BufferedReader(new InputStreamReader(entity1))
+						   .lines().collect(Collectors.joining("\n"));
+				if(result.contains("Success")) {
+					captureRes = result;
+				} else {
+					throw new Exception("Capture timed out");
+				}
+				
+		} catch (ParserConfigurationException e) {
+			logger.error("Error while capturing fingerprint: " + e.getMessage());
+		}
+		}
+		return captureRes;
+	}
+
+	private String XMLToString(Document doc) {
+		String response = null;
+		try {
+			javax.xml.transform.TransformerFactory tf = javax.xml.transform.TransformerFactory.newInstance();
+			javax.xml.transform.Transformer transformer = tf.newTransformer();
+			transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+			javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(
+					new java.io.StringWriter());
+			javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(doc);
+			transformer.transform(source, result);
+			response = result.getWriter().toString();
+		} catch (Exception e) {
+			logger.error("Error while converting XML to String: " + e.getMessage());
+		}
+		return response;
+	}
+
+}

From dac5309d057e8bc2241ffaa594324871c65b23a0 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Thu, 28 Sep 2023 15:00:10 +0530
Subject: [PATCH 2/6] biometric device changes

---
 .../common/controller/biometric/BiometricController.java    | 6 ++++--
 .../iemr/common/service/biometric/BiometricServiceImpl.java | 3 ---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
index fa41e914..c95cad9b 100644
--- a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
+++ b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
@@ -4,6 +4,7 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -28,8 +29,9 @@ public class BiometricController {
 	@Autowired
 	private BiometricService biometricService;
 	@CrossOrigin
-	@RequestMapping(value = { "/getBiometricData/{pid}" }, method = { RequestMethod.GET })
-	public OutputResponse saveBenNurseDataCAC(@RequestParam String pid) {
+	@RequestMapping(value = { "/getBiometricData/{pid}" }, method = { RequestMethod.GET }, headers = "Authorization")
+	public OutputResponse saveBenNurseDataCAC(@PathVariable("pid") String pid,
+			@RequestHeader(value = "Authorization") String Authorization) {
 		OutputResponse response = new OutputResponse();
 		try {
 			String pidResponse = biometricService.getBioData(pid);
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
index 422f396a..fec438ea 100644
--- a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
@@ -171,12 +171,9 @@ private String getCaptureInfo(String portNumber, String env) throws Exception {
 				// Print the XML content to the console
 				String xml = XMLToString(doc);
 				
-				String captureUrl = "http://127.0.0.1:port/rd/capture";
 				String capturingURL = captureUrl.replace("port", portNumber);
 				URL url = new URL(capturingURL);
 
-				System.out.println(capturingURL);
-
 				String httpMethod = "CAPTURE";
 				HttpClient httpClient = HttpClients.createDefault();
 

From d20443f5f412e65eba4963d8ce1af56f78f37c41 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Wed, 4 Oct 2023 19:35:30 +0530
Subject: [PATCH 3/6] biometric pid changes

---
 .../controller/biometric/BiometricController.java     |  4 ++--
 .../service/biometric/BiometricServiceImpl.java       | 11 ++++-------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
index c95cad9b..79546c87 100644
--- a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
+++ b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
@@ -30,7 +30,7 @@ public class BiometricController {
 	private BiometricService biometricService;
 	@CrossOrigin
 	@RequestMapping(value = { "/getBiometricData/{pid}" }, method = { RequestMethod.GET }, headers = "Authorization")
-	public OutputResponse saveBenNurseDataCAC(@PathVariable("pid") String pid,
+	public String saveBenNurseDataCAC(@PathVariable("pid") String pid,
 			@RequestHeader(value = "Authorization") String Authorization) {
 		OutputResponse response = new OutputResponse();
 		try {
@@ -39,6 +39,6 @@ public OutputResponse saveBenNurseDataCAC(@PathVariable("pid") String pid,
 		}catch (Exception e) {
 			logger.error("Error while fetching Biometric data : "+e.getMessage());
 		}
-		return response;
+		return response.toString();
 	}
 }
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
index fec438ea..0789ee86 100644
--- a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
@@ -5,6 +5,7 @@
 import java.io.InputStreamReader;
 import java.net.URI;
 import java.net.URL;
+import java.util.Base64;
 import java.util.stream.Collectors;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -80,12 +81,7 @@ public String getMethod() {
 			}
 			String xmlResponse = getDeviceInfo(portNumber, env);
 			if(xmlResponse != null) {
-				JSONObject xmlJSONObj = XML.toJSONObject(xmlResponse);
-				String pidData = xmlJSONObj.get("PidData").toString();
-				JSONObject obj = new JSONObject(pidData);
-				String content = obj.get("Data").toString();
-				JSONObject obj1 = new JSONObject(content);
-				pidRes = obj1.get("content").toString();
+				pidRes = Base64.getEncoder().encodeToString(xmlResponse.getBytes());
 			}
 		} catch (Exception e) {
 			logger.error("Error while getting biometric data: " + e.getMessage());
@@ -142,7 +138,7 @@ private String getCaptureInfo(String portNumber, String env) throws Exception {
 				// Create the <Opts> element and its attributes
 				Element optsElement = doc.createElement("Opts");
 				optsElement.setAttribute("fCount", "1");
-				optsElement.setAttribute("fType", "0");
+				optsElement.setAttribute("fType", "2");
 				optsElement.setAttribute("iCount", "0");
 				optsElement.setAttribute("pCount", "0");
 				optsElement.setAttribute("pgCount", "2");
@@ -150,6 +146,7 @@ private String getCaptureInfo(String portNumber, String env) throws Exception {
 				optsElement.setAttribute("pidVer", "2.0");
 				optsElement.setAttribute("timeout", "10000");
 				optsElement.setAttribute("pTimeout", "20000");
+				optsElement.setAttribute("wadh", "E0jzJ/P8UopUHAieZn8CKqS4WPMi5ZSYXgfnlfkWjrc=");
 				optsElement.setAttribute("posh", "UNKNOWN");
 				optsElement.setAttribute("env", env);
 				pidOptionsElement.appendChild(optsElement);

From c6b15d82bfb451a059eaf02ec8b8f79f725b34e6 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Thu, 5 Oct 2023 11:16:28 +0530
Subject: [PATCH 4/6] removed unused imports

---
 .../esanjeevani/ESanjeevaniServiceImpl.java    | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
index c4b0e409..47def2dc 100644
--- a/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/esanjeevani/ESanjeevaniServiceImpl.java
@@ -1,26 +1,14 @@
 package com.iemr.common.service.esanjeevani;
 
 import java.math.BigInteger;
-
-import java.security.MessageDigest
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
+import java.security.MessageDigest;
 import java.time.LocalDate;
 import java.time.Period;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-import javax.servlet.http.HttpUtils;
-
-import org.apache.commons.codec.digest.DigestUtils;
 import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,8 +17,6 @@
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
-import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
-import org.springframework.http.converter.StringHttpMessageConverter;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -38,14 +24,12 @@
 import org.springframework.util.StringUtils;
 import org.springframework.web.client.RestTemplate;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
 import com.iemr.common.model.esanjeevani.ESanjeevaniPatientAddress;
 import com.iemr.common.model.esanjeevani.ESanjeevaniPatientContactDetail;
 import com.iemr.common.model.esanjeevani.ESanjeevaniPatientRegistration;
 import com.iemr.common.model.esanjeevani.ESanjeevaniProviderAuth;
 import com.iemr.common.repo.esanjeevani.ESanjeevaniRepo;
-import com.iemr.common.utils.config.ConfigProperties;
 
 @Service
 public class ESanjeevaniServiceImpl implements ESanjeevaniService {

From 7232eef3c051c09419312fd8bb471e38e584bf48 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Fri, 17 May 2024 11:43:26 +0530
Subject: [PATCH 5/6] cough file changes

---
 .../lungassessment/LungAssessmentService.java |  2 +-
 .../LungAssessmentServiceImpl.java            | 22 +++++++++----------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentService.java b/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentService.java
index 7ed527b1..5fc1cc48 100644
--- a/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentService.java
+++ b/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentService.java
@@ -27,7 +27,7 @@ public interface LungAssessmentService {
 
 	public String getLungAssessmentAdminLogin(String email, String password) throws Exception;
 
-	public Boolean verifyCough(MultipartFile file, String authToken, Long patientId) throws Exception;
+	public Boolean verifyCough(MultipartFile file, String authToken, Long patientId, String tempFileName) throws Exception;
 
 	String getAssesment(String assesmentId) throws Exception;
 
diff --git a/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentServiceImpl.java b/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentServiceImpl.java
index 8903cd3f..320c7a0a 100644
--- a/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentServiceImpl.java
+++ b/src/main/java/com/iemr/common/service/lungassessment/LungAssessmentServiceImpl.java
@@ -26,7 +26,7 @@
 import java.io.FileOutputStream;
 import java.util.List;
 
-import javax.xml.ws.http.HTTPException;
+//import javax.xml.ws.http.HTTPException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -126,10 +126,11 @@ public String getLungAssessmentAdminLogin(String email, String password) throws
 
 			logger.info("Lung assessment authentication response: " + lungAssessmentToken);
 
-		} catch (HTTPException e) {
-			logger.error("Lung assessment authentication error : " + e.getMessage(), e);
-			throw new RuntimeException("get authentication failed with error", e);
-		} catch (Exception e) {
+		} /*
+			 * catch (HTTPException e) {
+			 * logger.error("Lung assessment authentication error : " + e.getMessage(), e);
+			 * throw new RuntimeException("get authentication failed with error", e); }
+			 */catch (Exception e) {
 			logger.error("Lung assessment authentication error : " + e.getMessage(), e);
 			throw new RuntimeException("get authentication failed with error", e);
 		}
@@ -137,7 +138,7 @@ public String getLungAssessmentAdminLogin(String email, String password) throws
 	}
 
 	@Override
-	public Boolean verifyCough(MultipartFile file, String authToken, Long patientId) throws Exception {
+	public Boolean verifyCough(MultipartFile file, String authToken, Long patientId, String tempFileName) throws Exception {
 
 		try {
 
@@ -157,7 +158,6 @@ public Boolean verifyCough(MultipartFile file, String authToken, Long patientId)
 			headers.add("accessToken", authToken);
 
 			byte[] bytes = file.getBytes();
-			String tempFileName = "coughSoundVerify" + patientId + System.currentTimeMillis() + ".wav";
 			BufferedOutputStream stream = new BufferedOutputStream(
 					new FileOutputStream(new File(lungAssessmentPath + tempFileName)));
 			stream.write(bytes);
@@ -228,7 +228,9 @@ public String initiateAssesment(String request, MultipartFile file) throws Excep
 			if (lungAssessmentToken == null || (((currTime - authCreatedAt) / (60 * 1000))) > 110)
 				lungAssessmentToken = getLungAssessmentAdminLogin(decryptlungAssessmentEmail, decryptlungAssessmentPassword);
 
-			Boolean isCoughValidateSuccess = verifyCough(file, lungAssessmentToken, lungAssessmentAssessmentRequestObj.getPatientId());
+			String tempFileName = "coughSoundAssessment" + lungAssessmentAssessmentRequestObj.getPatientId()
+			+ System.currentTimeMillis() + ".wav";
+			Boolean isCoughValidateSuccess = verifyCough(file, lungAssessmentToken, lungAssessmentAssessmentRequestObj.getPatientId(), tempFileName);
 
 			if (isCoughValidateSuccess) {
 				RestTemplate restTemplate = new RestTemplate();
@@ -241,8 +243,6 @@ public String initiateAssesment(String request, MultipartFile file) throws Excep
 				resultSet = lungAssessmentRepository.save(lungAssessmentAssessmentRequestObj);
 
 				byte[] bytes = file.getBytes();
-				String tempFileName = "coughSoundAssessment" + lungAssessmentAssessmentRequestObj.getPatientId()
-						+ System.currentTimeMillis() + ".wav";
 				BufferedOutputStream stream = new BufferedOutputStream(
 						new FileOutputStream(new File("lungAssessmentPath" + tempFileName)));
 				stream.write(bytes);
@@ -255,7 +255,7 @@ public String initiateAssesment(String request, MultipartFile file) throws Excep
 				bodyMap.add("gender", lungAssessmentAssessmentRequestObj.getGender());
 				bodyMap.add("assessmentId", lungAssessmentAssessmentRequestObj.getAssessmentId());
 				bodyMap.add("patientId", lungAssessmentAssessmentRequestObj.getPatientId());
-				bodyMap.add("coughsoundfile", new FileSystemResource("swaasaPath" + tempFileName));
+				bodyMap.add("coughsoundfile", new FileSystemResource(lungAssessmentPath + tempFileName));
 
 				HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyMap, headers);
 

From 3934e5793d66598032172dc18bc38ec49f542d76 Mon Sep 17 00:00:00 2001
From: Ancy Riju <AN40085822@wipro.com>
Date: Thu, 23 May 2024 12:46:52 +0530
Subject: [PATCH 6/6] discarding biometric changes

---
 pom.xml                                       |  13 -
 src/main/environment/common_test.properties   |   3 -
 .../biometric/BiometricController.java        |  44 ----
 .../service/biometric/BiometricService.java   |   7 -
 .../biometric/BiometricServiceImpl.java       | 223 ------------------
 5 files changed, 290 deletions(-)
 delete mode 100644 src/main/java/com/iemr/common/controller/biometric/BiometricController.java
 delete mode 100644 src/main/java/com/iemr/common/service/biometric/BiometricService.java
 delete mode 100644 src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java

diff --git a/pom.xml b/pom.xml
index 3a9bb7d1..b56a968d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,19 +48,6 @@
 		</repository>
 	</repositories>
 	<dependencies>
-
-		<dependency>
-		<groupId>org.apache.httpcomponents</groupId>
-		<artifactId>httpclient</artifactId>
-		
-		</dependency>
-		<!-- https://mvnrepository.com/artifact/xmlpull/xmlpull -->
-<dependency>
-    <groupId>xmlpull</groupId>
-    <artifactId>xmlpull</artifactId>
-    <version>1.1.3.1</version>
-</dependency>
-
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter</artifactId>
diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties
index 6f25e1a3..5c5514bb 100644
--- a/src/main/environment/common_test.properties
+++ b/src/main/environment/common_test.properties
@@ -157,9 +157,6 @@ eSanjeevani.source: 11001
 eSanjeevani.registerPatient: https://preprod.esanjeevaniopd.xyz/uat/ps/api/v1/Patient
 eSanjeevani.routeUrl: https://uat.esanjeevani.in/user/signin
 
-biometric.discover.url = http://127.0.0.1:port/
-biometric.deviceInfo.url = http://127.0.0.1:port/rd/info
-biometric.capture.url = http://127.0.0.1:port/rd/capture
 eAusadhaUrl=https://dlc.kar.nic.in/e-services/api/DWInstituteInward
 
 eausadhaAuthorization=<Enter eausadha authorization key>
diff --git a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java b/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
deleted file mode 100644
index 79546c87..00000000
--- a/src/main/java/com/iemr/common/controller/biometric/BiometricController.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.iemr.common.controller.biometric;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
- 
-
-import com.iemr.common.service.biometric.BiometricService;
-import com.iemr.common.utils.response.OutputResponse;
-
- 
-
-import io.swagger.annotations.ApiOperation;
-
-@CrossOrigin
-@RestController
-@RequestMapping(value = "/biometric")
-public class BiometricController {
-	private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
-	@Autowired
-	private BiometricService biometricService;
-	@CrossOrigin
-	@RequestMapping(value = { "/getBiometricData/{pid}" }, method = { RequestMethod.GET }, headers = "Authorization")
-	public String saveBenNurseDataCAC(@PathVariable("pid") String pid,
-			@RequestHeader(value = "Authorization") String Authorization) {
-		OutputResponse response = new OutputResponse();
-		try {
-			String pidResponse = biometricService.getBioData(pid);
-			response.setResponse(pidResponse);
-		}catch (Exception e) {
-			logger.error("Error while fetching Biometric data : "+e.getMessage());
-		}
-		return response.toString();
-	}
-}
\ No newline at end of file
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricService.java b/src/main/java/com/iemr/common/service/biometric/BiometricService.java
deleted file mode 100644
index af3d400d..00000000
--- a/src/main/java/com/iemr/common/service/biometric/BiometricService.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.iemr.common.service.biometric;
-
-public interface BiometricService {
-
-	String getBioData(String pid);
-
-}
diff --git a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java b/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
deleted file mode 100644
index 0789ee86..00000000
--- a/src/main/java/com/iemr/common/service/biometric/BiometricServiceImpl.java
+++ /dev/null
@@ -1,223 +0,0 @@
-package com.iemr.common.service.biometric;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URI;
-import java.net.URL;
-import java.util.Base64;
-import java.util.stream.Collectors;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-import org.json.JSONObject;
-import org.json.XML;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Text;
-
-@Service
-public class BiometricServiceImpl implements BiometricService {
-	private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
-
-	@Value("${biometric.discover.url}")
-	String discoverUrl;
-
-	@Value("${biometric.deviceInfo.url}")
-	private String deviceInfoUrl;
-
-	@Value("${biometric.capture.url}")
-	private String captureUrl;
-	
-	@Override
-	public String getBioData(String env) {
-		String pidRes = null;
-		try {
-			String portNumber = null;
-			for (int i = 11100; i <= 11120; i++) {
-				String port = String.valueOf(i);
-				String apiUrl = discoverUrl.replace("port", port);
-
-				String httpMethod = "RDSERVICE";
-				HttpClient httpClient = HttpClientBuilder.create().build();
-
-				HttpRequestBase request = new HttpRequestBase() {
-					@Override
-					public String getMethod() {
-						return httpMethod;
-					}
-				};
-				request.setURI(URI.create(apiUrl));
-				request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
-				try {
-					HttpResponse response = httpClient.execute((HttpUriRequest) request);
-
-					HttpEntity entity = response.getEntity();
-					String responseString = EntityUtils.toString(entity, "UTF-8");
-					if (!responseString.contains("NOTREADY")) {
-						portNumber = port;
-						break;
-					}
-				} catch (Exception e) {
-					logger.error("Error while checking biometric status: " + e.getMessage());
-				}
-			}
-			String xmlResponse = getDeviceInfo(portNumber, env);
-			if(xmlResponse != null) {
-				pidRes = Base64.getEncoder().encodeToString(xmlResponse.getBytes());
-			}
-		} catch (Exception e) {
-			logger.error("Error while getting biometric data: " + e.getMessage());
-		}
-		return pidRes;
-	}
-
-	private String getDeviceInfo(String portNumber, String env) {
-		String deviceRes = null;
-		String deviceInforURL = deviceInfoUrl.replace("port", portNumber);
-
-		String httpMethod = "DEVICEINFO";
-		HttpClient httpClient = HttpClientBuilder.create().build();
-
-		HttpRequestBase request = new HttpRequestBase() {
-			@Override
-			public String getMethod() {
-				return httpMethod;
-			}
-		};
-		request.setURI(URI.create(deviceInforURL));
-		request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
-		try {
-			HttpResponse response = httpClient.execute((HttpUriRequest) request);
-
-			HttpEntity entity = response.getEntity();
-			String responseString = EntityUtils.toString(entity, "UTF-8");
-
-			if (null != response && response.getStatusLine().getStatusCode() == 200) {
-				deviceRes = getCaptureInfo(portNumber, env);
-			}
-		} catch (Exception e) {
-			logger.error("Error while getting biometric device info : " + e.getMessage());
-		}
-		return deviceRes;
-	}
-
-	private String getCaptureInfo(String portNumber, String env) throws Exception {
-		String captureRes = null;
-		if (null != portNumber) {
-			try {
-				// Create a new DocumentBuilder
-				DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-				DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
-
-				// Create a new Document
-				Document doc = docBuilder.newDocument();
-
-				// Create the root element <PidOptions>
-				Element pidOptionsElement = doc.createElement("PidOptions");
-				pidOptionsElement.setAttribute("ver", "1.0");
-				doc.appendChild(pidOptionsElement);
-
-				// Create the <Opts> element and its attributes
-				Element optsElement = doc.createElement("Opts");
-				optsElement.setAttribute("fCount", "1");
-				optsElement.setAttribute("fType", "2");
-				optsElement.setAttribute("iCount", "0");
-				optsElement.setAttribute("pCount", "0");
-				optsElement.setAttribute("pgCount", "2");
-				optsElement.setAttribute("format", "0");
-				optsElement.setAttribute("pidVer", "2.0");
-				optsElement.setAttribute("timeout", "10000");
-				optsElement.setAttribute("pTimeout", "20000");
-				optsElement.setAttribute("wadh", "E0jzJ/P8UopUHAieZn8CKqS4WPMi5ZSYXgfnlfkWjrc=");
-				optsElement.setAttribute("posh", "UNKNOWN");
-				optsElement.setAttribute("env", env);
-				pidOptionsElement.appendChild(optsElement);
-
-				// Create the <CustOpts> element
-				Element custOptsElement = doc.createElement("CustOpts");
-				pidOptionsElement.appendChild(custOptsElement);
-
-				// Create the <Param> element inside <CustOpts> with its attributes
-				Element paramElement = doc.createElement("Param");
-				paramElement.setAttribute("name", "mantrakey");
-				paramElement.setAttribute("value", "");
-				custOptsElement.appendChild(paramElement);
-
-				// Create a text node for indentation
-				Text text = doc.createTextNode("\n");
-				pidOptionsElement.insertBefore(text, optsElement);
-
-				// Print the XML content to the console
-				String xml = XMLToString(doc);
-				
-				String capturingURL = captureUrl.replace("port", portNumber);
-				URL url = new URL(capturingURL);
-
-				String httpMethod = "CAPTURE";
-				HttpClient httpClient = HttpClients.createDefault();
-
-				HttpEntityEnclosingRequestBase request = new HttpEntityEnclosingRequestBase() {
-					@Override
-					public String getMethod() {
-						return httpMethod;
-					}
-				};
-				request.setURI(URI.create(capturingURL));
-				StringEntity entity2 = new StringEntity(xml);
-				request.setEntity(entity2);
-				request.setHeader(HttpHeaders.CONTENT_TYPE, "TEXT/XML");
-				
-				HttpResponse response = httpClient.execute(request);
-				response.setHeader("Content-Type", "TEXT/XML");
-				InputStream entity1 = response.getEntity().getContent();
-				String result = new BufferedReader(new InputStreamReader(entity1))
-						   .lines().collect(Collectors.joining("\n"));
-				if(result.contains("Success")) {
-					captureRes = result;
-				} else {
-					throw new Exception("Capture timed out");
-				}
-				
-		} catch (ParserConfigurationException e) {
-			logger.error("Error while capturing fingerprint: " + e.getMessage());
-		}
-		}
-		return captureRes;
-	}
-
-	private String XMLToString(Document doc) {
-		String response = null;
-		try {
-			javax.xml.transform.TransformerFactory tf = javax.xml.transform.TransformerFactory.newInstance();
-			javax.xml.transform.Transformer transformer = tf.newTransformer();
-			transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
-			javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(
-					new java.io.StringWriter());
-			javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(doc);
-			transformer.transform(source, result);
-			response = result.getWriter().toString();
-		} catch (Exception e) {
-			logger.error("Error while converting XML to String: " + e.getMessage());
-		}
-		return response;
-	}
-
-}
