---
title: "Entity: Medication Web Specification"
canonical: "https://wiki.patientsknowbest.com/space/api/3867574409/Entity%3A%20Medication%20Web%20Specification"
format: markdown
---
> Macro (toc)

# Overview

This page provides more detail on how the web interface displays medication information, which it fetches from the Aggregated FHIR API. Note:

- Whilst this page explains which elements are inspected, the web interface does not provide any feedback about which/whether other FHIR elements are present in the database that are not being displayed.
- Some information is displayed that is not fetched from the Aggregated FHIR API, such as attachments.

The [Manual provides more information](https://manual.patientsknowbest.com/patient/medicines) on the functionality; this page is aimed at a technical audience who need to understand the relationship between the FHIR resources and the web interface.

# FHIR® Resources

The web interface populates Medicines from the following FHIR resources:

- [MedicationRequest](https://www.hl7.org/fhir/R4/medicationrequest.html)
- [MedicationStatement](https://www.hl7.org/fhir/R4/medicationstatement.html)

# Summary

The web interface shows a list of medications. These are separated into “Current medicines” and “Past medicines”. A medication is considered to be current unless either of the following are true:

- The medication has an End Timestamp which is in the past
- The medication Status is UNKNOWN or not ACTIVE

The current medications are ordered by start timestamp descending, then end timestamp descending, and then alphabetically.

Past medications will be visually grouped together when they match on the following criteria:

- medicationCodeableConcept
- Source Organization
- Access route

# Mappings

| **Component** | **MedicationRequest** | **MedicationStatement** |
| --- | --- | --- |
| **Status**<br>This is not shown explicitly, but is included in the logic which determines if the medication is current or past. | status<br>status code mappings (FHIR → PKB):<br>- active → ACTIVE
- unknown → ACTIVE
- entered-in-error → INACTIVE
- completed → INACTIVE
- stopped → INACTIVE
- on-hold → INACTIVE
- cancelled → INACTIVE
- draft → INACTIVE | status<br>status code mappings (FHIR → PKB):<br>- active → ACTIVE
- unknown → ACTIVE
- entered-in-error → INACTIVE
- completed → INACTIVE
- stopped → INACTIVE
- on-hold → INACTIVE
- intended → INACTIVE
- not-taken → INACTIVE |
| **Substance**<br>The medication substance is shown in 2 places:<br>- A primary display string. This is a simple display string shown in the unexpanded row view.
- Additional details. Information about the medication code and system values are shown in the expanded row view. | <span style="color: #ff991f">**<conditional>**</span><br><span style="color: #ff991f">**If medicationReference is populated:**</span><br>(Note: Medication is a [merged resource type](https://wiki.patientsknowbest.com/space/api/3364388935/Aggregated#Merge-logic); the merge logic affects the content of the resource.)<br><u>Primary display string</u><br>- <span style="color: #ff991f">If code.text is populated:</span> the same text
- <span style="color: #ff991f">else:</span> the last populated code.coding[x].display
- <span style="color: #ff991f">else:</span> the empty string<br><u>Additional details</u><br>The code and system of all code.coding Codings are shown. Other elements of the Coding are not shown.<br>Note: the system will be replaced with user-friendly name when known to PKB.<br><span style="color: #ff991f">**Else:**</span><br><u>Primary display string</u><br>- <span style="color: #ff991f">If medicationCodeableConcept.text is populated:</span> the same text
- <span style="color: #ff991f">else:</span> if a Coding is present and contains the [http://fhir.patientsknowbest.com/structuredefinition/primary-coding](http://fhir.patientsknowbest.com/structuredefinition/primary-coding) extension: the display of the same Coding
- <span style="color: #ff991f">else:</span> the first populated medicationCodeableConcept.coding[x].display
- <span style="color: #ff991f">else:</span> the empty string<br><u>Additional details</u><br>As per the logic above for primary display string. |
| **Start Timestamp** | <span style="color: #ff991f"><conditional></span><br><span style="color: #ff991f">If this extension is present: </span>[http://nictiz.nl/fhir/StructureDefinition/zib-Medication-PeriodOfUse](http://nictiz.nl/fhir/StructureDefinition/zib-Medication-PeriodOfUse)<br>extension[x]: valuePeriod.start<br><span style="color: #ff991f">Else:</span><br>authoredOn | effectivePeriod.start |
| **End Timestamp** | <span style="color: #ff991f"><conditional></span><br><span style="color: #ff991f">If this extension is present: </span>[http://nictiz.nl/fhir/StructureDefinition/zib-Medication-PeriodOfUse](http://nictiz.nl/fhir/StructureDefinition/zib-Medication-PeriodOfUse)<br>extension[x]: valuePeriod.end<br><span style="color: #ff991f">Else:</span><br>No value. | effectivePeriod.end |
| For the dosage and frequency-related information, except where noted PKB will use the Primary Dosage, which is the Dosage determined as follows:<br>- Determine which Dosage list to inspect
  - If the resource is a MedicationRequest: then use <u>dosageInstruction</u>
  - Else if the resource is a MedicationStatement: then use <u>dosage</u>
- The select 1 Dosage from the list as follows:
  - If there is exactly one Dosage where <u>sequence is 1</u>, then use the same
  - Else: use the <u>first in the list</u> |
| **“Structured Frequency”**<br>**(Frequency Priority / Frequency Value / Frequency Units)** | <span style="color: #ff991f"><conditional></span><br><span style="color: #ff991f">If asNeededCodeableConcept is present, or asNeededBoolean is set to true:</span><br>“Take as needed” will be shown; i18n is applied.<br><span style="color: #ff991f">Else if Timing.code is populated with any value:</span><br>“Take as directed” will be shown; i18n is applied.<br><span style="color: #ff991f">Else if Timing.repeat has frequency set to 1, periodUnit has a value of either “d” or “h”, and period is a known integer for the corresponding periodUnit:</span><br>A corresponding textual description; i18n is applied.<br>Example: “Every four hours”<br><span style="color: #ff991f">Else:</span><br>No value. |
| **Frequency Text**<br>This is shown underneath the main line for the medication. | <span style="color: #ff991f">**<conditional>**</span><br><span style="color: #ff991f">**If text is populated:**</span> the same text<br><span style="color: #ff991f">**Else if there was no Structured Frequency found, and Timing.repeat is populated with both period and periodUnit:**</span><br><span style="color: #ff991f">If frequency element is also populated:</span><br>“<frequency> time(s) every <period> <periodUnit>(s)” will be generated and shown; i18n is not applied.<br><span style="color: #ff991f">Else:</span><br>“Every <period> <periodUnit>(s)” will be generated and shown; i18n is not applied.<br><span style="color: #ff991f">**Else:**</span><br>No value. |
| **Dose Value** | doseAndRep[0].doseQuantity.value |
| **Dose Units / Medication Unit**<br>The dose unit is shown in 2 places:<br>- A primary display string. This is a simple display string shown in the unexpanded row view.
  - Note: this is only displayed if Dose Value is populated.
- Additional details. Information about the dose unit code and system values are shown in the expanded row view. |  | <span style="color: #ff991f">**<conditional>**</span><br><span style="color: #ff991f">**If doseAndRep[0].doseQuantity has a code, no unit and no system:**</span><br>The code is assumed to be one of the supported unit values as per [[Medication Unit]].<br><u>Primary display string</u><br>The primary display string will be an appropriate display name with i18n applied.<br><u>Additional details</u><br>There is no additional code information to display.<br><span style="color: #ff991f">**Else:**</span><br>We inspect the first Dosage (which might differ from the previously determined Primary Dosage) and inspect doseAndRep[0].doseQuantity for the [http://fhir.patientsknowbest.com/structuredefinition/dose-units](http://fhir.patientsknowbest.com/structuredefinition/dose-units) extension.<br><u>Primary display string</u><br>- <span style="color: #ff991f">If text is populated:</span> the same text
- <span style="color: #ff991f">else:</span> if a Coding is present and contains the [http://patientsknowbest.com/structuredefinition/primary-coding](http://patientsknowbest.com/structuredefinition/primary-coding) extension: the display of the same Coding
- <span style="color: #ff991f">else:</span> the first populated coding[x].display
- <span style="color: #ff991f">else:</span> the empty string<br><u>Additional details</u><br>The code and system of all Codings are shown. Other elements of the Coding are not shown.<br>Note: the system will be replaced with user-friendly name when known to PKB. |
| **Instructions** | The instructions displayed will be the concatenation of all of the following information, in this order:<br>- Dosage.patientInstruction
- Each Dosage.additionalInstruction[x].text value |