11import com .auth0 .jwt .JWT ;
22import com .auth0 .jwt .algorithms .Algorithm ;
3+ import com .fasterxml .jackson .core .type .TypeReference ;
34import com .fasterxml .jackson .databind .ObjectMapper ;
45import com .google .common .base .Charsets ;
56import org .apache .hc .client5 .http .utils .Base64 ;
67import org .json .JSONObject ;
78
89import java .io .IOException ;
910import java .net .HttpURLConnection ;
10- import java .net .URL ;
11+ import java .net .URI ;
12+ import java .net .URISyntaxException ;
1113import java .security .KeyFactory ;
1214import java .security .interfaces .RSAPrivateKey ;
1315import java .security .spec .PKCS8EncodedKeySpec ;
1416import java .time .Instant ;
1517import java .time .temporal .ChronoUnit ;
16- import java .util .HashMap ;
1718import java .util .Map ;
1819import java .util .UUID ;
1920
@@ -37,7 +38,7 @@ public Map<String, Object> patient(String nhsNumber) throws Exception {
3738
3839 String patientData = getPatientData (nhsNumber , accessToken );
3940
40- return new ObjectMapper ().readValue (patientData , HashMap . class );
41+ return new ObjectMapper ().readValue (patientData , new TypeReference <>() {} );
4142 }
4243
4344 private String generateJwtToken () throws Exception {
@@ -52,16 +53,17 @@ private String generateJwtToken() throws Exception {
5253 .sign (algorithm );
5354 }
5455
55- private static String getPatientData (String nhsNumber , String accessToken ) throws IOException {
56- var connection = (HttpURLConnection ) (new URL ("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber )).openConnection ();
56+ private static String getPatientData (String nhsNumber , String accessToken ) throws IOException , URISyntaxException {
57+ var connection = (HttpURLConnection ) new URI ("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber )
58+ .toURL ().openConnection ();
5759 connection .setRequestMethod ("GET" );
5860 connection .setRequestProperty ("X-Request-Id" , UUID .randomUUID ().toString ());
5961 connection .setRequestProperty ("Authorization" , "Bearer " + accessToken );
6062 return new String (connection .getInputStream ().readAllBytes (), Charsets .UTF_8 );
6163 }
6264
63- private static String getOauthToken (String token ) throws IOException {
64- var connection = (HttpURLConnection ) new URL (OAUTH_ENDPOINT ).openConnection ();
65+ private static String getOauthToken (String token ) throws IOException , URISyntaxException {
66+ var connection = (HttpURLConnection ) new URI (OAUTH_ENDPOINT ). toURL ( ).openConnection ();
6567 connection .setRequestMethod ("POST" );
6668 connection .setDoOutput (true );
6769 connection .setRequestProperty ("content-type" , "application/x-www-form-urlencoded" );
0 commit comments