Skip to content

Commit

Permalink
added missing sandbox scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
agelledi committed Nov 14, 2024
1 parent bc45675 commit f167dc4
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 6 deletions.
25 changes: 24 additions & 1 deletion karate-tests/src/test/java/mocks/sandbox/get-patient-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,22 @@ const matchCases = [
params.postalCode === 'DN16',
action: () => timestampBody(EMPTY_SEARCHSET)
},
// Fuzzy search
{
condition: (params) => params.fuzzyMatch && !params.phone && !params.email,
action: () => timestampBody(FUZZY_SEARCH_PATIENT_17)
},
// Fuzzy search including phone
{
condition: (params) => params.fuzzyMatch && params.phone === '01632960587' && !params.email,
action: () => timestampBody(janeSmithSearchsetWithScore(0.9124))
},
// Fuzzy search including email
{
condition: (params) => params.fuzzyMatch && params.email === '[email protected]' && !params.phone,
action: () => timestampBody(janeSmithSearchsetWithScore(0.9124))
},
// Fuzzy search including phone and email
{
condition: (params) => params.fuzzyMatch && params.phone === '01632960587' && params.email === '[email protected]',
action: () => timestampBody(janeSmithSearchsetWithScore(0.9542))
Expand All @@ -198,39 +202,58 @@ const matchCases = [
condition: (params) => params.historyMatch && params.family === 'MED' && (params.birthDate[0]) === '2024-01-12',
action: () => timestampBody(EMPTY_SEARCHSET)
},
// Wildcard search
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && !params.phone && !params.email && !params.maxResults,
action: () => timestampBody(WILDCARD_SEARCH)
},
// Search with limited results
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && !params.phone && !params.email && parseInt(params.maxResults) < 2,
action: () => TOO_MANY_MATCHES
},
// Search with limited results inc phone
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.phone === '01632960587' && params.email,
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.phone && !params.email && parseInt(params.maxResults) < 2,
action: () => TOO_MANY_MATCHES
},
// Search with limited results inc email
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && !params.phone && params.email && parseInt(params.maxResults) < 2,
action: () => TOO_MANY_MATCHES
},
// wildcard search including phone
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.phone === '01632960587' && !params.email,
action: () => timestampBody(janeSmithSearchsetWithScore(1))
},
// wildcard search including email
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.email === '[email protected]' && !params.phone,
action: () => timestampBody(janeSmithSearchsetWithScore(1))
},
// wildcard search including email
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.email === '[email protected]' && params.phone === '01632960587',
action: () => timestampBody(janeSmithSearchsetWithScore(1))
},
// Search with limited results inc phone
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.email === '[email protected]',
action: () => timestampBody(janeSmithSearchsetWithScore(1))
},
// Multiple matches with phone and email
{
condition: (params) => ['Sm*', 'sm*'].includes(params.family) && params.email === '[email protected]' && params.phone === '01234123123' &&
(params.birthDate[0]) === 'eq2000-05-05',
action: () => timestampBody(MULTIMATCHWITHPHONEANDEMAIL_SEARCHSET)
},
// Restricted (sensitive) patient search
{
condition: (params) => ['Smythe', 'smythe'].includes(params.family),
action: () => timestampBody(RESTRICTED_PATIENT_SEARCH)
},
// Search with date range, Basic search, Basic search including phone
{
condition: (params) => ['Smith', 'smith'].includes(params.family) && ['Female', 'female'].includes(params.gender) &&
(params.birthDate[0] === 'eq2010-10-22' || (params.birthDate[0] === 'ge2010-10-21' && params.birthDate[1] === 'le2010-10-23')) &&
Expand Down
32 changes: 32 additions & 0 deletions karate-tests/src/test/java/mocks/sandbox/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@ function removeUsualName (patient) {
function removeBirthDate () {
forbiddenUpdate = 'Forbidden update with error - source not permitted to remove \'birthDate\''
}

function addDeceasedDate (patient, value) {
patient.deceasedDateTime = value
}

function addExtension (patient, value) {
patient.extension = [value]
}

function updateDeceasedDate (patient, value) {
patient.deceasedDateTime = value
}

function updateExtension (patient, index, value) {
patient.extension[index] = value
}

function updateSingleItemInExtension (patient, index, childIndex, value) {
patient.extension[index].extension[childIndex] = value
}

function removeExtensionIfExists (patient, updateErrors, index) {
if (!patient.extension[index]) {
updateErrors.push("Invalid update with error - Invalid patch - can't remove non-existent object '0'")
} else {
delete patient.extension[index]
}
}

function removeSingleItemFromExtension (patient, index, childIndex) {
patient.extension[index].extension.splice(childIndex, 1)
}
23 changes: 19 additions & 4 deletions karate-tests/src/test/java/mocks/sandbox/patch-patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

/* Functions defined in operations.js */
/* global updateAddressDetails, handleNameRemovalError, removeSuffixIfExists, removeNameSuffix, updateGivenName, updateGender, updateBirthDate,
addNameSuffixAtStart, addNameSuffix, addNewName, removeUsualName, removeBirthDate, forbiddenUpdate */
addNameSuffixAtStart, addNameSuffix, addNewName, removeUsualName, removeBirthDate, forbiddenUpdate, addDeceasedDate, addExtension
updateDeceasedDate, updateExtension, updateSingleItemInExtension, removeExtensionIfExists, removeSingleItemFromExtension */

function buildResponseHeaders (request, patient) {
return {
Expand Down Expand Up @@ -85,6 +86,9 @@ function patchPatient (originalPatient, request) {
if (request.header('if-match') !== `W/"${originalPatient.meta.versionId}"`) {
return setResourceVersionMismatchError(request)
}
if (request.body.patches.length === 0) {
return setInvalidUpdateError(request, NO_PATCHES_PROVIDED)
}

const validOperations = ['add', 'replace', 'remove', 'test']
// Validate patch operations
Expand All @@ -105,7 +109,9 @@ function patchPatient (originalPatient, request) {
const addPaths = {
'/name/-': () => addNewName(value, updatedPatient),
'/name/0/suffix': () => addNameSuffix(updatedPatient, value),
'/name/0/suffix/0': () => addNameSuffixAtStart(updatedPatient, value)
'/name/0/suffix/0': () => addNameSuffixAtStart(updatedPatient, value),
'/deceasedDateTime': () => addDeceasedDate(updatedPatient, value),
'/extension/-': () => addExtension(updatedPatient, value)
}
if (addPaths[path]) {
addPaths[path]()
Expand All @@ -120,7 +126,13 @@ function patchPatient (originalPatient, request) {
'/birthDate': () => updateBirthDate(updatedPatient, value),
'/address/0/line/0': () => updateAddressDetails(value, originalPatient, updateErrors),
'/address/0/line': () => updateAddressDetails(value, originalPatient, updateErrors),
'/address/0/id': () => updateAddressDetails(value, originalPatient, updateErrors)
'/address/0/id': () => updateAddressDetails(value, originalPatient, updateErrors),
'/deceasedDateTime': () => updateDeceasedDate(updatedPatient, value),
'/extension/3': () => updateExtension(updatedPatient, 3, value),
'/extension/4': () => updateExtension(updatedPatient, 4, value),
'/extension/5': () => updateExtension(updatedPatient, 5, value),
'/extension/4/extension/0': () => updateSingleItemInExtension(updatedPatient, 4, 0, value),
'/extension/5/extension/1': () => updateSingleItemInExtension(updatedPatient, 5, 1, value)
}
if (replacePaths[path]) {
replacePaths[path]()
Expand All @@ -135,8 +147,11 @@ function patchPatient (originalPatient, request) {
'/name/0/suffix': () => removeNameSuffix(updatedPatient),
'/name/0/suffix/0': () => removeSuffixIfExists(updatedPatient, updateErrors, 0),
'/name/1': () => handleNameRemovalError(request, updateErrors, updatedPatient),
'/name/5': () => handleNameRemovalError(request, updateErrors, updatedPatient),
'/name/0': () => removeUsualName(updatedPatient),
'/birthDate': () => removeBirthDate()
'/birthDate': () => removeBirthDate(),
'/extension/4': () => removeExtensionIfExists(updatedPatient, updateErrors, 4),
'/extension/5/extension/2': () => removeSingleItemFromExtension(updatedPatient, 5, 2)
}
if (removePaths[path]) {
removePaths[path]()
Expand Down
Loading

0 comments on commit f167dc4

Please sign in to comment.