For AI agents: the documentation index is at /docs/aidbox/llms.txt. A Markdown version of this page is available at /docs/aidbox/notebooks.md or by requesting it with the Accept: text/markdown header.
Aidbox Docs
All notebooks

MPI Demo Script

Script, instructions and REST-requests for Demo

11 cells · updated Dec 9, 2025

This is a read-only view. Responses shown were saved when the notebook was published — open it in your own Aidbox to run the cells against live data.

Before the Demo

  1. Perform a preliminary search by identifier: enter MPI-DEMO in the field on the Patient view and Non duplicates pages, then click Search.
  2. Remove pairs pt-1 pt-2 and pt-1 pt-4 from Non Duplicates if needed.
  3. Execute the following request:
REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
PUT /fhir/Patient/pt-1
content-type: text/yaml
accept: text/yaml

address:
  - use: home
    city: Anytown
    line:
      - 123 River St
    state: CA
    country: USA
    postalCode: '12345'
meta:
  extension:
    - url: ex:createdAt
      valueInstant: '2025-06-17T08:47:11.736939Z'
    - url: https://aidbox.app/ex/createdAt
      valueInstant: '2025-06-17T08:47:11.736939Z'
  lastUpdated: '2025-08-28T14:44:48.158828Z'
  versionId: '1505049'
name:
  - use: official
    given:
      - John
      - B.
    family: Doe
birthDate: '1980-11-07'
resourceType: Patient
id: >-
  pt-1
identifier:
  - type:
      coding:
        - code: MPI-DEMO
          system: MPI-DEMO
    value: MPI-DEMO
    system: MPI-DEMO
  - use: usual
    type:
      coding:
        - code: MR
          system: http://hl7.org/fhir/v2/0203
    value: '123456'
    system: http://hospital.smarthealthit.org
  - use: official
    type:
      coding:
        - code: SS
          system: http://hl7.org/fhir/v2/0203
    value: 987-65-4320
    system: http://hl7.org/fhir/sid/us-ssn
  - use: usual
    type:
      coding:
        - code: MR
          system: http://hl7.org/fhir/v2/0203
    value: '1234567'
    system: http://hospital.smarthealthit.org
  - use: usual
    type:
      coding:
        - code: MR
          system: http://hl7.org/fhir/v2/0203
    value: '1234'
    system: http://hospital.smarthealthit.org
telecom:
  - use: home
    value: 555-123-4567
    system: phone
  - use: home
    value: 555-765-4321
    system: fax
  - use: home
    value: john.doe@example.com
    system: email
gender: male
Response: Body
Status: 200
address:
- use: home
  city: Anytown
  line: [123 River St]
  state: CA
  country: USA
  postalCode: '12345'
meta:
  extension:
  - {url: 'ex:createdAt', valueInstant: '2025-06-17T08:47:11.736939Z'}
  - {url: 'https://aidbox.app/ex/createdAt', valueInstant: '2025-10-09T12:52:08.264758Z'}
  lastUpdated: '2025-11-20T17:13:23.470790Z'
  versionId: '1508709'
name:
- use: official
  given: [John, B.]
  family: Doe
birthDate: '1980-11-07'
resourceType: Patient
id: pt-1
identifier:
- type:
    coding:
    - {code: MPI-DEMO, system: MPI-DEMO}
  value: MPI-DEMO
  system: MPI-DEMO
- use: usual
  type:
    coding:
    - {code: MR, system: 'http://hl7.org/fhir/v2/0203'}
  value: '123456'
  system: http://hospital.smarthealthit.org
- use: official
  type:
    coding:
    - {code: SS, system: 'http://hl7.org/fhir/v2/0203'}
  value: 987-65-4320
  system: http://hl7.org/fhir/sid/us-ssn
- use: usual
  type:
    coding:
    - {code: MR, system: 'http://hl7.org/fhir/v2/0203'}
  value: '1234567'
  system: http://hospital.smarthealthit.org
- use: usual
  type:
    coding:
    - {code: MR, system: 'http://hl7.org/fhir/v2/0203'}
  value: '1234'
  system: http://hospital.smarthealthit.org
telecom:
- {use: home, value: 555-123-4567, system: phone}
- {use: home, value: 555-765-4321, system: fax}
- {use: home, value: john.doe@example.com, system: email}
gender: male

Search

Open Patients View

Before I start to show you the live system, I’d like to mention, that this product was originally built to solve a specific challenge for our current customer. We understand your needs might be different, and we’re ready to expand the functionality or add features if you choose to move forward with us.

So let's start and go through the core features and workflows.

The first screen you see is the Patients view.

Here, you can search for a patient using the available information. Let’s say we know the patient’s first name is John, the last name is Doe, and we also know his phone number - 555-123-4567.

In the search on the left, enter John in the First Name field and Doe in the Last Name field

Let’s try searching for him. Okay, we’ve found our John Doe. pt-1

We can click on a row to see more details about this patient, browse their encounters, quickly jump to the merge history, or review the non-duplicates.

Match

And of course, we can search for potential duplicates. Let's cick "Match" button here or or directly in the table.

Click Match

After that, we get to a view where we can choose the most similar patient for merging, or select any patient from the database.

Let’s go back to the search by similarity.

And here we see a list of potential matches — patients who might be duplicates of John.

You should see a list of 3 matches: pt-2, pt-3, and pt-4

Why these records? Our matching model evaluates records in the system, calculates a matching weight for each pair, and sorts them by how likely it is that they represent the same person. You can set a threshold — a minimum weight value for a record to be shown as a potential match. Only records with a weight above that threshold will appear in this list.

In the case with John Doee, the weight is pretty high — the maximum is 33 — so it seems very likely this is a duplicate.

We can also visually see that the differences in the data are indeed small — the fields with different values are highlighted in red.

Merge

Let’s try to merge these records.

With just one click, we go to the merge page.

Click on the row with John Doee (pt-2)

Here, we can choose which information to keep in the final, merged record. For example:

Choose the fields like in the script

  • We want to keep the ID from the original record.
  • We take the middle name from the duplicate.
  • The last name has a typo in the duplicate, so we keep the original one.
  • And we choose the address from the duplicate. Now we click Merge.

It’ll be only one match in the list after the merge pt-3

As a result, we see that: John’s address has been updated. The duplicate John has disappeared from the list, this record was actually deleted. One of other potential matches have disappeared too — because the base record has changed. Let’s try to adjust the threshold — set it lower, for example to 14.

Enter 14 in the Threshold field and click Search

Now we can see more potential matches — all remaining Johns are here.

Non-Duplicates

Let’s imagine now that we know for sure that our John Doe and this John Smith are not the same person. We can mark them as non-duplicates. Click on the row, and hit the "Mark as non-duplicates" button.

Click on the row with John Smith (pt-4) and then Mark as non-duplicates

Done! Now John Smith is no longer shown in the match suggestions for John Doe.

Let’s go back to the Patients view, and open the Non-duplicates tab.

Select “Non duplicates” on the tab panel

Here, we can see our non-duplicate pair.

You’ll see the pair of pt-1 and pt-4

If we made a mistake, we can always remove them from the list.

Merge Logs & Unmerge

In the background, you will need to execute a request to add an encounters for pt-1

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /Encounter
content-type: application/json
accept: application/json
 
{
	"identifier": [{"type": {"coding": [{"code": "EPISODENUMBER"}]},
                 	"value": "54321",
                	"system": "CPLSW"}],
	"status": "planned",
	"class": {"code": "1"},
	"participant": [{"individual": {"id": "prac-1",
                 	"resourceType": "Practitioner"}}],
	"period": {"start": "2025-10-10", "end": "2025-10-11"},
	"subject": {
  	"id": "pt-1",
  	"resourceType": "Patient"
	},
	"resourceType": "Encounter"
  }
Response: Body
Status: 201
{
  "meta": {
    "lastUpdated": "2025-11-20T18:54:19.961716Z",
    "createdAt": "2025-11-20T18:54:19.961716Z",
    "versionId": "1508723"
  },
  "participant": [
    {
      "individual": {
        "id": "prac-1",
        "resourceType": "Practitioner"
      }
    }
  ],
  "resourceType": "Encounter",
  "status": "planned",
  "id": "526cffd3-506e-46fe-b834-703163d11a02",
  "class": {
    "code": "1"
  },
  "identifier": [
    {
      "type": {
        "coding": [
          {
            "code": "EPISODENUMBER"
          }
        ]
      },
      "value": "54321",
      "system": "CPLSW"
    }
  ],
  "period": {
    "end": "2025-10-11",
    "start": "2025-10-10"
  },
  "subject": {
    "id": "pt-1",
    "resourceType": "Patient"
  }
}
REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /Encounter
content-type: application/json
accept: application/json
 
{
	"identifier": [{"type": {"coding": [{"code": "EPISODENUMBER"}]},
                 	"value": "54321",
                	"system": "CPLSW"}],
	"status": "planned",
	"class": {"code": "1"},
	"participant": [{"individual": {"id": "prac-1",
                 	"resourceType": "Practitioner"}}],
	"period": {"start": "2025-01-01"},
	"subject": {
  	"id": "pt-1",
  	"resourceType": "Patient"
	},
	"resourceType": "Encounter"
  }
Response: Body
Status: 201
{
  "meta": {
    "lastUpdated": "2025-11-06T11:44:48.832425Z",
    "createdAt": "2025-11-06T11:44:48.832425Z",
    "versionId": "1507036"
  },
  "participant": [
    {
      "individual": {
        "id": "prac-1",
        "resourceType": "Practitioner"
      }
    }
  ],
  "resourceType": "Encounter",
  "status": "planned",
  "id": "392bb480-bd08-4dc0-be49-b67e58c4df0e",
  "class": {
    "code": "1"
  },
  "identifier": [
    {
      "type": {
        "coding": [
          {
            "code": "EPISODENUMBER"
          }
        ]
      },
      "value": "54321",
      "system": "CPLSW"
    }
  ],
  "period": {
    "start": "2025-01-01"
  },
  "subject": {
    "id": "pt-1",
    "resourceType": "Patient"
  }
}

Now, let’s check the Merges tab.

Select Merges on the tab panel

You can:

  • View details of the merge
  • See who performed the merge and when
  • Dive in and Review the linked resources

Here you should click on the row with pt-1 и pt-2 with status Merged

  • And perform an Unmerge operation if needed.

So we can click Unmerge preview button.

Click Unmerge preview. If an encounter was created, a window will appear to select which patient to link it to

Oh, we notice that some new encounter was created for the merged record. We want to reassign them to the correct patient before unmerging.

Assign new encounter to pt-2

Okay — we’re ready — click Unmerge.

Click Unmerge, then click Back to the Merges and refresh the page

Now, in the table, we can see that the status has changed to UNMERGED.

Show Non-duplicates in Match list

Let’s go back to the Patients view to check what happened.

Select “Patients” on the tab panel

We already know that our John Doee should be restored. But he’s no longer in the match list. That’s because during the unmerge, the system automatically marked him as a non-duplicate of the original John Doe. Let’s enable the “Show non-duplicates” toggle

Click on the “Show non-duplicates” toggle

And yes, here he is.

That’s it for the demo. Thank you for your attention Our team will be happy to answer any questions.