Skip to content

Commit 3051876

Browse files
ravishanigarapuhelenKaryamsettyKA40094929
authored
FLW mobile app API changes and flw high risk chanhes in worklist (#147)
* Update application.properties * Swagger changes * AMM-1456 : Skiped jwtToken validation if not present in Cookie or header from mobile request. * Jwtten and user-agent validation * null check * Constants added and null check * Empty check added * Optimized code * removed commented code * Constans and null check added (#134) * Update application.properties * Swagger changes * AMM-1456 : Skiped jwtToken validation if not present in Cookie or header from mobile request. * Jwtten and user-agent validation * null check * Constants added and null check * Empty check added * Optimized code * removed commented code * Exception Handled and Null conditions added * Coderabbit comments addressed * Prescription Template API not working (#139) * Update application.properties * Swagger changes * AMM-1456 : Skiped jwtToken validation if not present in Cookie or header from mobile request. * Jwtten and user-agent validation * null check * Constants added and null check * Empty check added * Optimized code * removed commented code * Exception Handled and Null conditions added * Coderabbit comments addressed * AMM-1473 * AMM-1473 NCDScreening confirmed API change (#144) * Update application.properties * Swagger changes * AMM-1456 : Skiped jwtToken validation if not present in Cookie or header from mobile request. * Jwtten and user-agent validation * null check * Constants added and null check * Empty check added * Optimized code * removed commented code * Exception Handled and Null conditions added * Coderabbit comments addressed * AMM-1473 * fix(bug): added high_risk to worklist to show flw highrisk patients (#145) Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT> * AMM-1733 * AMM-1733 High risk pregnency field added in nurse worklist (#146) * Update application.properties * Swagger changes * AMM-1456 : Skiped jwtToken validation if not present in Cookie or header from mobile request. * Jwtten and user-agent validation * null check * Constants added and null check * Empty check added * Optimized code * removed commented code * Exception Handled and Null conditions added * Coderabbit comments addressed * AMM-1473 * AMM-1733 --------- Co-authored-by: Helen Grace Karyamsetty <133211481+helenKaryamsetty@users.noreply.github.com> Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT>
1 parent 01b10ca commit 3051876

10 files changed

Lines changed: 168 additions & 120 deletions

File tree

src/main/java/com/iemr/hwc/controller/wo/LocationControllerWo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,19 @@ public String updateGeolocationVillage(@RequestBody String requestObj) {
198198
public ResponseEntity<String> getOutreachMasterForState(@PathVariable("stateID") Integer stateID) {
199199
logger.info("get Outreach programs for state with Id ..." + stateID);
200200

201-
OutputResponse outputResponse = new OutputResponse();
201+
OutputResponse response = new OutputResponse();
202202
HttpStatus statusCode = HttpStatus.OK;
203203
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
204204
headers.add("Content-Type", "application/json");
205205

206206
try {
207207
String resList = locationServiceImpl.getOutreachProgramsList(stateID);
208-
outputResponse.setResponse(resList);
208+
response.setResponse(resList);
209209
} catch (Exception e) {
210210
logger.error("Error while fetching outreach list for stateId" + stateID);
211211
response.setError(500, "Unable to fetch outreach list for stateId" + stateID + "Exception - " + e);
212212
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
213213
}
214-
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(), headers, statusCode);
214+
return new ResponseEntity<>(response.toStringWithSerializeNulls(), headers, statusCode);
215215
}
216216
}

src/main/java/com/iemr/hwc/data/benFlowStatus/BeneficiaryFlowStatus.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
import java.util.ArrayList;
2626
import java.util.List;
2727

28+
import com.google.gson.annotations.Expose;
29+
import com.iemr.hwc.annotation.sqlInjectionSafe.SQLInjectionSafe;
30+
import com.iemr.hwc.data.login.MasterVan;
31+
import com.iemr.hwc.data.masterdata.registrar.GenderMaster;
32+
2833
import jakarta.persistence.CascadeType;
2934
import jakarta.persistence.Column;
3035
import jakarta.persistence.Entity;
@@ -36,11 +41,6 @@
3641
import jakarta.persistence.Table;
3742
import jakarta.persistence.Transient;
3843

39-
import com.google.gson.annotations.Expose;
40-
import com.iemr.hwc.annotation.sqlInjectionSafe.SQLInjectionSafe;
41-
import com.iemr.hwc.data.login.MasterVan;
42-
import com.iemr.hwc.data.masterdata.registrar.GenderMaster;
43-
4444
/***
4545
*
4646
* @author NE298657
@@ -296,6 +296,19 @@ public class BeneficiaryFlowStatus {
296296
@Column(name = "referred_visit_id")
297297
private Long referred_visit_id;
298298

299+
300+
@Transient
301+
Boolean is_high_risk;
302+
303+
304+
public Boolean isIs_high_risk() {
305+
return is_high_risk;
306+
}
307+
308+
public void setIs_high_risk(boolean is_high_risk) {
309+
this.is_high_risk = is_high_risk;
310+
}
311+
299312
@Transient
300313
private I_bendemographics i_bendemographics;
301314
@Transient

src/main/java/com/iemr/hwc/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public interface BeneficiaryFlowStatusRepo extends CrudRepository<BeneficiaryFlo
5757
public ArrayList<BeneficiaryFlowStatus> getNurseWorklistNew(
5858
@Param("providerServiceMapId") Integer providerServiceMapId, @Param("vanID") Integer vanID,
5959
@Param("fromDate") Timestamp fromDate);
60-
6160
// nurse worklist TC current date
6261
@Query("SELECT t from BeneficiaryFlowStatus t WHERE (t.specialist_flag != 0 AND t.specialist_flag != 100 AND t.specialist_flag is not null)"
6362
+ " AND t.deleted = false AND DATE(t.benVisitDate) >= DATE(:fromDate) "
@@ -458,5 +457,8 @@ public int updateLabTechnicianFlag(@Param("lab_technician_flag") Short lab_techn
458457

459458
@Query("SELECT COUNT(t) from BeneficiaryFlowStatus t WHERE t.villageID IN :villageIDs AND t.modified_date > :lastModDate ")
460459
Long getFlowRecordsCount(@Param("villageIDs") List<Integer> villageID, @Param("lastModDate") Timestamp lastModDate);
460+
461+
@Query(value = "SELECT is_high_risk from t_anc_visit t WHERE t.ben_id = :ben_id order by 1 desc limit 1",nativeQuery = true)
462+
public Boolean getIsHighrisk(@Param("ben_id") Long ben_id);
461463

462464
}

src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncServiceImpl.java

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -604,36 +604,44 @@ public ResponseEntity<String> savePrescriptionTemplatesToServer(List<Prescriptio
604604
return new ResponseEntity<>(outputResponse.toString(),headers,statusCode);
605605
}
606606

607-
@Override
608-
public ResponseEntity<String> savePrescriptionTemplatesToApp(Integer userID, String authorization) {
609-
OutputResponse outputResponse = new OutputResponse();
610-
HttpStatus statusCode = HttpStatus.OK;
611-
612-
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
613-
headers.add("Content-Type", "application/json");
614-
615-
List<PrescriptionTemplates> templateList = prescriptionTemplatesRepo.getPrescriptionTemplatesByUserID(userID);
616-
617-
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create().toJson(templateList));
618-
619-
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode);
620-
}
621-
622-
@Override
623-
public ResponseEntity<String> deletePrescriptionTemplates(Integer userID, Integer tempID) {
624-
OutputResponse outputResponse = new OutputResponse();
625-
HttpStatus statusCode = HttpStatus.OK;
626-
627-
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
628-
headers.add("Content-Type", "application/json");
629-
630-
prescriptionTemplatesRepo.deletePrescriptionTemplatesByUserIDAndTempID(userID, tempID);
631-
632-
outputResponse.setResponse("Successfully deleted");
633-
634-
return new ResponseEntity<>(outputResponse.toString(),headers,statusCode);
635-
}
636-
607+
@Override
608+
public ResponseEntity<String> savePrescriptionTemplatesToApp(Integer userID, String authorization) {
609+
OutputResponse outputResponse = new OutputResponse();
610+
HttpStatus statusCode = HttpStatus.OK;
611+
612+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
613+
headers.add("Content-Type", "application/json");
614+
try {
615+
List<PrescriptionTemplates> templateList = prescriptionTemplatesRepo
616+
.getPrescriptionTemplatesByUserID(userID);
617+
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls()
618+
.create().toJson(templateList));
619+
} catch (Exception e) {
620+
logger.error("Error while fetching Prescription Templates userID : " + userID);
621+
outputResponse.setError(500, "Unable to fetch Prescription Templates userID" + userID + "Exception - " + e);
622+
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
623+
624+
}
625+
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(), headers, statusCode);
626+
}
627+
628+
@Override
629+
public ResponseEntity<String> deletePrescriptionTemplates(Integer userID, Integer tempID) {
630+
OutputResponse outputResponse = new OutputResponse();
631+
HttpStatus statusCode = HttpStatus.OK;
632+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
633+
headers.add("Content-Type", "application/json");
634+
try {
635+
prescriptionTemplatesRepo.deletePrescriptionTemplatesByUserIDAndTempID(userID, tempID);
636+
outputResponse.setResponse("Successfully deleted");
637+
} catch (Exception e) {
638+
logger.error("Error while deleting Prescription Templates userID : " + userID + " tempID : " + tempID);
639+
outputResponse.setError(500, "Unable to delete Prescription Templates userID : " + userID + " tempID "
640+
+ tempID + "Exception - " + e);
641+
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
642+
}
643+
return new ResponseEntity<>(outputResponse.toString(), headers, statusCode);
644+
}
637645

638646
@Override
639647
public ResponseEntity<String> createNewOutreachActivity(OutreachActivity activity, String authorization) {
@@ -674,45 +682,60 @@ public ResponseEntity<String> createNewOutreachActivity(OutreachActivity activit
674682
return new ResponseEntity<>(outputResponse.toString(),headers,statusCode);
675683
}
676684

677-
@Override
678-
public ResponseEntity<String> getActivitiesByUser(Integer userId, String authorization) {
679-
OutputResponse outputResponse = new OutputResponse();
680-
HttpStatus statusCode = HttpStatus.OK;
681-
682-
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
683-
headers.add("Content-Type", "application/json");
684-
685-
ArrayList<Object[]> activitiesObj = outreachActivityRepo.getActivitiesByUserID(userId);
686-
687-
ArrayList<OutreachActivity> activities = OutreachActivity.getActivitiesForUser(activitiesObj);
688-
689-
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create().toJson(activities));
690-
691-
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode);
692-
}
693-
694-
@Override
695-
public ResponseEntity<String> getActivityById(Integer activityId, String authorization) {
696-
OutputResponse outputResponse = new OutputResponse();
697-
HttpStatus statusCode = HttpStatus.OK;
698-
699-
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
700-
headers.add("Content-Type", "application/json");
701-
702-
OutreachActivity activity = outreachActivityRepo.findById(activityId).get();
703-
704-
if (activity != null && activity.getImg1Data() != null){
705-
String img1 = Base64.getEncoder().encodeToString(activity.getImg1Data());
706-
activity.setImg1(img1);
707-
}
708-
709-
if (activity != null && activity.getImg2Data() != null){
710-
String img2 = Base64.getEncoder().encodeToString(activity.getImg2Data());
711-
activity.setImg2(img2);
712-
}
713-
714-
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create().toJson(activity));
715-
716-
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode);
717-
}
685+
@Override
686+
public ResponseEntity<String> getActivitiesByUser(Integer userId, String authorization) {
687+
OutputResponse outputResponse = new OutputResponse();
688+
HttpStatus statusCode = HttpStatus.OK;
689+
690+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
691+
headers.add("Content-Type", "application/json");
692+
try {
693+
ArrayList<Object[]> activitiesObj = outreachActivityRepo.getActivitiesByUserID(userId);
694+
695+
ArrayList<OutreachActivity> activities = OutreachActivity.getActivitiesForUser(activitiesObj);
696+
697+
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls()
698+
.create().toJson(activities));
699+
} catch (Exception e) {
700+
logger.error("Encountered exception while fetching activity userId : " + userId);
701+
outputResponse.setError(500, "Encountered exception while fetching activity. " + e);
702+
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
703+
}
704+
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(), headers, statusCode);
705+
}
706+
707+
@Override
708+
public ResponseEntity<String> getActivityById(Integer activityId, String authorization) {
709+
OutputResponse outputResponse = new OutputResponse();
710+
HttpStatus statusCode = HttpStatus.OK;
711+
712+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
713+
headers.add("Content-Type", "application/json");
714+
try {
715+
Optional<OutreachActivity> activityOptional = outreachActivityRepo.findById(activityId);
716+
if (activityOptional.isPresent()) {
717+
OutreachActivity activity = activityOptional.get();
718+
if (activity.getImg1Data() != null) {
719+
String img1 = Base64.getEncoder().encodeToString(activity.getImg1Data());
720+
activity.setImg1(img1);
721+
}
722+
723+
if (activity.getImg2Data() != null) {
724+
String img2 = Base64.getEncoder().encodeToString(activity.getImg2Data());
725+
activity.setImg2(img2);
726+
}
727+
728+
outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls()
729+
.create().toJson(activity));
730+
}else {
731+
outputResponse.setError(404, "Activity not found with ID : "+activityId);
732+
statusCode = HttpStatus.NOT_FOUND;
733+
}
734+
} catch (Exception e) {
735+
logger.error("Encountered exception while fetching activity activityId " + activityId);
736+
outputResponse.setError(500, "Encountered exception while fetching activity. " + e);
737+
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
738+
}
739+
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(), headers, statusCode);
740+
}
718741
}

src/main/java/com/iemr/hwc/service/common/transaction/CommonNurseServiceImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,10 +3541,15 @@ public String getNurseWorkListNew(Integer providerServiceMapId, Integer vanID) {
35413541
else
35423542
cal.add(Calendar.DAY_OF_YEAR, -7);
35433543
long sevenDaysAgo = cal.getTimeInMillis();
3544+
Timestamp fromDate = new Timestamp(sevenDaysAgo);
35443545

35453546
ArrayList<BeneficiaryFlowStatus> obj = beneficiaryFlowStatusRepo.getNurseWorklistNew(providerServiceMapId,
3546-
vanID, new Timestamp(sevenDaysAgo));
3547-
3547+
vanID, fromDate);
3548+
for (BeneficiaryFlowStatus beneficiaryFlowStatus : obj) {
3549+
Boolean isHighrisk = beneficiaryFlowStatusRepo.getIsHighrisk(beneficiaryFlowStatus.getBeneficiaryID());
3550+
if(null != isHighrisk)
3551+
beneficiaryFlowStatus.setIs_high_risk(isHighrisk);
3552+
}
35483553
return new Gson().toJson(obj);
35493554
}
35503555

src/main/java/com/iemr/hwc/service/ncdscreening/NCDScreeningServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ public String fetchConfirmedScreeningDisease(Long beneficiaryRegId) throws IEMRE
16971697
List<Object[]> resultSet = hypertensionScreeningRepo.fetchConfirmedScreening(beneficiaryRegId);
16981698
if (resultSet != null && resultSet.size() > 0) {
16991699
for (Object[] obj : resultSet) {
1700-
map.put("beneficiaryRegId", obj[0] != null ? ((BigInteger) obj[0]).longValue() : null);
1700+
map.put("beneficiaryRegId", obj[0] != null ? ((Long) obj[0]) : null);
17011701
if (obj[1] != null && (Boolean) obj[1] == true)
17021702
response.add("Diabetes Mellitus");
17031703
if (obj[2] != null && (Boolean) obj[2] == true)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.iemr.hwc.utils;
2+
3+
public class Constants {
4+
public static final String JWT_TOKEN = "Jwttoken";
5+
public static final String USER_AGENT = "User-Agent";
6+
public static final String OKHTTP = "okhttp";
7+
8+
private Constants() {}
9+
}

src/main/java/com/iemr/hwc/utils/JwtUserIdValidationFilter.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.slf4j.LoggerFactory;
88
import org.springframework.stereotype.Component;
99

10+
import com.iemr.hwc.utils.http.AuthorizationHeaderRequestWrapper;
11+
1012
import jakarta.servlet.Filter;
1113
import jakarta.servlet.FilterChain;
1214
import jakarta.servlet.ServletException;
@@ -74,7 +76,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
7476
}
7577

7678
// Log headers for debugging
77-
String jwtTokenFromHeader = request.getHeader("Jwttoken");
7879
logger.info("JWT token from header: ");
7980

8081
// Skip login and public endpoints
@@ -88,39 +89,33 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
8889
}
8990

9091
try {
91-
String jwtFromCookie = getJwtTokenFromCookies(request);
92-
String jwtFromHeader = request.getHeader("JwtToken");
93-
String authHeader = request.getHeader("Authorization");
94-
95-
if (jwtFromCookie != null) {
96-
logger.info("Validating JWT token from cookie");
97-
if (jwtAuthenticationUtil.validateUserIdAndJwtToken(jwtFromCookie)) {
98-
filterChain.doFilter(servletRequest, servletResponse);
99-
return;
100-
}
101-
}
102-
103-
if (jwtFromHeader != null) {
104-
logger.info("Validating JWT token from header");
105-
if (jwtAuthenticationUtil.validateUserIdAndJwtToken(jwtFromHeader)) {
106-
filterChain.doFilter(servletRequest, servletResponse);
107-
return;
108-
}
109-
}
110-
String userAgent = request.getHeader("User-Agent");
111-
logger.info("User-Agent: " + userAgent);
112-
113-
if (userAgent != null && isMobileClient(userAgent) && authHeader != null) {
114-
filterChain.doFilter(servletRequest, servletResponse);
115-
return;
116-
}
117-
118-
logger.warn("No valid authentication token found");
119-
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized: Invalid or missing token");
120-
92+
String jwtToken = getJwtTokenFromCookies(request);
93+
String jwtFromHeader = request.getHeader(Constants.JWT_TOKEN);
94+
String authHeader = request.getHeader("Authorization");
95+
96+
if ((jwtToken != null && jwtAuthenticationUtil.validateUserIdAndJwtToken(jwtToken)) ||
97+
(jwtFromHeader != null && jwtAuthenticationUtil.validateUserIdAndJwtToken(jwtFromHeader))) {
98+
AuthorizationHeaderRequestWrapper authorizationHeaderRequestWrapper = new AuthorizationHeaderRequestWrapper(request, "");
99+
filterChain.doFilter(authorizationHeaderRequestWrapper, servletResponse);
100+
return;
101+
} else {
102+
String userAgent = request.getHeader(Constants.USER_AGENT);
103+
logger.info("User-Agent: " + userAgent);
104+
if (userAgent != null && isMobileClient(userAgent) && authHeader != null) {
105+
try {
106+
UserAgentContext.setUserAgent(userAgent);
107+
filterChain.doFilter(servletRequest, servletResponse);
108+
} finally {
109+
UserAgentContext.clear();
110+
}
111+
return;
112+
}
113+
}
114+
logger.warn("No valid authentication token found");
115+
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized: Invalid or missing token");
121116
} catch (Exception e) {
122-
logger.error("Authorization error: ", e);
123-
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization error: " + e.getMessage());
117+
logger.error("Authorization error: ", e);
118+
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization error: " + e.getMessage());
124119
}
125120
}
126121

@@ -147,14 +142,14 @@ private boolean isMobileClient(String userAgent) {
147142
if (userAgent == null)
148143
return false;
149144
userAgent = userAgent.toLowerCase();
150-
return userAgent.contains("okhttp"); // iOS (custom clients)
145+
return userAgent.contains(Constants.OKHTTP);
151146
}
152147

153148
private String getJwtTokenFromCookies(HttpServletRequest request) {
154149
Cookie[] cookies = request.getCookies();
155150
if (cookies != null) {
156151
for (Cookie cookie : cookies) {
157-
if (cookie.getName().equals("Jwttoken")) {
152+
if (cookie.getName().equalsIgnoreCase(Constants.JWT_TOKEN)) {
158153
return cookie.getValue();
159154
}
160155
}

0 commit comments

Comments
 (0)