Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetosense API - variable name change and generate PDF correction #34

Merged
merged 10 commits into from
Mar 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@

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;
Expand Down Expand Up @@ -176,40 +178,70 @@
}

// 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);
String urlHost= url.getHost();
logger.info("Fetosense hostname: " + urlHost);
if(urlHost !=null && urlHost.equals(fetosenseURI)) {
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);
con.setDoInput(true);
filePathLocal = foetalMonitorFilePath + "/" + timeStamp.toString() + ".pdf";
Path path = Paths.get(filePathLocal);
Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);

// base64 = readPDFANDGetBase64(filePathLocal);
}
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
}
con.disconnect();
}

return filePathLocal;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove unused code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// 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
Expand Down Expand Up @@ -245,7 +277,7 @@
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);
Expand Down
Loading