Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.hl7.fhir.r4.model.Coding as R4Coding
import org.hl7.fhir.r4.model.DateTimeType as R4DateTimeType
import org.hl7.fhir.r4.model.DomainResource as R4Resource
import org.hl7.fhir.r4.model.Extension as R4Extension
import org.hl7.fhir.r4.model.IdType as R4IdType
import org.hl7.fhir.r4.model.MedicationRequest as R4MedicationRequest
import org.hl7.fhir.r4.model.StringType as R4StringType
import org.hl7.fhir.r4.model.UnsignedIntType as R4UnsignedIntType

internal const val CARECONNECT_REPEAT_INFORMATION_URL =
Expand Down Expand Up @@ -40,6 +42,15 @@ internal const val UKCORE_PRESCRIBING_ORGANIZATION_URL =
"https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-MedicationPrescribingOrganization"


internal const val CARECONNECT_DESCRIPTION_ID_URL =
"https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid"
internal const val CARECONNECT_GPC_DESCRIPTION_ID_URL =
//TODO: what's the GPC url for this extension?
""

internal const val UKCORE_DESCRIPTION_ID_URL =
"https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-CodingSCTDescId"

internal val careconnectTransformers: HashMap<String, ExtensionTransformer> = hashMapOf(
CARECONNECT_REPEAT_INFORMATION_URL to ::repeatInformation,
CARECONNECT_GPC_REPEAT_INFORMATION_URL to ::repeatInformation,
Expand All @@ -48,7 +59,9 @@ internal val careconnectTransformers: HashMap<String, ExtensionTransformer> = ha
CARECONNECT_LAST_ISSUE_DATE_URL to ::lastIssueDate,

CARECONNECT_PRESCRIBING_AGENCY_URL to ::prescribingAgency,
CARECONNECT_GPC_PRESCRIBING_AGENCY_URL to ::prescribingAgency
CARECONNECT_GPC_PRESCRIBING_AGENCY_URL to ::prescribingAgency,

CARECONNECT_DESCRIPTION_ID_URL to ::descriptionId,
)

fun repeatInformation(src: R3Extension, tgt: R4Resource) {
Expand Down Expand Up @@ -131,3 +144,29 @@ fun prescribingAgency(src: R3Extension, tgt: R4Resource) {

tgt.addExtension(ext)
}

fun descriptionId(src: R3Extension, tgt: R4Resource) {
val ext = R4Extension().apply {
url = UKCORE_DESCRIPTION_ID_URL

src.getExtensionsByUrl("descriptionId").firstOrNull()?.let {
val descIdExt = R4Extension().apply {
url = "descriptionId"
setValue(R4IdType(it.value.toString()))
}

addExtension(descIdExt)
}

src.getExtensionsByUrl("descriptionDisplay").firstOrNull()?.let {
val descDisplayExt = R4Extension().apply {
url = "descriptionDisplay"
setValue(R4StringType(it.value.toString()))
}

addExtension(descDisplayExt)
}
}

tgt.addExtension(ext)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.nhsd.fhir.converter.transformer

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.hl7.fhir.dstu3.model.Extension as R3Extension
import org.hl7.fhir.dstu3.model.IdType as R3IdType
import org.hl7.fhir.dstu3.model.StringType as R3StringType
import org.hl7.fhir.r4.model.MedicationStatement as R4MedicationStatement

internal class PrescriptionIdTest {
@ParameterizedTest
@ValueSource(strings = [CARECONNECT_DESCRIPTION_ID_URL])
internal fun `it should create extension with the associated ukcore url`(extUrl: String) {
// Given
val r3Extension = R3Extension().apply {
url = extUrl
}

val r4Resource = org.hl7.fhir.r4.model.MedicationStatement()

// When
descriptionId(r3Extension, r4Resource)

// Then
val transformedExt = r4Resource.getExtensionByUrl(UKCORE_DESCRIPTION_ID_URL)
assertThat(transformedExt).isNotNull
}

@ParameterizedTest
@ValueSource(strings = [CARECONNECT_DESCRIPTION_ID_URL])
internal fun `it should carry over the descriptionId extension`(extUrl: String) {
// Given
val descId = 22298006L

val r3Extension = R3Extension().apply {
addExtension(R3Extension("descriptionId", R3IdType(descId)))
}

val r4Resource = R4MedicationStatement()

// When
descriptionId(r3Extension, r4Resource)

// Then
val transformedExt = r4Resource.getExtensionByUrl(UKCORE_DESCRIPTION_ID_URL)

assertThat(transformedExt.extension).hasSize(1)
val idType = transformedExt.extension[0].value
assertThat(idType.toString()).isEqualTo(descId.toString())
}

@ParameterizedTest
@ValueSource(strings = [CARECONNECT_DESCRIPTION_ID_URL])
internal fun `it should carry over the descriptionDisplay extension`(extUrl: String) {
// Given
val descDisplay = "description-display"

val r3Extension = R3Extension().apply {
addExtension(R3Extension("descriptionDisplay", R3StringType(descDisplay)))
}

val r4Resource = R4MedicationStatement()

// When
descriptionId(r3Extension, r4Resource)

// Then
val transformedExt = r4Resource.getExtensionByUrl(UKCORE_DESCRIPTION_ID_URL)

assertThat(transformedExt.extension).hasSize(1)
val actDescDisplay = transformedExt.extension[0].value
assertThat(actDescDisplay.toString()).isEqualTo(descDisplay)
}
}