diff --git a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Main.kt b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Main.kt index 00e7f13..fd244ae 100644 --- a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Main.kt +++ b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Main.kt @@ -27,15 +27,6 @@ fun main(args: Array) { Application().main(args) } -/*fun main(args: Array) { - 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 @@ -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 @@ -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() @@ -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) -} +} \ No newline at end of file diff --git a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Utils.kt b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Utils.kt index 843944d..8c018da 100644 --- a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Utils.kt +++ b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/Utils.kt @@ -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" @@ -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 } } @@ -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() \ No newline at end of file diff --git a/sm-gen/src/test/kotlin/org/smartregister/fhir/structuremaptool/TransformSupportServicesTest.kt b/sm-gen/src/test/kotlin/org/smartregister/fhir/structuremaptool/TransformSupportServicesTest.kt index 6d4f460..5f066cc 100644 --- a/sm-gen/src/test/kotlin/org/smartregister/fhir/structuremaptool/TransformSupportServicesTest.kt +++ b/sm-gen/src/test/kotlin/org/smartregister/fhir/structuremaptool/TransformSupportServicesTest.kt @@ -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 @@ -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) } diff --git a/sm-gen/src/test/kotlin/utils/DetermineFhirDataTypeTest.kt b/sm-gen/src/test/kotlin/utils/DetermineFhirDataTypeTest.kt new file mode 100644 index 0000000..58c8738 --- /dev/null +++ b/sm-gen/src/test/kotlin/utils/DetermineFhirDataTypeTest.kt @@ -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("
Patient narrative
") + ) + + // Test String as Default Case + assertEquals("String", determineFhirDataType("Unmatched string")) + } +} \ No newline at end of file