Skip to content

Commit e19ad70

Browse files
authored
Resolve OpenKM download failure and ECG controller access issue (#145)
* fix: add labtech role for ecg controller * fix: add role * fix: url issue in download document * Remove authorization check from getKMFile method Removed authorization check for getKMFile endpoint.
1 parent d887c44 commit e19ad70

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@
6363
<dependency>
6464
<groupId>org.springframework.boot</groupId>
6565
<artifactId>spring-boot-starter</artifactId>
66-
<exclusions>
66+
<!-- <exclusions>
6767
<exclusion>
6868
<groupId>org.springframework.boot</groupId>
6969
<artifactId>spring-boot-starter-logging</artifactId>
7070
</exclusion>
71-
</exclusions>
71+
</exclusions> -->
72+
</dependency>
73+
<dependency>
74+
<groupId>org.slf4j</groupId>
75+
<artifactId>slf4j-api</artifactId>
76+
<version>${slf4j.version}</version>
7277
</dependency>
7378
<dependency>
7479
<groupId>co.elastic.logging</groupId>

src/main/java/com/iemr/tm/controller/common/main/WorklistController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ public String getTCSpecialistWorklistFutureScheduled(
806806
// openkm file download
807807
@Operation(summary = "Add file as string to openKM")
808808
@PostMapping(value = "/getKMFile", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON, headers = "Authorization")
809-
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
810809
public String getKMFile(@Param(value = "{}") @RequestBody String request,
811810
@RequestHeader(value = "Authorization") String Authorization) {
812811
OutputResponse response = new OutputResponse();
@@ -819,6 +818,7 @@ public String getKMFile(@Param(value = "{}") @RequestBody String request,
819818
}
820819
} catch (Exception e) {
821820
logger.error("Error while getting file download url : " + e);
821+
response.setError(5000, "Error while getting file download url");
822822
}
823823
return response.toString();
824824
}

src/main/java/com/iemr/tm/service/common/transaction/CommonServiceImpl.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@
6868
import com.iemr.tm.utils.RestTemplateUtil;
6969
import com.iemr.tm.utils.exception.IEMRException;
7070
import com.iemr.tm.utils.mapper.InputMapper;
71+
import org.slf4j.Logger;
72+
import org.slf4j.LoggerFactory;
7173

7274
import jakarta.servlet.http.HttpServletRequest;
7375

7476
@Service
7577
@PropertySource("classpath:application.properties")
7678
public class CommonServiceImpl implements CommonService {
7779

80+
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
81+
7882
@Value("${openkmDocUrl}")
7983
private String openkmDocUrl;
8084

@@ -559,14 +563,36 @@ public String getOpenKMDocURL(String requestOBJ, String Authorization) throws JS
559563
if (obj.has("fileID")) {
560564
fileUUID = benVisitDetailRepo.getFileUUID(obj.getInt("fileID"));
561565

566+
logger.info("fileUUID for fileID " + obj.getInt("fileID") + " is " + fileUUID);
567+
logger.info("openkmDocUrl is " + openkmDocUrl);
568+
562569
if (fileUUID != null) {
563570
Map<String, Object> requestBody = new HashMap<>();
564571
requestBody.put("fileUID", fileUUID);
565572

566573
HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestBody, Authorization);
567574
ResponseEntity<String> response = restTemplate.exchange(openkmDocUrl, HttpMethod.POST, request,
568575
String.class);
569-
return response.getBody();
576+
logger.info("Response=" + response.getBody());
577+
578+
String responseBody = response.getBody();
579+
if (responseBody != null) {
580+
JSONObject responseObj = new JSONObject(responseBody);
581+
if (responseObj.has("data")) {
582+
Object dataVal = responseObj.get("data");
583+
if (dataVal instanceof JSONObject) {
584+
JSONObject dataObj = (JSONObject) dataVal;
585+
if (dataObj.has("response")) {
586+
String fileUrl = dataObj.getString("response");
587+
// Fix malformed URL: https://user:pass@https://host -> https://user:pass@host
588+
fileUrl = fileUrl.replaceAll("@https?://", "@");
589+
return fileUrl;
590+
}
591+
}
592+
return dataVal.toString();
593+
}
594+
}
595+
return responseBody;
570596
} else
571597
return null;
572598
} else

0 commit comments

Comments
 (0)