# Operational FHIR Encounter plus Patient and ITK HL7v2
**Category:** [FHIR](https://openhealthhub.org/c/fhir/31)
**Created:** 2019-04-29 14:29 UTC
**Views:** 2657
**Replies:** 2
**URL:** https://openhealthhub.org/t/operational-fhir-encounter-plus-patient-and-itk-hl7v2/2061
---
## Post #1 by @mayfield.g.kev
On UK systems Encounter management is mainly done using HL7v2. An example is shown below
MSH|^~\&|PatientCentre|RR8|ROUTE|ROUTE|20190429115837||ADT^A08|lt190429105838455588|T|2.4||||||ASCII|EN
EVN|A01|20190429115837||AD02
PID|||000031920^^^RR8^PI~0031740^^^RR8^MR|GH5236^^^RR8^AN|TEST^LYNNEA^^^^^L||20030501|2|||^^^^^^^^|||||U^^NHS|U^UNKNOWN^RR8|||||99^^NHS||||||||0||3
PV1||I|ZZZ^^^RR813|21||^^^^^^^^|||PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS|101^^^^^^^^NHS||||19|||||000000001^^^RR8^VN|||||||||||||||||||||||||201904291157||||||000520726^^^RR8^VN
PV2||||||||||000||~|xxx||||||||||||||||||||
ZU1||1|||||||||||^^^|||||||||||
ZU5||10^NHS - NOT DETAINED^RR8
It may be an old standard but it still does the job. The equivalent in FHIR is [FHIR Messaging](https://www.hl7.org/fhir/stu3/messaging.html) and is similar to the DCH event messages mentioned in a previous post https://www.openhealthhub.org/t/operational-fhir-encounter-example/2060
By rearranging the DCH message we have the following core structure, the first three letters on each line are the segment type
* **MessageHeader**
* **Encounter**
* **Patient**
This structure is also in the HL7v2 message above
* **MSH** Message Header
* **EVN** Event Header
* **PID** Patient Information
* **PV1** Patient visit
* **PV2** Patient visit continued
We can now see a rough map between HL7 v2 and FHIR, PID is Patient, PV1 and PV2 is Encounter, etc.
**Encounter / PV1**
I'm just going to on building on from this post https://www.openhealthhub.org/t/operational-fhir-encounter-example/2060 and start adding other elements. Looking at the PV1.2 segment, the type is I which stands for inpatient (for a breakdown of the PV1 segment use https://corepointhealth.com/resource-center/hl7-resources/hl7-pv1-patient-visit-information-segment/ or download the ITK HL7v2 specification from [TRUD](https://isd.digital.nhs.uk/trud3/user/guest/group/0/home))
PV1||**I**|ZZZ^^^RR813|21||^^^^^^^^|||PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS|101^^^^^^^^NHS||||19|||||000000001^^^RR8^VN|||||||||||||||||||||||||201904291157||||||000520726^^^RR8^VN
This gives in FHIR
Next we will add extract the type which is located at PV1.10
PV1||I|ZZZ^^^RR813|21||^^^^^^^^|||PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS|**101^^^^^^^^NHS**||||19|||||000000001^^^RR8^VN|||||||||||||||||||||||||201904291157||||||000520726^^^RR8^VN
and in FHIR
We need a status for the encounter, this is mandatory. The message type in the MSH segment at MSH.9, for Encounter messages, ADT^A01 indicates the patient has arrived, ADT^A03 means the patient has been discharged, ADT^A02 shows a patient transfer and ADT^A08 an amendment. In our example the patient is being admitted, so the status becomes
As the patient has arrived we will have a start time for the Encounter and this is located at PV1.44
PV1||I|ZZZ^^^RR813|21||^^^^^^^^|||PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS|101^^^^^^^^NHS||||19|||||000000001^^^RR8^VN|||||||||||||||||||||||||**201904291157**||||||000520726^^^RR8^VN
We also have a practitioner which is located at PV1.17
PV1||I|ZZZ^^^RR813|21||^^^^^^^^|||**PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS**|101^^^^^^^^NHS||||19|||||000000001^^^RR8^VN|||||||||||||||||||||||||201904291157||||||000520726^^^RR8^VN
I'm going to ignore the PHS code and just concentrate on the SDS/ODS code for the Practitioner. In the last post we had a discussion about using identifier references but here we have no choice, we only know the consultant by their code, so this gives (I've set a participation type but this is optional):
Note: I'm doing a quick conversion at the moment, it may be desirable to use a full reference and include Practitioner in the message Bundle.
**Identifiers**
HL7v2 normally carries two:
PV1.19 Visit Number
PV1.50 Alternate Visit Number.
PV1||I|ZZZ^^^RR813|21||^^^^^^^^|||PHS^^^^^^^^RR8~C0735492^^^^^^^^NHS|101^^^^^^^^NHS||||19|||||**000000001**^^^RR8^VN|||||||||||||||||||||||||201904291157||||||**000520726**^^^RR8^VN
For this LeedsTH we can ignore the second number but as we want a unique identifier for our Encounters (000000001 in unlikely to be unique) we concatenate this with the internal patient number taken from the PID segment.
PID|||**000031920^^^RR8^PI**~0031740^^^RR8^MR|GH5236^^^RR8^AN|TEST^LYNNEA^^^^^L||20030501|2|||^^^^^^^^|||||U^^NHS|U^UNKNOWN^RR8|||||99^^NHS||||||||0||3
Giving a encounter number of 000031920-000000001 for the system value we have chosen to use
https://fhir.leedsth.nhs.uk/Id/Encounter/episode-number (the use of the term episode may be confusing but this is the name the PAS system uses).
In theory we should also create a NamingSystem to be recorded in a registries to describe and define the url
e.g. [Leeds Teaching Trust Episode Number https://fhir.leedsth.nhs.uk/Id/Encounter/episode-number](https://data.developer.nhs.uk/ccri/term/namingsystem/475) This shows who owns the url and links to other interop systems, we will come back to this.
We also add in a serviceProvider and put a name for the patient giving this Encounter resource
**Patient/PID**
Patient demographics will be supplied on the PID and PD1 (if present) segment. Taking the identifiers first, we don't have a NHS number so that can't be included but we do have a LeedsTH PAS Number and Internal Patient number.
PID|||**000031920^^^RR8^PI~0031740^^^RR8^MR**|GH5236^^^RR8^AN|TEST^LYNNEA^^^^^L||20030501|2|||^^^^^^^^|||||U^^NHS|U^UNKNOWN^RR8|||||99^^NHS||||||||0||3
This gives:
As with the LeedsTH Encounter identifiers I've also created NamingSystems but this time they have entries for HL7 v2 and FHIR e.g. for PAS Number we have:
The CCRI Server renders this a little better https://data.developer.nhs.uk/ccri/term/namingsystem/470
The name and date of birth is straight forward.
The gender value **2** needs to be converted to a value in this valueSet https://fhir.hl7.org.uk/STU3/ValueSet/CareConnect-AdministrativeGender-1 If you follow the link you will see it has an embedded ConceptMap which shows 2 = female.
Like before we add in the profile in the meta section giving:
Pasting this example into the CCRI validation tool shows no errors. As a final test you may wish to POST this resource to the CCRI (set the ContentType header to and POST the resource to https://data.developer.nhs.uk/ccri-fhir/STU3/Patient)
You could also try POST the Encounter resource, however the server uses FHIR RESTful and doesn't know how to process the identifier references.
We've only scratched the surface on converting from v2 to FHIR, we've not covered the MessageHeader or how to deal additional data not covered by the Care Connect FHIR profiles (extensions).
---
## Post #2 by @zizizak
Hi there, I see you make mapping HL7V2 to FHIR, does we have library to make that ? If we do this so complex. See other resouce : http://www.hl7.org/documentcenter/public/wg/xml/drafts/v2xml.html
---
## Post #3 by @mayfield.g.kev
I've built a mapper but thats for a client. What I did was follow the spreadsheets produced by HL7 International https://docs.google.com/spreadsheets/d/1PaFYPSSq4oplTvw_4OgOn6h2Bs_CMvCAU9CqC4tPBgk
Some more UK focused examples are here https://kevinmayfield.github.io/careconnect-messaging/adt.html
---
**Canonical:** https://openhealthhub.org/t/operational-fhir-encounter-plus-patient-and-itk-hl7v2/2061
**Original content:** https://openhealthhub.org/t/operational-fhir-encounter-plus-patient-and-itk-hl7v2/2061