Skip to content

Commit 7ac82ab

Browse files
Merge pull request #330 from minvws/fixes-v0.1
Fixes for NVI and PRS v0.1
2 parents 72597cc + 5815709 commit 7ac82ab

5 files changed

Lines changed: 27 additions & 38 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ HMAC_KEY=
2323
GF_OAUTH_URL=
2424
GF_PRS_URL=
2525
GF_NVI_URL=
26+
GF_NVI_CUSTODIAN_IDENTIFIER_VALUE=
2627

2728
GF_CLIENT_CERT=
2829
GF_CLIENT_KEY=

app/Http/Controllers/IndexController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
class IndexController extends Controller
2121
{
22+
public const REGISTERED_TEST_BSN = '999990007';
23+
2224
public function index(DemoService $demoService): View
2325
{
24-
$demoService->createNVIDataReference('999990007');
26+
$demoService->createNVIDataReference(self::REGISTERED_TEST_BSN);
2527

2628
return view('index', [
2729
'datadomains' => DATA_DOMAINS,

app/Services/DemoService.php

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
namespace App\Services;
66

77
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\GuzzleException;
89

910
class DemoService
1011
{
1112
/**
1213
* The paths to the mTLS certificate and key. These are used to authenticate with the PRS and NVI.
13-
* @var string
1414
*/
1515
protected string $mtls_cert;
16+
1617
/***
1718
* The paths to the mTLS certificate and key. These are used to authenticate with the PRS and NVI.
18-
* @var string
1919
*/
2020
protected string $mtls_key;
2121

2222
/**
2323
* The verify option for Guzzle. This can be set to false to disable SSL verification, or it can
2424
* be set to a path to a CA bundle.
25-
*
26-
* @var string|bool
2725
*/
2826
protected string|bool $verify;
2927

@@ -36,9 +34,8 @@ public function __construct(string $mtls_cert, string $mtls_key, string|bool $ve
3634

3735
/**
3836
* Retrieves an OAuth token for the given URL (audience)
39-
* @param string $url
40-
* @return string
41-
* @throws \GuzzleHttp\Exception\GuzzleException
37+
*
38+
* @throws GuzzleException
4239
*/
4340
public function getOauthToken(string $url): string
4441
{
@@ -49,26 +46,24 @@ public function getOauthToken(string $url): string
4946
'verify' => $this->verify,
5047
]);
5148

52-
$response = $client->post('/oauth/token', [
49+
$response = $client->post('oauth/token', [
5350
'form_params' => [
54-
'target_audience' => $url,
51+
'target_audience' => rtrim($url, '/'),
5552
'grant_type' => 'client_credentials',
5653
'scope' => 'epd:read',
5754
],
5855
]);
5956

6057
$data = json_decode((string) $response->getBody(), true);
58+
6159
return $data['access_token'];
6260
}
6361

6462
/**
6563
* This creates a blinded input for a given hashed BSN. We do this by calling a test endpoint on the PRS, since PHP
6664
* does not have the necessary cryptographic libraries to do this locally.
6765
*
68-
* @param string $token
69-
* @param string $hashed_bsn
70-
* @return array
71-
* @throws \GuzzleHttp\Exception\GuzzleException
66+
* @throws GuzzleException
7267
*/
7368
public function createPrsInput(string $token, string $hashed_bsn): array
7469
{
@@ -79,7 +74,7 @@ public function createPrsInput(string $token, string $hashed_bsn): array
7974
'verify' => $this->verify,
8075
]);
8176

82-
$response = $client->post('/test/oprf/client', [
77+
$response = $client->post('test/oprf/client', [
8378
'headers' => [
8479
'Authorization' => "Bearer $token",
8580
],
@@ -88,16 +83,13 @@ public function createPrsInput(string $token, string $hashed_bsn): array
8883
],
8984
]);
9085

91-
return json_decode((string)$response->getBody(), true);
86+
return json_decode((string) $response->getBody(), true);
9287
}
9388

9489
/**
9590
* Evaluate the blinded input with the PRS and return the result.
9691
*
97-
* @param string $token
98-
* @param string $input
99-
* @return array
100-
* @throws \GuzzleHttp\Exception\GuzzleException
92+
* @throws GuzzleException
10193
*/
10294
public function prsEvaluate(string $token, string $input): array
10395
{
@@ -108,7 +100,7 @@ public function prsEvaluate(string $token, string $input): array
108100
'verify' => $this->verify,
109101
]);
110102

111-
$response = $client->post('/oprf/eval', [
103+
$response = $client->post('oprf/eval', [
112104
'headers' => [
113105
'Authorization' => "Bearer $token",
114106
],
@@ -119,17 +111,13 @@ public function prsEvaluate(string $token, string $input): array
119111
],
120112
]);
121113

122-
return json_decode((string)$response->getBody(), true);
114+
return json_decode((string) $response->getBody(), true);
123115
}
124116

125117
/**
126118
* Retrieves data from the NVI for a given token, eval_input and blind_factor.
127119
*
128-
* @param string $token
129-
* @param string $eval_input
130-
* @param string $blind_factor
131-
* @return array
132-
* @throws \GuzzleHttp\Exception\GuzzleException
120+
* @throws GuzzleException
133121
*/
134122
public function retrieveFromNVI(string $token, string $eval_input, string $blind_factor): array
135123
{
@@ -140,7 +128,7 @@ public function retrieveFromNVI(string $token, string $eval_input, string $blind
140128
'verify' => $this->verify,
141129
]);
142130

143-
$response = $client->post('/Organization/$localize', [
131+
$response = $client->post('Organization/$localize', [
144132
'headers' => [
145133
'Authorization' => "Bearer $token",
146134
],
@@ -162,21 +150,18 @@ public function retrieveFromNVI(string $token, string $eval_input, string $blind
162150
'code' => 'LaboratoryTestResult',
163151
],
164152
],
165-
]
153+
],
166154
],
167155
]);
168156

169-
return json_decode((string)$response->getBody(), true);
157+
return json_decode((string) $response->getBody(), true);
170158
}
171159

172-
173160
/**
174161
* Creates a NVIDataReference for the given BSN. This is used to demonstrate the full flow of creating a reference
175162
* in the NVI and then retrieving it.
176163
*
177-
* @param string $bsn
178-
* @return void
179-
* @throws \GuzzleHttp\Exception\GuzzleException
164+
* @throws GuzzleException
180165
*/
181166
public function createNVIDataReference(string $bsn): void
182167
{
@@ -197,15 +182,15 @@ public function createNVIDataReference(string $bsn): void
197182
'verify' => $this->verify,
198183
]);
199184

200-
$client->post('/NVIDataReference', [
185+
$client->post('NVIDataReference', [
201186
'headers' => [
202187
'Authorization' => "Bearer $token",
203188
],
204189
'json' => [
205190
'resourceType' => 'NVIDataReference',
206191
'source' => [
207-
'system' => "urn:oid:2.16.528.1.1007.3.3",
208-
'value' => "90000206"
192+
'system' => 'urn:oid:2.16.528.1.1007.3.3',
193+
'value' => config('gfmodules.nvi.custodian_identifier_value'),
209194
],
210195
'sourceType' => [
211196
'coding' => [

config/gfmodules.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
'nvi' => [
1616
'url' => env('GF_NVI_URL'),
17+
'custodian_identifier_value' => env('GF_NVI_CUSTODIAN_IDENTIFIER_VALUE', '90000206'),
1718
],
1819
'client_cert' => env('GF_CLIENT_CERT'),
1920
'client_key' => env('GF_CLIENT_KEY'),

resources/views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@csrf
2828
<div class="form-group">
2929
<label class="required">Vindt patient</label>
30-
<input name="bsn" type="text" maxlength="9" placeholder="BSN nummer">
30+
<input name="bsn" type="text" maxlength="9" placeholder="BSN nummer" value="{{ \App\Http\Controllers\IndexController::REGISTERED_TEST_BSN }}">
3131
</div>
3232

3333
<div class="form-group">

0 commit comments

Comments
 (0)