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

Develop to master #35

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ public class FoetalMonitorServiceImpl implements FoetalMonitorService {

private static HttpUtils httpUtils = new HttpUtils();
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());


@Autowired
private FoetalMonitorRepo foetalMonitorRepo;
Expand Down Expand Up @@ -176,40 +177,68 @@ 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");

// "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();
con.setDoInput(true);
filePathLocal = foetalMonitorFilePath + "/" + timeStamp.toString() + ".pdf";
Path path = Paths.get(filePathLocal);
Files.copy(con.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);




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