From 0d42484d894a6b3c7c3c272e6d6e6402baaccb6a Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Fri, 8 Sep 2023 03:20:38 +0000 Subject: [PATCH 1/7] Implement save fingerprints for a user --- .../hwc/controller/wo/UserBiomectrics.java | 60 +++++++++ .../iemr/hwc/data/registrar/FingerPrint.java | 9 ++ .../hwc/data/registrar/FingerPrintDTO.java | 12 ++ .../data/registrar/UserBiometricsMapping.java | 114 ++++++++++++++++++ .../repo/registrar/UserBiometricsRepo.java | 13 ++ .../hwc/repo/videoconsultation/UserRepo.java | 3 + .../registrar/RegistrarServiceImpl.java | 74 +++++++++--- 7 files changed, 268 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java create mode 100644 src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java create mode 100644 src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java create mode 100644 src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java create mode 100644 src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java diff --git a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java new file mode 100644 index 00000000..f7158eb4 --- /dev/null +++ b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java @@ -0,0 +1,60 @@ +package com.iemr.hwc.controller.wo; + +import com.iemr.hwc.controller.common.master.CommonMasterController; +import com.iemr.hwc.data.registrar.FingerPrintDTO; +import com.iemr.hwc.service.location.LocationServiceImpl; +import com.iemr.hwc.service.registrar.RegistrarServiceImpl; +import com.iemr.hwc.utils.response.OutputResponse; +import io.swagger.annotations.ApiOperation; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@CrossOrigin +@RestController +@RequestMapping(value = "wo/user_biometrics") +public class UserBiomectrics { + // private OutputResponse response; + private Logger logger = LoggerFactory.getLogger(CommonMasterController.class); + + private LocationServiceImpl locationServiceImpl; + + @Autowired + public void setLocationServiceImpl(LocationServiceImpl locationServiceImpl) { + this.locationServiceImpl = locationServiceImpl; + } + + @Autowired + private RegistrarServiceImpl registrarService; + @CrossOrigin() + @ApiOperation(value = "add fingerprint for a given username", consumes = "application/json", produces = "application/json") + @RequestMapping(value = "add/fingerprint/wo", method = { RequestMethod.POST }, produces = { + "application/json" }) + public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { + OutputResponse response = new OutputResponse(); + try { + if (comingRequest != null && comingRequest.getUserName() != null && !comingRequest.getFp().isEmpty()) { + String resp = registrarService.saveFingerprints(comingRequest); + if(resp !=null && resp.equals("ok")){ + response.setResponse(resp); + } + else if(resp !=null && resp.equals("ko")){ + response.setError(500, "Error adding fingerprints"); + } + else if(resp !=null && resp.equals("bad_request")){ + response.setError(500, "Invalid request"); + } + } else { + response.setError(5000, "Invalid request"); + } + } catch (Exception e) { + logger.error(e.getMessage()); + response.setError(5000, "Error while adding fingerprints data"); + } + return response.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java b/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java new file mode 100644 index 00000000..76db0cbf --- /dev/null +++ b/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java @@ -0,0 +1,9 @@ +package com.iemr.hwc.data.registrar; + +import lombok.Data; + +@Data +public class FingerPrint { + private String fpVal; + private String fingerType; +} diff --git a/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java b/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java new file mode 100644 index 00000000..0ba0e8e0 --- /dev/null +++ b/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java @@ -0,0 +1,12 @@ +package com.iemr.hwc.data.registrar; + +import lombok.Data; + +import java.util.List; + +@Data +public class FingerPrintDTO { + private Integer id; + private String userName; + private List fp; +} \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java b/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java new file mode 100644 index 00000000..41a972a9 --- /dev/null +++ b/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java @@ -0,0 +1,114 @@ +package com.iemr.hwc.data.registrar; + +/* + * AMRIT – Accessible Medical Records via Integrated Technology + * Integrated EHR (Electronic Health Records) Solution + * + * Copyright (C) "Piramal Swasthya Management and Research Institute" + * + * This file is part of AMRIT. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +import com.google.gson.annotations.Expose; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.sql.Timestamp; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "m_userbiometricmapping") +public class UserBiometricsMapping { + + @Id + @GeneratedValue + @Expose + @Column(name = "UserBiometricMapID", insertable = false) + private Long userBiometricMapID; + + @Expose + @Column(name = "UserID") + private Long userID; + + @Expose + @Column(name = "FirstName") + private String firstName; + + @Expose + @Column(name = "LastName") + private String lastName; + + @Expose + @Column(name = "UserName") + private String userName; + + @Expose + @Column(name = "GUID_LeftFinger") + private String gUIDLeftFinger; + + @Expose + @Column(name = "GUID_RightFinger") + private String gUIDRightFinger; + + @Expose + @Column(name = "Deleted", insertable = false, updatable = true) + private Boolean deleted; + + @Expose + @Column(name = "Processed", insertable = false) + private String processed; + + @Expose + @Column(name = "CreatedBy", updatable = false) + private String createdBy; + + @Expose + @Column(name = "CreatedDate", insertable = false, updatable = false) + private Timestamp createdDate; + + @Expose + @Column(name = "ModifiedBy", insertable = false, updatable = true) + private String modifiedBy; + + @Expose + @Column(name = "LastModDate", insertable = false, updatable = false) + private Timestamp lastModDate; + + @Expose + @Lob + @Column(name = "right_thumb") + private String rightThumb; + + @Expose + @Lob + @Column(name = "right_index_finger") + private String rightIndexFinger; + + @Expose + @Lob + @Column(name = "left_thumb") + private String leftThumb; + + @Expose + @Lob + @Column(name = "left_index_finger") + private String leftIndexFinger; + +} \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java new file mode 100644 index 00000000..345cf217 --- /dev/null +++ b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java @@ -0,0 +1,13 @@ +package com.iemr.hwc.repo.registrar; + +import com.iemr.hwc.data.registrar.UserBiometricsMapping; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.stereotype.Repository; + + +@Repository +@RestResource(exported = false) +public interface UserBiometricsRepo extends CrudRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java b/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java index 8b74a5cd..59ea37a0 100644 --- a/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java +++ b/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java @@ -36,4 +36,7 @@ public interface UserRepo extends CrudRepository { @Query(value="select u from M_UserTemp u left join u.userSwymed user where u.userID=:userID and user.userID=:userID") M_UserTemp findOneMap(@Param("userID")Long userid); + @Query(" SELECT u FROM M_UserTemp u WHERE u.UserName = :UserName AND u.Deleted = false ") + public M_UserTemp getUserByUsername(@Param("UserName") String username); + } diff --git a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java index d2079f7f..3d077ada 100644 --- a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java @@ -28,6 +28,10 @@ import javax.ws.rs.core.MediaType; +import com.iemr.hwc.data.registrar.*; +import com.iemr.hwc.data.videoconsultation.M_UserTemp; +import com.iemr.hwc.repo.registrar.*; +import com.iemr.hwc.repo.videoconsultation.UserRepo; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,23 +50,6 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus; -import com.iemr.hwc.data.registrar.BenGovIdMapping; -import com.iemr.hwc.data.registrar.BeneficiaryData; -import com.iemr.hwc.data.registrar.BeneficiaryDemographicAdditional; -import com.iemr.hwc.data.registrar.BeneficiaryDemographicData; -import com.iemr.hwc.data.registrar.BeneficiaryImage; -import com.iemr.hwc.data.registrar.BeneficiaryPhoneMapping; -import com.iemr.hwc.data.registrar.FetchBeneficiaryDetails; -import com.iemr.hwc.data.registrar.V_BenAdvanceSearch; -import com.iemr.hwc.data.registrar.WrapperRegWorklist; -import com.iemr.hwc.repo.registrar.BeneficiaryDemographicAdditionalRepo; -import com.iemr.hwc.repo.registrar.BeneficiaryImageRepo; -import com.iemr.hwc.repo.registrar.RegistrarRepoBenData; -import com.iemr.hwc.repo.registrar.RegistrarRepoBenDemoData; -import com.iemr.hwc.repo.registrar.RegistrarRepoBenGovIdMapping; -import com.iemr.hwc.repo.registrar.RegistrarRepoBenPhoneMapData; -import com.iemr.hwc.repo.registrar.RegistrarRepoBeneficiaryDetails; -import com.iemr.hwc.repo.registrar.ReistrarRepoBenSearch; import com.iemr.hwc.service.benFlowStatus.CommonBenStatusFlowServiceImpl; import com.iemr.hwc.utils.mapper.InputMapper; import com.iemr.hwc.utils.response.OutputResponse; @@ -105,6 +92,12 @@ public class RegistrarServiceImpl implements RegistrarService { private BeneficiaryImageRepo beneficiaryImageRepo; private CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl; + @Autowired + private UserRepo userRepo; + + @Autowired + private UserBiometricsRepo userBiometricsRepo; + @Autowired public void setCommonBenStatusFlowServiceImpl(CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl) { this.commonBenStatusFlowServiceImpl = commonBenStatusFlowServiceImpl; @@ -848,4 +841,51 @@ public int searchAndSubmitBeneficiaryToNurse(String requestOBJ) throws Exception int i = commonBenStatusFlowServiceImpl.createBenFlowRecord(requestOBJ, null, null); return i; } + + public String saveFingerprints(FingerPrintDTO comingRequest) { + String response = ""; + M_UserTemp user = userRepo.getUserByUsername(comingRequest.getUserName()); + if(user !=null){ + UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping(); + userBiometricsMapping.setUserID(user.getUserID()); + userBiometricsMapping.setFirstName(user.getFirstName()); + userBiometricsMapping.setLastName(user.getLastName()); + userBiometricsMapping.setUserName(user.getUserName()); + userBiometricsMapping.setCreatedBy(user.getUserName()); + + for(FingerPrint finger: comingRequest.getFp()){ + if(finger.getFingerType()!=null && !finger.getFingerType().isEmpty() && finger.getFpVal()!=null && !finger.getFpVal().isEmpty()){ + if(finger.getFingerType().equals("right_thumb")){ + userBiometricsMapping.setRightThumb(finger.getFpVal()); + } + else if(finger.getFingerType().equals("right_index_finger")){ + userBiometricsMapping.setRightIndexFinger(finger.getFpVal()); + } + else if(finger.getFingerType().equals("left_thumb")){ + userBiometricsMapping.setLeftThumb(finger.getFpVal()); + } + else if(finger.getFingerType().equals("left_index_finger")){ + userBiometricsMapping.setLeftIndexFinger(finger.getFpVal()); + } + } + else{ + response = "bad_request"; + break; + } + } + + UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping); + if(resp !=null){ + response = "ok"; + } + else{ + response = "ko"; + } + } + else{ + response = "wrong username"; + } + + return response; + } } From d6b307fb6f83907037b262b8ef70ae96ec1fc42b Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Fri, 8 Sep 2023 19:08:32 +0000 Subject: [PATCH 2/7] Add API to get for a user Fix issue from reviewer --- .../hwc/controller/wo/UserBiomectrics.java | 46 +++++++++++++------ .../java/com/iemr/hwc/data/login/Users.java | 2 + .../iemr/hwc/data/registrar/FingerPrint.java | 9 ---- .../hwc/data/registrar/FingerPrintDTO.java | 5 +- .../com/iemr/hwc/repo/login/UserRepo.java | 38 +++++++++++++++ .../repo/registrar/UserBiometricsRepo.java | 5 ++ .../hwc/repo/videoconsultation/UserRepo.java | 3 -- .../registrar/RegistrarServiceImpl.java | 36 ++++++--------- 8 files changed, 95 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java create mode 100644 src/main/java/com/iemr/hwc/repo/login/UserRepo.java diff --git a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java index f7158eb4..eb78a6da 100644 --- a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java @@ -1,7 +1,9 @@ package com.iemr.hwc.controller.wo; +import com.google.gson.Gson; import com.iemr.hwc.controller.common.master.CommonMasterController; import com.iemr.hwc.data.registrar.FingerPrintDTO; +import com.iemr.hwc.data.registrar.UserBiometricsMapping; import com.iemr.hwc.service.location.LocationServiceImpl; import com.iemr.hwc.service.registrar.RegistrarServiceImpl; import com.iemr.hwc.utils.response.OutputResponse; @@ -21,13 +23,6 @@ public class UserBiomectrics { // private OutputResponse response; private Logger logger = LoggerFactory.getLogger(CommonMasterController.class); - private LocationServiceImpl locationServiceImpl; - - @Autowired - public void setLocationServiceImpl(LocationServiceImpl locationServiceImpl) { - this.locationServiceImpl = locationServiceImpl; - } - @Autowired private RegistrarServiceImpl registrarService; @CrossOrigin() @@ -37,7 +32,7 @@ public void setLocationServiceImpl(LocationServiceImpl locationServiceImpl) { public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { OutputResponse response = new OutputResponse(); try { - if (comingRequest != null && comingRequest.getUserName() != null && !comingRequest.getFp().isEmpty()) { + if (comingRequest != null && comingRequest.getUserName() != null) { String resp = registrarService.saveFingerprints(comingRequest); if(resp !=null && resp.equals("ok")){ response.setResponse(resp); @@ -45,16 +40,41 @@ public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { else if(resp !=null && resp.equals("ko")){ response.setError(500, "Error adding fingerprints"); } - else if(resp !=null && resp.equals("bad_request")){ - response.setError(500, "Invalid request"); - } } else { - response.setError(5000, "Invalid request"); + response.setError(400, "Invalid request"); } } catch (Exception e) { logger.error(e.getMessage()); - response.setError(5000, "Error while adding fingerprints data"); + response.setError(500, "Error while adding fingerprints data"); + } + return response.toString(); + } + + @ApiOperation(value = "Get fingerprint by username", consumes = "application/json", produces = "application/json") + @RequestMapping(value = "/get/fingerprint/{userID}/wo", method = RequestMethod.GET) + public String getVillageByDistrictID(@PathVariable("userID") Integer userID) { + logger.info("Get fingerprint by username ..." + userID); + OutputResponse response = new OutputResponse(); + UserBiometricsMapping user = registrarService.getFingerprintsByUserID(userID); + if (user != null){ + Gson gson = new Gson(); + UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping(); + userBiometricsMapping.setUserID(user.getUserID()); + userBiometricsMapping.setFirstName(user.getFirstName()); + userBiometricsMapping.setLastName(user.getLastName()); + userBiometricsMapping.setUserName(user.getUserName()); + userBiometricsMapping.setCreatedBy(user.getUserName()); + userBiometricsMapping.setRightThumb(user.getRightThumb()); + userBiometricsMapping.setRightIndexFinger(user.getRightIndexFinger()); + userBiometricsMapping.setLeftThumb(user.getLeftThumb()); + userBiometricsMapping.setLeftIndexFinger(user.getLeftIndexFinger()); + + response.setResponse(gson.toJson(userBiometricsMapping)); + } + else{ + response.setError(404, "User with userID: "+userID+" not found"); } + logger.info("village master" + response.toString()); return response.toString(); } } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/data/login/Users.java b/src/main/java/com/iemr/hwc/data/login/Users.java index 88a312e5..bb2186cb 100644 --- a/src/main/java/com/iemr/hwc/data/login/Users.java +++ b/src/main/java/com/iemr/hwc/data/login/Users.java @@ -31,7 +31,9 @@ import javax.persistence.Table; import com.google.gson.annotations.Expose; +import lombok.Data; +@Data @Entity @Table(name = "m_user") public class Users { diff --git a/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java b/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java deleted file mode 100644 index 76db0cbf..00000000 --- a/src/main/java/com/iemr/hwc/data/registrar/FingerPrint.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.iemr.hwc.data.registrar; - -import lombok.Data; - -@Data -public class FingerPrint { - private String fpVal; - private String fingerType; -} diff --git a/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java b/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java index 0ba0e8e0..6b746d3d 100644 --- a/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java +++ b/src/main/java/com/iemr/hwc/data/registrar/FingerPrintDTO.java @@ -8,5 +8,8 @@ public class FingerPrintDTO { private Integer id; private String userName; - private List fp; + private String rightThumb; + private String rightIndexFinger; + private String leftThumb; + private String leftIndexFinger; } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/repo/login/UserRepo.java b/src/main/java/com/iemr/hwc/repo/login/UserRepo.java new file mode 100644 index 00000000..11160969 --- /dev/null +++ b/src/main/java/com/iemr/hwc/repo/login/UserRepo.java @@ -0,0 +1,38 @@ +/* +* AMRIT – Accessible Medical Records via Integrated Technology +* Integrated EHR (Electronic Health Records) Solution +* +* Copyright (C) "Piramal Swasthya Management and Research Institute" +* +* This file is part of AMRIT. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see https://www.gnu.org/licenses/. +*/ +package com.iemr.hwc.repo.login; + +import com.iemr.hwc.data.login.Users; +import com.iemr.hwc.data.videoconsultation.M_UserTemp; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RestResource; +import org.springframework.stereotype.Repository; + +@Repository +@RestResource(exported = false) +public interface UserRepo extends CrudRepository { + @Query(" SELECT u FROM M_UserTemp u WHERE u.UserName = :UserName AND u.Deleted = false ") + public Users getUserByUsername(@Param("UserName") String username); + +} diff --git a/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java index 345cf217..b8269a59 100644 --- a/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java +++ b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java @@ -1,7 +1,10 @@ package com.iemr.hwc.repo.registrar; +import com.iemr.hwc.data.login.Users; import com.iemr.hwc.data.registrar.UserBiometricsMapping; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.stereotype.Repository; @@ -9,5 +12,7 @@ @Repository @RestResource(exported = false) public interface UserBiometricsRepo extends CrudRepository { + @Query(" SELECT u FROM UserBiometricsMapping u WHERE u.userID = :userID AND u.deleted = false ") + public UserBiometricsMapping getFingerprintsByUserID(@Param("userID") Integer userID); } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java b/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java index 59ea37a0..8b74a5cd 100644 --- a/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java +++ b/src/main/java/com/iemr/hwc/repo/videoconsultation/UserRepo.java @@ -36,7 +36,4 @@ public interface UserRepo extends CrudRepository { @Query(value="select u from M_UserTemp u left join u.userSwymed user where u.userID=:userID and user.userID=:userID") M_UserTemp findOneMap(@Param("userID")Long userid); - @Query(" SELECT u FROM M_UserTemp u WHERE u.UserName = :UserName AND u.Deleted = false ") - public M_UserTemp getUserByUsername(@Param("UserName") String username); - } diff --git a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java index 3d077ada..a3b16649 100644 --- a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java @@ -28,10 +28,12 @@ import javax.ws.rs.core.MediaType; +import com.iemr.hwc.data.location.DistrictBranchMapping; +import com.iemr.hwc.data.login.Users; import com.iemr.hwc.data.registrar.*; import com.iemr.hwc.data.videoconsultation.M_UserTemp; +import com.iemr.hwc.repo.login.UserRepo; import com.iemr.hwc.repo.registrar.*; -import com.iemr.hwc.repo.videoconsultation.UserRepo; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -844,7 +846,7 @@ public int searchAndSubmitBeneficiaryToNurse(String requestOBJ) throws Exception public String saveFingerprints(FingerPrintDTO comingRequest) { String response = ""; - M_UserTemp user = userRepo.getUserByUsername(comingRequest.getUserName()); + Users user = userRepo.getUserByUsername(comingRequest.getUserName()); if(user !=null){ UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping(); userBiometricsMapping.setUserID(user.getUserID()); @@ -852,27 +854,10 @@ public String saveFingerprints(FingerPrintDTO comingRequest) { userBiometricsMapping.setLastName(user.getLastName()); userBiometricsMapping.setUserName(user.getUserName()); userBiometricsMapping.setCreatedBy(user.getUserName()); - - for(FingerPrint finger: comingRequest.getFp()){ - if(finger.getFingerType()!=null && !finger.getFingerType().isEmpty() && finger.getFpVal()!=null && !finger.getFpVal().isEmpty()){ - if(finger.getFingerType().equals("right_thumb")){ - userBiometricsMapping.setRightThumb(finger.getFpVal()); - } - else if(finger.getFingerType().equals("right_index_finger")){ - userBiometricsMapping.setRightIndexFinger(finger.getFpVal()); - } - else if(finger.getFingerType().equals("left_thumb")){ - userBiometricsMapping.setLeftThumb(finger.getFpVal()); - } - else if(finger.getFingerType().equals("left_index_finger")){ - userBiometricsMapping.setLeftIndexFinger(finger.getFpVal()); - } - } - else{ - response = "bad_request"; - break; - } - } + userBiometricsMapping.setRightThumb(comingRequest.getRightThumb()); + userBiometricsMapping.setRightIndexFinger(comingRequest.getRightIndexFinger()); + userBiometricsMapping.setLeftThumb(comingRequest.getLeftThumb()); + userBiometricsMapping.setLeftIndexFinger(comingRequest.getLeftIndexFinger()); UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping); if(resp !=null){ @@ -888,4 +873,9 @@ else if(finger.getFingerType().equals("left_index_finger")){ return response; } + + public UserBiometricsMapping getFingerprintsByUserID(Integer userID) { + UserBiometricsMapping user = userBiometricsRepo.getFingerprintsByUserID(userID); + return user; + } } From 7ef3504617645a0a2ae1cc213bd0c2bae3a49e2d Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Fri, 8 Sep 2023 19:44:33 +0000 Subject: [PATCH 3/7] Add API to get for a user Fix issue from reviewer --- .../java/com/iemr/hwc/controller/wo/UserBiomectrics.java | 2 +- .../hwc/repo/login/{UserRepo.java => UserLoginRepo.java} | 5 ++--- .../com/iemr/hwc/repo/registrar/UserBiometricsRepo.java | 2 +- .../iemr/hwc/service/registrar/RegistrarServiceImpl.java | 8 +++----- 4 files changed, 7 insertions(+), 10 deletions(-) rename src/main/java/com/iemr/hwc/repo/login/{UserRepo.java => UserLoginRepo.java} (86%) diff --git a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java index eb78a6da..5bcac74e 100644 --- a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java @@ -52,7 +52,7 @@ else if(resp !=null && resp.equals("ko")){ @ApiOperation(value = "Get fingerprint by username", consumes = "application/json", produces = "application/json") @RequestMapping(value = "/get/fingerprint/{userID}/wo", method = RequestMethod.GET) - public String getVillageByDistrictID(@PathVariable("userID") Integer userID) { + public String getFingerprintsByUsername(@PathVariable("userID") Long userID) { logger.info("Get fingerprint by username ..." + userID); OutputResponse response = new OutputResponse(); UserBiometricsMapping user = registrarService.getFingerprintsByUserID(userID); diff --git a/src/main/java/com/iemr/hwc/repo/login/UserRepo.java b/src/main/java/com/iemr/hwc/repo/login/UserLoginRepo.java similarity index 86% rename from src/main/java/com/iemr/hwc/repo/login/UserRepo.java rename to src/main/java/com/iemr/hwc/repo/login/UserLoginRepo.java index 11160969..dac1d665 100644 --- a/src/main/java/com/iemr/hwc/repo/login/UserRepo.java +++ b/src/main/java/com/iemr/hwc/repo/login/UserLoginRepo.java @@ -22,7 +22,6 @@ package com.iemr.hwc.repo.login; import com.iemr.hwc.data.login.Users; -import com.iemr.hwc.data.videoconsultation.M_UserTemp; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; @@ -31,8 +30,8 @@ @Repository @RestResource(exported = false) -public interface UserRepo extends CrudRepository { - @Query(" SELECT u FROM M_UserTemp u WHERE u.UserName = :UserName AND u.Deleted = false ") +public interface UserLoginRepo extends CrudRepository { + @Query(" SELECT u FROM Users u WHERE u.userName = :UserName AND u.deleted = false ") public Users getUserByUsername(@Param("UserName") String username); } diff --git a/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java index b8269a59..84177314 100644 --- a/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java +++ b/src/main/java/com/iemr/hwc/repo/registrar/UserBiometricsRepo.java @@ -13,6 +13,6 @@ @RestResource(exported = false) public interface UserBiometricsRepo extends CrudRepository { @Query(" SELECT u FROM UserBiometricsMapping u WHERE u.userID = :userID AND u.deleted = false ") - public UserBiometricsMapping getFingerprintsByUserID(@Param("userID") Integer userID); + public UserBiometricsMapping getFingerprintsByUserID(@Param("userID") Long userID); } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java index a3b16649..90494e1b 100644 --- a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java @@ -28,11 +28,9 @@ import javax.ws.rs.core.MediaType; -import com.iemr.hwc.data.location.DistrictBranchMapping; import com.iemr.hwc.data.login.Users; import com.iemr.hwc.data.registrar.*; -import com.iemr.hwc.data.videoconsultation.M_UserTemp; -import com.iemr.hwc.repo.login.UserRepo; +import com.iemr.hwc.repo.login.UserLoginRepo; import com.iemr.hwc.repo.registrar.*; import org.json.JSONObject; import org.slf4j.Logger; @@ -95,7 +93,7 @@ public class RegistrarServiceImpl implements RegistrarService { private CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl; @Autowired - private UserRepo userRepo; + private UserLoginRepo userRepo; @Autowired private UserBiometricsRepo userBiometricsRepo; @@ -874,7 +872,7 @@ public String saveFingerprints(FingerPrintDTO comingRequest) { return response; } - public UserBiometricsMapping getFingerprintsByUserID(Integer userID) { + public UserBiometricsMapping getFingerprintsByUserID(Long userID) { UserBiometricsMapping user = userBiometricsRepo.getFingerprintsByUserID(userID); return user; } From cc6a2985dbbea97af9a373e166b3aea9fe114535 Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Fri, 8 Sep 2023 19:49:19 +0000 Subject: [PATCH 4/7] Fix issue from reviewer --- src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java index 5bcac74e..9bf904ef 100644 --- a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java @@ -74,7 +74,7 @@ public String getFingerprintsByUsername(@PathVariable("userID") Long userID) { else{ response.setError(404, "User with userID: "+userID+" not found"); } - logger.info("village master" + response.toString()); + logger.info("Get fingerprint " + response.toString()); return response.toString(); } } \ No newline at end of file From 1a75ec287effa64d34ae80fdec3b182b3041d4fc Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Tue, 12 Sep 2023 01:59:39 +0000 Subject: [PATCH 5/7] Add active flag to biometrics Make the biometric APIs(Add and Get) with auth --- .../UserBiomectrics.java | 17 ++++---- .../data/registrar/UserBiometricsMapping.java | 4 ++ .../registrar/RegistrarServiceImpl.java | 41 +++++++++++-------- 3 files changed, 35 insertions(+), 27 deletions(-) rename src/main/java/com/iemr/hwc/controller/{wo => userBiomectrics}/UserBiomectrics.java (85%) diff --git a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java similarity index 85% rename from src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java rename to src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java index 9bf904ef..0f06bd34 100644 --- a/src/main/java/com/iemr/hwc/controller/wo/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java @@ -1,33 +1,28 @@ -package com.iemr.hwc.controller.wo; +package com.iemr.hwc.controller.userBiomectrics; import com.google.gson.Gson; import com.iemr.hwc.controller.common.master.CommonMasterController; import com.iemr.hwc.data.registrar.FingerPrintDTO; import com.iemr.hwc.data.registrar.UserBiometricsMapping; -import com.iemr.hwc.service.location.LocationServiceImpl; import com.iemr.hwc.service.registrar.RegistrarServiceImpl; import com.iemr.hwc.utils.response.OutputResponse; import io.swagger.annotations.ApiOperation; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.List; - @CrossOrigin @RestController -@RequestMapping(value = "wo/user_biometrics") +@RequestMapping(value = "wo/user_biometrics", headers = "Authorization") public class UserBiomectrics { - // private OutputResponse response; private Logger logger = LoggerFactory.getLogger(CommonMasterController.class); @Autowired private RegistrarServiceImpl registrarService; @CrossOrigin() @ApiOperation(value = "add fingerprint for a given username", consumes = "application/json", produces = "application/json") - @RequestMapping(value = "add/fingerprint/wo", method = { RequestMethod.POST }, produces = { + @RequestMapping(value = "add/fingerprint", method = { RequestMethod.POST }, produces = { "application/json" }) public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { OutputResponse response = new OutputResponse(); @@ -40,6 +35,9 @@ public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { else if(resp !=null && resp.equals("ko")){ response.setError(500, "Error adding fingerprints"); } + else if(resp !=null && resp.equals("fingerprint_already_added")){ + response.setError(210, "Fingerprints already added"); + } } else { response.setError(400, "Invalid request"); } @@ -51,7 +49,7 @@ else if(resp !=null && resp.equals("ko")){ } @ApiOperation(value = "Get fingerprint by username", consumes = "application/json", produces = "application/json") - @RequestMapping(value = "/get/fingerprint/{userID}/wo", method = RequestMethod.GET) + @RequestMapping(value = "/get/fingerprint/{userID}", method = RequestMethod.GET) public String getFingerprintsByUsername(@PathVariable("userID") Long userID) { logger.info("Get fingerprint by username ..." + userID); OutputResponse response = new OutputResponse(); @@ -68,6 +66,7 @@ public String getFingerprintsByUsername(@PathVariable("userID") Long userID) { userBiometricsMapping.setRightIndexFinger(user.getRightIndexFinger()); userBiometricsMapping.setLeftThumb(user.getLeftThumb()); userBiometricsMapping.setLeftIndexFinger(user.getLeftIndexFinger()); + userBiometricsMapping.setActive(user.getActive()); response.setResponse(gson.toJson(userBiometricsMapping)); } diff --git a/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java b/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java index 41a972a9..eb553667 100644 --- a/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java +++ b/src/main/java/com/iemr/hwc/data/registrar/UserBiometricsMapping.java @@ -111,4 +111,8 @@ public class UserBiometricsMapping { @Column(name = "left_index_finger") private String leftIndexFinger; + @Column(name = "active") + @Expose + private Boolean active; + } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java index 0d3a0671..7b8a72f6 100644 --- a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java @@ -845,24 +845,29 @@ public int searchAndSubmitBeneficiaryToNurse(String requestOBJ) throws Exception public String saveFingerprints(FingerPrintDTO comingRequest) { String response = ""; Users user = userRepo.getUserByUsername(comingRequest.getUserName()); - if(user !=null){ - UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping(); - userBiometricsMapping.setUserID(user.getUserID()); - userBiometricsMapping.setFirstName(user.getFirstName()); - userBiometricsMapping.setLastName(user.getLastName()); - userBiometricsMapping.setUserName(user.getUserName()); - userBiometricsMapping.setCreatedBy(user.getUserName()); - userBiometricsMapping.setRightThumb(comingRequest.getRightThumb()); - userBiometricsMapping.setRightIndexFinger(comingRequest.getRightIndexFinger()); - userBiometricsMapping.setLeftThumb(comingRequest.getLeftThumb()); - userBiometricsMapping.setLeftIndexFinger(comingRequest.getLeftIndexFinger()); - - UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping); - if(resp !=null){ - response = "ok"; - } - else{ - response = "ko"; + if(user !=null) { + UserBiometricsMapping userBiomectric = userBiometricsRepo.getFingerprintsByUserID(user.getUserID()); + if (userBiomectric == null || (userBiomectric != null && userBiomectric.getActive() == false)) { // If the user don't have fingerprint yet, otherwise check if active equals false + UserBiometricsMapping userBiometricsMapping = new UserBiometricsMapping(); + userBiometricsMapping.setUserID(user.getUserID()); + userBiometricsMapping.setFirstName(user.getFirstName()); + userBiometricsMapping.setLastName(user.getLastName()); + userBiometricsMapping.setUserName(user.getUserName()); + userBiometricsMapping.setCreatedBy(user.getUserName()); + userBiometricsMapping.setRightThumb(comingRequest.getRightThumb()); + userBiometricsMapping.setRightIndexFinger(comingRequest.getRightIndexFinger()); + userBiometricsMapping.setLeftThumb(comingRequest.getLeftThumb()); + userBiometricsMapping.setLeftIndexFinger(comingRequest.getLeftIndexFinger()); + userBiometricsMapping.setActive(true); + + UserBiometricsMapping resp = userBiometricsRepo.save(userBiometricsMapping); + if (resp != null) { + response = "ok"; + } else { + response = "ko"; + } + } else { + response = "fingerprint_already_added"; } } else{ From bda90d8577cb74f01b4e4bcafa4106f560d189a9 Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Tue, 12 Sep 2023 10:21:54 +0000 Subject: [PATCH 6/7] Remove wo on controller path --- .../iemr/hwc/controller/userBiomectrics/UserBiomectrics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java index 0f06bd34..5582ed44 100644 --- a/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java @@ -14,7 +14,7 @@ @CrossOrigin @RestController -@RequestMapping(value = "wo/user_biometrics", headers = "Authorization") +@RequestMapping(value = "/user_biometrics", headers = "Authorization") public class UserBiomectrics { private Logger logger = LoggerFactory.getLogger(CommonMasterController.class); From b4e5ce5b8c9ad57753d56521b709dbb7903ae5ab Mon Sep 17 00:00:00 2001 From: Babacar Ndiaye Date: Fri, 15 Sep 2023 11:00:21 +0000 Subject: [PATCH 7/7] Update saveFingerprints response --- .../iemr/hwc/controller/userBiomectrics/UserBiomectrics.java | 2 +- .../com/iemr/hwc/service/registrar/RegistrarServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java index 5582ed44..f42979e3 100644 --- a/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java +++ b/src/main/java/com/iemr/hwc/controller/userBiomectrics/UserBiomectrics.java @@ -32,7 +32,7 @@ public String addFingerPrints(@RequestBody FingerPrintDTO comingRequest) { if(resp !=null && resp.equals("ok")){ response.setResponse(resp); } - else if(resp !=null && resp.equals("ko")){ + else if(resp !=null && resp.equals("not_ok")){ response.setError(500, "Error adding fingerprints"); } else if(resp !=null && resp.equals("fingerprint_already_added")){ diff --git a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java index 7b8a72f6..65f263a9 100644 --- a/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/registrar/RegistrarServiceImpl.java @@ -864,7 +864,7 @@ public String saveFingerprints(FingerPrintDTO comingRequest) { if (resp != null) { response = "ok"; } else { - response = "ko"; + response = "not_ok"; } } else { response = "fingerprint_already_added";