@@ -4,6 +4,7 @@ import { check } from "k6";
44import { randomItem } from "https://jslib.k6.io/k6-utils/1.2.0/index.js" ;
55import { crypto } from "k6/experimental/webcrypto" ;
66import { createRecord } from "../setup.js" ;
7+ import { getHeaders , getFullUrl } from "../test-config.js" ;
78import exec from "k6/execution" ;
89
910const distPath = __ENV . DIST_PATH || "./dist" ;
@@ -38,7 +39,7 @@ function getNextPointer() {
3839 const iter = exec . vu . iterationInScenario ;
3940 const index = iter % dataLines . length ;
4041 const line = dataLines [ index ] ;
41- // Adjust field names as per CSV columns: count,pointer_id,pointer_type,custodian,nhs_number
42+
4243 const [ pointer_id , pointer_type , custodian , nhs_number ] = line
4344 . split ( "," )
4445 . map ( ( field ) => field . trim ( ) ) ;
@@ -115,25 +116,6 @@ pickCustodian = function (typeCode) {
115116 return randomItem ( arr ) ;
116117} ;
117118
118- function getBaseURL ( ) {
119- return `https://${ __ENV . HOST } /producer/DocumentReference` ;
120- }
121-
122- function getHeaders ( odsCode = ODS_CODE ) {
123- return {
124- "Content-Type" : "application/fhir+json" ,
125- "X-Request-Id" : `K6perftest-producer-${ exec . scenario . name } -${ exec . vu . idInTest } -${ exec . vu . iterationInScenario } ` ,
126- "NHSD-Correlation-Id" : `K6perftest-producer-${ exec . scenario . name } -${ exec . vu . idInTest } -${ exec . vu . iterationInScenario } ` ,
127- "NHSD-Connection-Metadata" : JSON . stringify ( {
128- "nrl.ods-code" : odsCode ,
129- "nrl.app-id" : "K6PerformanceTest" ,
130- } ) ,
131- "NHSD-Client-RP-Details" : JSON . stringify ( {
132- "developer.app.name" : "K6PerformanceTest" ,
133- "developer.app.id" : "K6PerformanceTest" ,
134- } ) ,
135- } ;
136- }
137119function checkResponse ( res ) {
138120 const is_success = check ( res , { "status is 200" : ( r ) => r . status === 200 } ) ;
139121 if ( ! is_success ) {
@@ -146,9 +128,12 @@ export function createDocumentReference() {
146128 const pointerType = pickPointerType ( ) ;
147129 const custodian = pickCustodian ( pointerType ) ;
148130 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
149- const res = http . post ( getBaseURL ( ) , JSON . stringify ( record ) , {
150- headers : getHeaders ( custodian ) ,
131+ const path = "/DocumentReference" ;
132+
133+ const res = http . post ( getFullUrl ( path , "producer" ) , JSON . stringify ( record ) , {
134+ headers : getHeaders ( custodian , "producer" ) ,
151135 } ) ;
136+
152137 check ( res , { "create status is 201" : ( r ) => r . status === 201 } ) ;
153138 if ( res . status !== 201 ) {
154139 console . warn (
@@ -161,9 +146,12 @@ export function createDocumentReference() {
161146
162147export function readDocumentReference ( ) {
163148 const { pointer_id, custodian } = getNextPointer ( ) ;
164- const res = http . get ( `${ getBaseURL ( ) } /${ pointer_id } ` , {
165- headers : getHeaders ( custodian ) ,
149+ const path = `/DocumentReference/${ pointer_id } ` ;
150+
151+ const res = http . get ( getFullUrl ( path , "producer" ) , {
152+ headers : getHeaders ( custodian , "producer" ) ,
166153 } ) ;
154+
167155 checkResponse ( res ) ;
168156}
169157
@@ -172,9 +160,14 @@ export function createThenReadDocumentReference() {
172160 const pointerType = pickPointerType ( ) ;
173161 const custodian = pickCustodian ( pointerType ) ;
174162 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
175- const createRes = http . post ( getBaseURL ( ) , JSON . stringify ( record ) , {
176- headers : getHeaders ( custodian ) ,
177- } ) ;
163+ const createPath = "/DocumentReference" ;
164+
165+ const createRes = http . post (
166+ getFullUrl ( createPath , "producer" ) ,
167+ JSON . stringify ( record ) ,
168+ { headers : getHeaders ( custodian , "producer" ) }
169+ ) ;
170+
178171 check ( createRes , { "create status is 201" : ( r ) => r . status === 201 } ) ;
179172 if ( createRes . status !== 201 ) {
180173 console . warn (
@@ -190,9 +183,10 @@ export function createThenReadDocumentReference() {
190183 const createdId = locationHeader
191184 ? locationHeader . split ( "/" ) . pop ( )
192185 : record . id ;
186+ const path = `/DocumentReference/${ createdId } ` ;
193187
194- const readRes = http . get ( ` ${ getBaseURL ( ) } / ${ createdId } ` , {
195- headers : getHeaders ( custodian ) ,
188+ const readRes = http . get ( getFullUrl ( path , "producer" ) , {
189+ headers : getHeaders ( custodian , "producer" ) ,
196190 } ) ;
197191
198192 check ( readRes , { "create and read status is 200" : ( r ) => r . status === 200 } ) ;
@@ -211,9 +205,14 @@ export function upsertThenReadDocumentReference() {
211205 const custodian = pickCustodian ( pointerType ) ;
212206 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
213207 record . id = `${ custodian } -${ crypto . randomUUID ( ) } ` ;
214- const upsertRes = http . put ( getBaseURL ( ) , JSON . stringify ( record ) , {
215- headers : getHeaders ( custodian ) ,
216- } ) ;
208+ const upsertPath = "/DocumentReference" ;
209+
210+ const upsertRes = http . put (
211+ getFullUrl ( upsertPath , "producer" ) ,
212+ JSON . stringify ( record ) ,
213+ { headers : getHeaders ( custodian , "producer" ) }
214+ ) ;
215+
217216 check ( upsertRes , { "upsert status is 201" : ( r ) => r . status === 201 } ) ;
218217 if ( upsertRes . status !== 201 ) {
219218 console . warn (
@@ -225,9 +224,10 @@ export function upsertThenReadDocumentReference() {
225224 }
226225
227226 const upsertedId = record . id ;
227+ const path = `/DocumentReference/${ upsertedId } ` ;
228228
229- const readRes = http . get ( ` ${ getBaseURL ( ) } / ${ upsertedId } ` , {
230- headers : getHeaders ( custodian ) ,
229+ const readRes = http . get ( getFullUrl ( path , "producer" ) , {
230+ headers : getHeaders ( custodian , "producer" ) ,
231231 } ) ;
232232
233233 check ( readRes , { "upsert and read status is 200" : ( r ) => r . status === 200 } ) ;
@@ -245,9 +245,14 @@ export function createThenUpdateDocumentReference() {
245245 const pointerType = pickPointerType ( ) ;
246246 const custodian = pickCustodian ( pointerType ) ;
247247 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
248- const createRes = http . post ( getBaseURL ( ) , JSON . stringify ( record ) , {
249- headers : getHeaders ( custodian ) ,
250- } ) ;
248+ const path = `/DocumentReference/${ upsertedId } ` ;
249+
250+ const createRes = http . post (
251+ getFullUrl ( path , "producer" ) ,
252+ JSON . stringify ( record ) ,
253+ { headers : getHeaders ( custodian , "producer" ) }
254+ ) ;
255+
251256 check ( createRes , {
252257 "createThenUpdateDocumentReference: create status is 201" : ( r ) =>
253258 r . status === 201 ,
@@ -271,13 +276,12 @@ export function createThenUpdateDocumentReference() {
271276
272277 // Now update the record
273278 record . content [ 0 ] . attachment . url = "https://example.com/k6-updated-url.pdf" ;
279+ const updatePath = `/DocumentReference/${ createdId } ` ;
274280
275281 const updateRes = http . put (
276- ` ${ getBaseURL ( ) } / ${ createdId } ` ,
282+ getFullUrl ( updatePath , "producer" ) ,
277283 JSON . stringify ( record ) ,
278- {
279- headers : getHeaders ( custodian ) ,
280- }
284+ { headers : getHeaders ( custodian , "producer" ) }
281285 ) ;
282286
283287 check ( updateRes , {
@@ -299,9 +303,14 @@ export function upsertThenUpdateDocumentReference() {
299303 const custodian = pickCustodian ( pointerType ) ;
300304 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
301305 record . id = `${ custodian } -${ crypto . randomUUID ( ) } ` ;
302- const upsertRes = http . put ( getBaseURL ( ) , JSON . stringify ( record ) , {
303- headers : getHeaders ( custodian ) ,
304- } ) ;
306+ const path = "/DocumentReference" ;
307+
308+ const upsertRes = http . put (
309+ getFullUrl ( path , "producer" ) ,
310+ JSON . stringify ( record ) ,
311+ { headers : getHeaders ( custodian , "producer" ) }
312+ ) ;
313+
305314 check ( upsertRes , { "upsert status is 201" : ( r ) => r . status === 201 } ) ;
306315 if ( upsertRes . status !== 201 ) {
307316 console . warn (
@@ -317,12 +326,12 @@ export function upsertThenUpdateDocumentReference() {
317326 // Now update the record
318327 record . content [ 0 ] . attachment . url = "https://example.com/k6-updated-url.pdf" ;
319328
329+ const updatePath = `/DocumentReference/${ upsertedId } ` ;
330+
320331 const updateRes = http . put (
321- ` ${ getBaseURL ( ) } / ${ upsertedId } ` ,
332+ getFullUrl ( updatePath , "producer" ) ,
322333 JSON . stringify ( record ) ,
323- {
324- headers : getHeaders ( custodian ) ,
325- }
334+ { headers : getHeaders ( custodian , "producer" ) }
326335 ) ;
327336
328337 check ( updateRes , {
@@ -344,9 +353,12 @@ export function upsertDocumentReference() {
344353 const custodian = pickCustodian ( pointerType ) ;
345354 const record = createRecord ( nhsNumber , pointerType , custodian ) ;
346355 record . id = `${ custodian } -k6perf-${ crypto . randomUUID ( ) } ` ;
347- const res = http . put ( getBaseURL ( ) , JSON . stringify ( record ) , {
348- headers : getHeaders ( custodian ) ,
356+ const path = "/DocumentReference" ;
357+
358+ const res = http . put ( getFullUrl ( path , "producer" ) , JSON . stringify ( record ) , {
359+ headers : getHeaders ( custodian , "producer" ) ,
349360 } ) ;
361+
350362 check ( res , { "create status is 201" : ( r ) => r . status === 201 } ) ;
351363 if ( res . status !== 201 ) {
352364 console . warn (
@@ -363,10 +375,12 @@ export function searchDocumentReference() {
363375 `https://fhir.nhs.uk/Id/nhs-number|${ nhs_number } `
364376 ) ;
365377 const type = encodeURIComponent ( `http://snomed.info/sct|${ pointer_type } ` ) ;
366- const url = `${ getBaseURL ( ) } ?subject:identifier=${ identifier } &type=${ type } ` ;
367- const res = http . get ( url , {
368- headers : getHeaders ( custodian ) ,
378+ const path = `/DocumentReference?subject:identifier=${ identifier } &type=${ type } ` ;
379+
380+ const res = http . get ( getFullUrl ( path , "producer" ) , {
381+ headers : getHeaders ( custodian , "producer" ) ,
369382 } ) ;
383+
370384 check ( res , {
371385 "searchDocumentReference status is 200" : ( r ) => r . status === 200 ,
372386 } ) ;
@@ -383,9 +397,12 @@ export function searchPostDocumentReference() {
383397 "subject:identifier" : `https://fhir.nhs.uk/Id/nhs-number|${ nhs_number } ` ,
384398 type : `http://snomed.info/sct|${ pointer_type } ` ,
385399 } ) ;
386- const res = http . post ( `${ getBaseURL ( ) } /_search` , body , {
387- headers : getHeaders ( custodian ) ,
400+ const path = `/DocumentReference/_search` ;
401+
402+ const res = http . post ( getFullUrl ( path , "producer" ) , body , {
403+ headers : getHeaders ( custodian , "producer" ) ,
388404 } ) ;
405+
389406 check ( res , {
390407 "searchPostDocumentReference status is 200" : ( r ) => r . status === 200 ,
391408 } ) ;
0 commit comments