3535import org .springframework .web .bind .annotation .RequestBody ;
3636import org .springframework .web .bind .annotation .RequestHeader ;
3737import org .springframework .web .bind .annotation .RequestMapping ;
38- import org .springframework .web .bind .annotation .RequestMethod ;
3938import org .springframework .web .bind .annotation .RestController ;
4039
4140import com .iemr .tm .data .benFlowStatus .BeneficiaryFlowStatus ;
4241import com .iemr .tm .service .common .transaction .CommonDoctorServiceImpl ;
4342import com .iemr .tm .service .common .transaction .CommonNurseServiceImpl ;
4443import com .iemr .tm .service .common .transaction .CommonServiceImpl ;
45- import com .iemr .tm .utils .CookieUtil ;
4644import com .iemr .tm .utils .JwtUtil ;
4745import com .iemr .tm .utils .mapper .InputMapper ;
4846import com .iemr .tm .utils .response .OutputResponse ;
47+ import org .springframework .security .core .Authentication ;
4948
5049import io .lettuce .core .dynamic .annotation .Param ;
5150import io .swagger .v3 .oas .annotations .Operation ;
52- import jakarta .servlet .http .HttpServletRequest ;
5351
5452@ RestController
5553@ RequestMapping (value = "/common" , headers = "Authorization" , consumes = "application/json" , produces = "application/json" )
@@ -711,18 +709,22 @@ public String getBeneficiaryCaseSheetHistory(
711709 @ Operation (summary = "Get teleconsultation specialist worklist" )
712710 @ GetMapping (value = { "/getTCSpecialistWorklist/{providerServiceMapID}/{serviceID}" })
713711 public String getTCSpecialistWorkListNew (@ PathVariable ("providerServiceMapID" ) Integer providerServiceMapID ,
714- @ PathVariable ("serviceID" ) Integer serviceID , HttpServletRequest request ) {
712+ @ PathVariable ("serviceID" ) Integer serviceID , Authentication authentication ) {
715713 OutputResponse response = new OutputResponse ();
716- try {
717- String jwtToken = CookieUtil .getJwtTokenFromCookie (request );
718- String userId = jwtUtil .getUserIdFromToken (jwtToken );
719- Integer userID =Integer .parseInt (userId );
720- if (providerServiceMapID != null && userId != null ) {
714+ try {
715+ if (authentication == null || !authentication .isAuthenticated ()) {
716+ response .setError (403 , "Unauthorized access" );
717+ return response .toString ();
718+ }
719+
720+ Integer userID = Integer .valueOf (authentication .getPrincipal ().toString ());
721+
722+ if (providerServiceMapID != null && userID != null ) {
721723 String s = commonDoctorServiceImpl .getTCSpecialistWorkListNewForTM (providerServiceMapID , userID ,
722724 serviceID );
723725 if (s != null )
724726 response .setResponse (s );
725- } else if (userId == null || jwtToken == null ) {
727+ } else if (userID == null ) {
726728 response .setError (403 , "Unauthorized access!" );
727729 } else {
728730 logger .error ("Invalid request" );
@@ -742,20 +744,21 @@ public String getTCSpecialistWorkListNew(@PathVariable("providerServiceMapID") I
742744 "/getTCSpecialistWorklistPatientApp/{providerServiceMapID}/{serviceID}/{vanID}" })
743745 public String getTCSpecialistWorkListNewPatientApp (
744746 @ PathVariable ("providerServiceMapID" ) Integer providerServiceMapID ,
745- @ PathVariable ("serviceID" ) Integer serviceID , @ PathVariable ("vanID" ) Integer vanID , HttpServletRequest request ) {
747+ @ PathVariable ("serviceID" ) Integer serviceID , @ PathVariable ("vanID" ) Integer vanID , Authentication authentication ) {
746748 OutputResponse response = new OutputResponse ();
747749 try {
748- String jwtToken = CookieUtil .getJwtTokenFromCookie (request );
749- String userId = jwtUtil .getUserIdFromToken (jwtToken );
750- Integer userID =Integer .parseInt (userId );
750+ if (authentication == null || !authentication .isAuthenticated ()) {
751+ response .setError (403 , "Unauthorized access" );
752+ return response .toString ();
753+ }
754+
755+ Integer userID = Integer .valueOf (authentication .getPrincipal ().toString ());
751756 if (providerServiceMapID != null && userID != null ) {
752757 String s = commonDoctorServiceImpl .getTCSpecialistWorkListNewForTMPatientApp (providerServiceMapID ,
753758 userID , serviceID , vanID );
754759 if (s != null )
755760 response .setResponse (s );
756- } else if (userId == null || jwtToken == null ) {
757- response .setError (403 , "Unauthorized access!" );
758- } else {
761+ } else {
759762 logger .error ("Invalid request" );
760763 response .setError (5000 , "Invalid request" );
761764 }
@@ -773,21 +776,22 @@ public String getTCSpecialistWorkListNewPatientApp(
773776 "/getTCSpecialistWorklistFutureScheduled/{providerServiceMapID}/{serviceID}" })
774777 public String getTCSpecialistWorklistFutureScheduled (
775778 @ PathVariable ("providerServiceMapID" ) Integer providerServiceMapID ,
776- @ PathVariable ("serviceID" ) Integer serviceID , HttpServletRequest request ) {
779+ @ PathVariable ("serviceID" ) Integer serviceID , Authentication authentication ) {
777780 OutputResponse response = new OutputResponse ();
778781 try {
779782
780- String jwtToken = CookieUtil .getJwtTokenFromCookie (request );
781- String userId = jwtUtil .getUserIdFromToken (jwtToken );
782- Integer userID =Integer .parseInt (userId );
783+ if (authentication == null || !authentication .isAuthenticated ()) {
784+ response .setError (403 , "Unauthorized access" );
785+ return response .toString ();
786+ }
787+
788+ Integer userID = Integer .valueOf (authentication .getPrincipal ().toString ());
783789 if (providerServiceMapID != null && userID != null ) {
784790 String s = commonDoctorServiceImpl .getTCSpecialistWorkListNewFutureScheduledForTM (providerServiceMapID ,
785791 userID , serviceID );
786792 if (s != null )
787793 response .setResponse (s );
788- } else if (userId == null || jwtToken == null ) {
789- response .setError (403 , "Unauthorized access!" );
790- } else {
794+ } else {
791795 logger .error ("Invalid request" );
792796 response .setError (5000 , "Invalid request" );
793797 }
0 commit comments