# PDS API Patient search returns unexpected match

**URL:** <https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226>\
**Category:** Personal Demographics Service FHIR API\
**Tags:** spine\
**Created:** [15 February 2023 14:26 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226 "2023-02-15T14:26:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [15 February 2023 14:26 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/1 "2023-02-15T14:26:29Z")

</div>

Using the PDS API against the INT environment, we have found that the returned results don’t always match the search parameters.

Searching for a patient with these parameters:

```auto
{
  birthdate: '2011-05-09',
  gender: 'female',
  family: 'Shipperbottom'
}

```

returns a Bundle containing a single matched Patient resource with these attributes:

```auto
{
  birthdate: '1926-09-24',
  gender: 'male',
  family: 'Shipperbottom'
}

```

We expected that the matched Patient resource would be consistent with the search parameters.

Why does the service return this result?

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [16 February 2023 16:43 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/2 "2023-02-16T16:43:10Z")

</div>

Having done some further investigation, we can see that this problem occurs for around of the first patients listed in the PDS test data spreadsheet so we can confirm that this is not an isolated problem with a single patient.

The following combinations of parameters exhibit the problem:

```auto
           {
              birthdate: '1943-05-19',
              gender: PatientGenderCodes.FEMALE,
              family: 'AINDOW'
            },
            {
              birthdate: '2011-05-09',
              gender: PatientGenderCodes.FEMALE,
              family: 'SHIPPERBOTTOM'
            },
            {
              birthdate: '2009-02-15',
              gender: PatientGenderCodes.MALE,
              family: 'ANDERTON'
            },
            {
              birthdate: '2008-05-21',
              gender: PatientGenderCodes.MALE,
              family: 'FIELDING'
            },
            {
              birthdate: '2001-01-26',
              gender: PatientGenderCodes.FEMALE,
              family: 'SEO'
            }

```

---

<div class="post-metadata">

**Author:** ![chris.clarke](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/chris.clarke/32/134_2.png) [@chris.clarke](https://developer.community.nhs.uk/u/chris.clarke)\
**Post date:** [17 February 2023 12:45 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/3 "2023-02-17T12:45:57Z")

</div>

Some background:  
For “simple” searches, PDS uses inverted indexes, these are usually updated when a pdsRecord is saved.  
It _looks_ like, in the case of these particular records, the way they’ve been loaded has not updated those indexes and we’ve been left with some stale entries.  
I’m investigating as to the tool used and will recommend we add some improvements to prevent this happening in future. I’ll also look to clear out the aforementioned stale indexes for these records.

This will not happen in live as we do not use these tools to load test data.

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [17 February 2023 15:21 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/4 "2023-02-17T15:21:24Z")

</div>

Thanks for this update - it’s always useful to understand the system architecture.

For our hazard log entry, the same problem could occur in production but the risk is mitigated through operational controls (i.e. not using test tooling to load data) and the probability of occurrence will be very low. For our use case I don’t think we’ll then need to add any further mitigation.

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [27 February 2023 11:00 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/5 "2023-02-27T11:00:28Z")

</div>

We’ve retested this following the fix and find that searching for a patient with these parameters taken from the All PDS Data dataset no longer returns any matches:

```auto
{
  birthdate: '2011-05-09',
  gender: 'female',
  family: 'Shipperbottom'
}

```

We can retrieve a patient by searching using these parameters (i.e. the values previously returned as an erroneous response):

```auto
{
  birthdate: '1926-09-24',
  gender: 'male',
  family: 'Shipperbottom'
}

```

The returned patient has NHS Number `9449306621`, but has materially different demographics than for this patient in the test dataset.

Is it expected that the INT system contains different patients to the All PDS data test cases?

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [14 March 2023 10:22 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/6 "2023-03-14T10:22:29Z")

</div>

NHS API Management team let me know that the INT system should be consistent with the test pack. They haven’t provided any information about if/when this will be resolved.

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [25 May 2023 18:40 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/7 "2023-05-25T18:40:04Z")

</div>

Tested again and the problem is still present.

---

<div class="post-metadata">

**Author:** ![jeffriab](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@jeffriab](https://developer.community.nhs.uk/u/jeffriab)\
**Post date:** [5 October 2023 12:16 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/8 "2023-10-05T12:16:16Z")

</div>

Hi. Is anyone from the NHS team able to provide an update to this, please?

We’ve just found another instance where the `GET /Patient` endpoint response in the INT environment is different from the query and from `all-pds-data2.xlsx` in [PDS FHIR API test data - NHS Digital](https://digital.nhs.uk/developer/api-catalogue/personal-demographics-service-fhir/pds-fhir-api-test-data). The request specifies `BRITTAIN` family name, `1928-12-12` date of birth, and `KT19 9SA` postcode (per the spreadsheet), but the endpoint returns a patient with `2021-03-07` date of birth.

Thanks!

---

<div class="post-metadata">

**Author:** ![dunmail](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/dunmail/32/126_2.png) [@dunmail](https://developer.community.nhs.uk/u/dunmail)\
**Post date:** [5 October 2023 12:46 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/9 "2023-10-05T12:46:44Z")

</div>

Whilst the test data page says that the data are read-only, in reality they can be updated by users of the system and therefore can differ from the details in the spreadsheet. This is compounded by the problem that @chris.clarke described where the data underpinning `read` and `search` interactions become unsynchronised.

You can request a dataset specifically for your own use that is less likely to be modified.

---

<div class="post-metadata">

**Author:** ![jeffriab](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@jeffriab](https://developer.community.nhs.uk/u/jeffriab)\
**Post date:** [5 October 2023 13:09 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/10 "2023-10-05T13:09:18Z")

</div>

Thank you, @dunmail ! This is really unfortunate. Hopefully the NHS team can get this fixed soon as it just results in wasted time investigating the issue every time someone stumbles into it.

---

<div class="post-metadata">

**Author:** ![iminshall](https://avatars.discourse-cdn.com/v4/letter/i/a5b964/32.png) [@iminshall](https://developer.community.nhs.uk/u/iminshall)\
**Post date:** [14 December 2023 13:17 UTC](https://developer.community.nhs.uk/t/pds-api-patient-search-returns-unexpected-match/226/11 "2023-12-14T13:17:38Z")

</div>

Must admit I gave up some time ago that the INT data is representative of the spreadsheets. Most of my ‘favourite’ test patients seem to have different demographics.
