Skip to content

Commit

Permalink
[CNFT1-3431] Simplifies how routing to the modernized patient profile…
Browse files Browse the repository at this point in the history
… is handled (#2007) (#2019)

* simplifies the redirection to the modernized patient profile

* fix cookie test

* handling drr

* wip

* consolidation

* smells

(cherry picked from commit 945deb7)
  • Loading branch information
adamloup-enquizit authored Nov 13, 2024
1 parent 67fd564 commit 074bce6
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ ResponseEntity<Void> fromPatientParameters(final HttpServletRequest request) {
return redirected(requested.from(request));
}

/**
* Resolves a redirect to the Modernized Patient Profile using the identifier given.
*
* @param identifier The unique identifier of a patient
* @return A {@link ResponseEntity} that redirects to the Modernized Patient Profile
*/
ResponseEntity<Void> forPatient(final long identifier) {
return redirected(requested.from(identifier));
}

private ResponseEntity<Void> redirected(final Optional<IncomingPatient> incoming) {
return incoming.map(ModernizedPatientProfileRedirect::forPatient)
.orElse(ModernizedPatientProfileRedirect.fallback())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Hidden
Expand All @@ -25,30 +25,37 @@ class PatientProfileIncomingRedirection {
* @param request The {@link HttpServletRequest} from Classic NBS
* @return A {@link ResponseEntity} redirecting to the Modernized Patient Profile
*/
@PostMapping("/nbs/redirect/patientProfile")
ResponseEntity<Void> redirectedPatientProfilePost(final HttpServletRequest request) {
@GetMapping("/nbs/redirect/patient/profile")
ResponseEntity<Void> redirectedPatientProfileGET(final HttpServletRequest request) {
return resolver.fromPatientParameters(request);
}

/**
* Receives proxied View Patient Profile requests from Classic NBS.
* Receives proxied View Patient Profile requests from Classic NBS. GET requests from Patient Profile typically
* include the patient identifier in tas a query parameter.
*
* @param patient The unique identifier of a patient
* @param request The {@link HttpServletRequest} from Classic NBS
* @return A {@link ResponseEntity} redirecting to the Modernized Patient Profile
*/
@GetMapping("/nbs/redirect/patient/profile")
ResponseEntity<Void> redirected(@RequestParam(name = "uid") final long patient) {
return resolver.forPatient(patient);
@PostMapping("/nbs/redirect/patient/profile")
ResponseEntity<Void> redirectedPatientProfilePOST(final HttpServletRequest request) {
return resolver.fromPatientParameters(request);
}

/**
* Receives proxied View Patient Profile requests from Classic NBS.
*
* @param request The {@link HttpServletRequest} from Classic NBS
* @return A {@link ResponseEntity} redirecting to the Modernized Patient Profile
*/
@GetMapping("/nbs/redirect/patientProfile")
ResponseEntity<Void> redirectedPatientProfileGet(final HttpServletRequest request) {
return resolver.fromReturnPatient(request);
@GetMapping("/nbs/redirect/patientProfile/{tab}/return")
ResponseEntity<Void> redirectPatientProfileReturnGET(
final HttpServletRequest request,
@PathVariable(required = false) final String tab
) {
return resolver.fromReturnPatient(request, tab);
}

@PostMapping("/nbs/redirect/patientProfile/{tab}/return")
ResponseEntity<Void> redirectPatientProfileReturnPOST(
final HttpServletRequest request,
@PathVariable(required = false) final String tab
) {
return resolver.fromReturnPatient(request, tab);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PatientProfileFromActionRequester {
ResultActions returning(final InvestigationIdentifier investigation) {
try {
return mvc.perform(
authenticated.withSession(get("/nbs/redirect/patientProfile/return"))
authenticated.withSession(get("/nbs/redirect/patientProfile/summary/return"))
.cookie(new Cookie("Patient-Action", String.valueOf(investigation.identifier())))
);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void redirecting_a_classic_master_patient_record_profile() throws Excepti
response.active(
mvc
.perform(
authenticated.withSession(post("/nbs/redirect/patientProfile"))
authenticated.withSession(post("/nbs/redirect/patient/profile"))
.param("MPRUid", String.valueOf(patient.id()))
)
);
Expand All @@ -55,7 +55,7 @@ public void redirecting_a_classic_revision_patient_profile() throws Exception {
response.active(
mvc
.perform(
authenticated.withSession(post("/nbs/redirect/patientProfile"))
authenticated.withSession(post("/nbs/redirect/patient/profile"))
.param("uid", String.valueOf(patient.id()))
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gov.cdc.nbs.patient.identifier.PatientIdentifier;
import gov.cdc.nbs.testing.interaction.http.Authenticated;
import jakarta.servlet.http.Cookie;
import org.springframework.stereotype.Component;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
Expand Down Expand Up @@ -35,4 +36,12 @@ ResultActions profile(final PatientIdentifier patient) {
}
}

ResultActions returningTo(final PatientIdentifier patient, final String tab) {
try {
return mvc.perform(authenticated.withSession(get("/nbs/redirect/patientProfile/{tab}/return", tab))
.cookie(new Cookie("Return-Patient", String.valueOf(patient.id()))));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,40 @@
package gov.cdc.nbs.patient.profile.redirect.incoming;

import gov.cdc.nbs.patient.identifier.PatientIdentifier;
import gov.cdc.nbs.testing.interaction.http.Authenticated;
import gov.cdc.nbs.testing.support.Active;
import io.cucumber.java.en.When;
import jakarta.servlet.http.Cookie;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

public class PatientProfileReturningRedirectionSteps {

private final Authenticated authenticated;

private final Active<PatientIdentifier> activePatient;

private final MockMvc mvc;
private final PatientProfileRedirectRequester requester;

private final Active<ResultActions> activeResponse;

PatientProfileReturningRedirectionSteps(
final Authenticated authenticated,
final Active<PatientIdentifier> activePatient,
final MockMvc mvc,
final PatientProfileRedirectRequester requester,
final Active<ResultActions> activeResponse
) {
this.authenticated = authenticated;
this.activePatient = activePatient;
this.mvc = mvc;
this.requester = requester;
this.activeResponse = activeResponse;
}

@When("Returning to a Patient Profile")
public void returning_to_a_patient_profile() throws Exception {

long patient = activePatient.active().id();

activeResponse.active(
mvc.perform(
this.authenticated.withSession(get("/nbs/redirect/patientProfile/return"))
.cookie(new Cookie("Return-Patient", String.valueOf(patient))))
);
public void returning_to_a_patient_profile() {
activePatient.maybeActive()
.map(patient -> requester.returningTo(patient, "summary"))
.ifPresent(activeResponse::active);
}

@When("Returning to a Patient Profile {patientProfileTab} tab")
public void returning_to_a_patient_profile_tab(final String tab) throws Exception {

long patient = activePatient.active().id();

activeResponse.active(
mvc.perform(authenticated.withSession(get("/nbs/redirect/patientProfile/{tab}/return", tab))
.cookie(new Cookie("Return-Patient", String.valueOf(patient))))
);
public void returning_to_a_patient_profile_tab(final String tab) {
activePatient.maybeActive()
.map(patient -> requester.returningTo(patient, tab))
.ifPresent(activeResponse::active);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@patient-profile-returning-redirect @web-interaction
@patient-profile-returning-redirect
Feature: NBS Classic Patient Profile returns to modernized Patient Profile

Background:
Expand Down Expand Up @@ -28,4 +28,3 @@ Feature: NBS Classic Patient Profile returns to modernized Patient Profile
Scenario: A user in NBS6 is viewing a patient from the results of an Event search
When navigating to a Patient Profile from event search results
Then I am redirected to the Modernized Patient Profile

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* <li>Query Parameter {@code ContextAction} of {@code ViewFile}</li>
* <li>Query Parameter {@code ContextAction} of {@code FileSummary}</li>
* </ul>
*
* If the request contains a query parameter of either {@code uid} or {@code MPRUid} the request is routed to an endpoint
* of the patient profile service that can resolve the modernized patient profile using the value of the query parameter.
* Otherwise, the request is routed to an endpoint that can resolve the modernized patient profile using contextual
* request data present in cookies.
*/
@Configuration
@ConditionalOnProperty(prefix = "nbs.gateway.patient.profile", name = "enabled", havingValue = "true")
Expand All @@ -29,19 +34,32 @@ class PatientProfileRouteLocatorConfiguration {
RouteLocator patientProfileLocator(
final RouteLocatorBuilder builder,
@Qualifier("defaults") final List<GatewayFilter> defaults,
final PatientProfileService parameters
final PatientProfileService service
) {
return builder.routes()
.route(
"patient-profile",
"patient-profile-direct",
route -> route
.order(RouteOrdering.PATIENT_PROFILE.order())
.query("ContextAction", "ViewFile|FileSummary")
.and()
.query("uid").or().query("MPRUid")
.filters(
filter -> filter.setPath(service.direct())
.filters(defaults)
)
.uri(service.uri())
)
.route(
"patient-profile-resolving",
route -> route
.order(RouteOrdering.PATIENT_PROFILE.order())
.query("ContextAction", "ViewFile|FileSummary")
.filters(
filter -> filter.setPath("/nbs/redirect/patientProfile")
filter -> filter.setPath(service.summary())
.filters(defaults)
)
.uri(parameters.uri())
.uri(service.uri())
)
.build();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public PatientProfileService(final URI uri) {
super(uri);
}

public String direct() {return "/nbs/redirect/patient/profile";}

public String events() {
return "/nbs/redirect/patientProfile/events/return";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ViewInvestigationRouteLocatorConfiguration {
"Patient-Action"
);
private static final RemoveCookieGatewayFilterFactory.Config REMOVE_RETURN_PATIENT_CONFIG =
new RemoveCookieGatewayFilterFactory.Config("/nbs/", "Return-Patient");
new RemoveCookieGatewayFilterFactory.Config("/nbs", "Return-Patient");

@Bean
RouteLocator viewInvestigationActionCookie(
Expand All @@ -52,7 +52,7 @@ RouteLocator viewInvestigationActionCookie(
.routes()
.route(
"view-open-investigations-apply-patient-action-cookie",
route -> route.path("/nbs/MyProgramAreaInvestigations1.do")
route -> route.path("/nbs/MyProgramAreaInvestigations1.do", "/nbs/PatientSearchResults1.do")
.and()
.query(IDENTIFIER_PARAMETER)
.filters(
Expand Down
Loading

0 comments on commit 074bce6

Please sign in to comment.