Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsupported datatypes #280

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ fun main(args: Array<String>) {
Application().main(args)
}

/*fun main(args: Array<String>) {
val values = hashMapOf(Pair("username", "Bilira"), Pair("client_id", "uBr6UUy5VprEcvCnWndSWcALKivttaqk25"))
val digest = MessageDigest.getInstance("MD5")
val bytes = digest.digest(values.toString().toByteArray(charset("UTF-8")))
val answ = String.format("%032x", BigInteger(1, bytes))
System.out.println(answ)

}*/

/*

REMAINING TASKS
Expand All @@ -48,7 +39,7 @@ REMAINING TASKS
class Application : CliktCommand() {
val xlsfile: String by option(help = "XLS filepath").prompt("Kindly enter the XLS filepath")
val questionnairefile: String by
option(help = "Questionnaire filepath").prompt("Kindly enter the questionnaire filepath")
option(help = "Questionnaire filepath").prompt("Kindly enter the questionnaire filepath")

override fun run() {
// Create a map of Resource -> questionnaire name or path -> value
Expand Down Expand Up @@ -155,13 +146,6 @@ class Application : CliktCommand() {
.add(instruction)
}
}
// val resource = ?: Class.forName("org.hl7.fhir.r4.model.$resourceName").newInstance() as
// Resource

// Perform the extraction for the row
/*generateStructureMapLine(structureMapBody, row, resource, extractionResources)

extractionResources[resourceName + resourceIndex] = resource*/

sb.append(structureMapHeader)
sb.appendNewLine().appendNewLine().appendNewLine()
Expand Down Expand Up @@ -339,4 +323,4 @@ fun writeStructureMapOutput(structureMap: String) {
FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().setPrettyPrint(true)
val mapString = iParser.encodeResourceToString(map)
File("generated-json-map.json").writeText(mapString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,21 @@ class Group(
if (answerExpression != null) {
if (
answerExpression.isNotEmpty() &&
answerExpression.isNotBlank() &&
answerExpression != "''"
answerExpression.isNotBlank() &&
answerExpression != "''"
) {
val propertyType = inferType(instruction!!.fullPropertyPath())
val answerType = answerExpression.getAnswerType(questionnaireResponse)

if (
propertyType != "Type" &&
answerType != propertyType &&
propertyType
?.canHandleConversion(
answerType ?: "",
)
?.not() == true &&
answerExpression.startsWith("evaluate")
answerType != propertyType &&
propertyType
?.canHandleConversion(
answerType ?: "",
)
?.not() == true &&
answerExpression.startsWith("evaluate")
) {
println(
"Failed type matching --> ${instruction!!.fullPropertyPath()} of type $answerType != $propertyType"
Expand Down Expand Up @@ -435,7 +435,7 @@ private fun String.getType(questionnaireResponse: QuestionnaireResponse): String
internal val fhirPathEngine: FHIRPathEngine =
with(FhirContext.forCached(FhirVersionEnum.R4)) {
FHIRPathEngine(HapiWorkerContext(this, this.validationSupport)).apply {
hostServices = FHIRPathEngineHostServices
hostServices = FhirPathEngineHostServices
}
}

Expand Down Expand Up @@ -543,4 +543,4 @@ fun String.getResourceProperty(): String? {
return substring(lastIndexOf('.') + 1)
}

fun String.getFhirType(): String = replace("Type", "").lowercase()
fun String.getFhirType(): String = replace("Type", "").lowercase()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.smartregister.fhir.structuremaptool

import io.mockk.mockk
import org.hl7.fhir.r4.context.SimpleWorkerContext
import org.hl7.fhir.exceptions.FHIRException
import org.hl7.fhir.r4.model.CarePlan
import org.hl7.fhir.r4.model.Encounter
Expand All @@ -15,11 +15,13 @@ import org.junit.jupiter.api.BeforeEach
import kotlin.test.Test

class TransformSupportServicesTest{
lateinit var transformSupportServices: TransformSupportServices
private lateinit var transformSupportServices: TransformSupportServices

@BeforeEach
fun setUp() {
transformSupportServices = TransformSupportServices(mockk())
val simpleWorkerContext = SimpleWorkerContext()

transformSupportServices = TransformSupportServices(simpleWorkerContext)
}


Expand Down
96 changes: 96 additions & 0 deletions sm-gen/src/test/kotlin/utils/DetermineFhirDataTypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package utils

import org.junit.jupiter.api.Assertions.assertEquals
import org.smartregister.fhir.structuremaptool.determineFhirDataType
import kotlin.test.Test

class DetermineFhirDataTypeTest {

@Test
fun testDetermineFhirDataType() {
// Test Null or Empty Input
assertEquals("Invalid Input: Null or Empty String", determineFhirDataType(null.toString()))
assertEquals("Invalid Input: Null or Empty String", determineFhirDataType(""))

// Test Boolean
assertEquals("Boolean", determineFhirDataType("true"))
assertEquals("Boolean", determineFhirDataType("false"))

// Test Integer
assertEquals("Integer", determineFhirDataType("123"))
assertEquals("Integer", determineFhirDataType("-456"))

// Test Decimal
assertEquals("Decimal", determineFhirDataType("123.456"))
assertEquals("Decimal", determineFhirDataType("-0.789"))

// Test Date
assertEquals("Date", determineFhirDataType("2023-08-23"))

// Test DateTime
assertEquals("DateTime", determineFhirDataType("2023-08-23T14:30:00+01:00"))

// Test Instant
assertEquals("Instant", determineFhirDataType("2023-08-23T14:30:00.123Z"))

// Test Quantity
assertEquals("Quantity", determineFhirDataType("70 kg"))

// Test Coding
assertEquals("Coding", determineFhirDataType("12345|"))

// Test Reference
assertEquals("Reference", determineFhirDataType("Patient/123"))

// Test Period
assertEquals("Period", determineFhirDataType("2023-01-01/2023-12-31"))

// Test Range
assertEquals("Range", determineFhirDataType("10-20"))

// Test Annotation
assertEquals("Annotation", determineFhirDataType("Note: Patient is recovering well"))

// Test Attachment

// Test Base64Binary
assertEquals("Base64Binary", determineFhirDataType("QmFzZTY0QmluYXJ5"))

// Test ContactPoint
assertEquals("ContactPoint", determineFhirDataType("+123456789"))

// Test HumanName
assertEquals("HumanName", determineFhirDataType("John Doe"))

// Test Address
assertEquals("Address", determineFhirDataType("123 Main Street"))

// Test Duration
assertEquals("Duration", determineFhirDataType("1 hour"))

// Test Money
assertEquals("Money", determineFhirDataType("100.00 USD"))

// Test Ratio
assertEquals("Ratio", determineFhirDataType("1:1000"))

// Test Signature
// Test Identifier
assertEquals("Identifier", determineFhirDataType("AB123-45"))

// Test Uri
assertEquals("Uri", determineFhirDataType("https://example.com"))

// Test Uuid
assertEquals("Uuid", determineFhirDataType("123e4567-e89b-12d3-a456-426614174000"))

// Test Narrative
assertEquals(
"Narrative",
determineFhirDataType("<div xmlns=\"http://www.w3.org/1999/xhtml\">Patient narrative</div>")
)

// Test String as Default Case
assertEquals("String", determineFhirDataType("Unmatched string"))
}
}