# Identifiers

URL: https://docs.clinia.com/api/identifiers

> The character sets patient and session identifiers must match, and the prefixed form of the identifiers the Context Engine mints for graph nodes and edges.

Two kinds of identifier appear in the API: the ones you assign to a patient or a session, and the ones the Context Engine mints for the records it derives.

## Identifiers you assign [#identifiers-you-assign]

You choose the `patientId` when you [create a patient](https://docs.clinia.com/api/rest/put-patients-patientId), and you choose the `sessionId` when you [submit a transcript](https://docs.clinia.com/docs/learned-memory/learn-from-a-transcript).

New identifiers you assign must respect `[A-Za-z0-9][A-Za-z0-9.~:-]{0,127}`: 1 to 128 characters, opening on a letter or a digit, then letters, digits, `.`, `~`, `:` and `-`. [Creating a patient](https://docs.clinia.com/api/rest/put-patients-patientId) and [submitting a transcript](https://docs.clinia.com/api/rest/post-patients-patientId-ingestions-sessions) answer `400` for an identifier outside it.

`:` and `.` are in the set so a namespaced or composite key from the system you are integrating — `urn:oid:1.2.840.113619`, `epic:MRN-4471` — carries over unchanged.

`_` is missing from that set because it is [reserved for the identifiers the Context Engine mints](#identifiers-the-context-engine-mints).

Addressing a record you already have is wider than creating one, so nothing you assigned earlier stops working.

When you [create a session](https://docs.clinia.com/api/rest/post-patients-patientId-sessions) without choosing its id, the Context Engine mints the `sessionId` as a bare [cuid2](https://github.com/paralleldrive/cuid2), with no type prefix.

## Identifiers the Context Engine mints [#identifiers-the-context-engine-mints]

Every identifier the Context Engine mints for a node or an edge of the [patient graph](https://docs.clinia.com/docs/get-started/patient-graph) is a type prefix, an underscore, then a 24-character [cuid2](https://github.com/paralleldrive/cuid2):

```
lm_tz4a98xxat96iws9zmbrgj3a
└┘ └──────────────────────┘
prefix        cuid2
```

The full pattern is `[a-z]{2,4}_[a-z][0-9a-z]{23}`. The prefix names the record's type, so an identifier says what it addresses on its own, and reserving `_` keeps any identifier you assign from reading as one the Context Engine minted.

The [possible node prefixes](https://docs.clinia.com/api/rest/get-patients-patientId-graph-nodes-type-items-nodeId) are:

- `ef` - [`extracted_fact`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `fct` - [`fact`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `en` - [`extracted_narrative`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `np` - [`narrative_passage`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `nar` - [`narrative`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `lm` - [`learned_memory`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#learned-memory-objects)
- `ece` - [`extracted_clinical_event`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)

The [possible edge prefixes](https://docs.clinia.com/api/rest/get-patients-patientId-graph-edges-type-items-edgeId) are:

- `rd` - [`resolution_decision`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `rslv` - [`resolves_to`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `ci` - [`chunked_into`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)
- `rel` - [`relationship`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects)

A node-id filter accepts only an id carrying its type's prefix, and answers `400` for any other.

`GET …/graph/nodes/{type}/items/{nodeId}` and `GET …/graph/edges/{type}/items/{edgeId}` answer `400` when the id's prefix does not match `{type}`.
