diff --git a/sm-gen/build.gradle.kts b/sm-gen/build.gradle.kts index dc3a327..284ed68 100644 --- a/sm-gen/build.gradle.kts +++ b/sm-gen/build.gradle.kts @@ -11,18 +11,23 @@ group = "org.example" version = "1.0-SNAPSHOT" repositories { - mavenCentral() - gradlePluginPortal() + google() + mavenCentral() + mavenLocal() } dependencies { - testImplementation(kotlin("test")) - implementation("com.github.ajalt.clikt:clikt:3.4.0") - implementation("org.apache.poi:poi:3.17") - implementation("org.apache.poi:poi-ooxml:3.17") - implementation("ca.uhn.hapi.fhir:hapi-fhir-structures-r4:5.4.0") - implementation("ca.uhn.hapi.fhir:hapi-fhir-validation:5.4.0") - implementation(kotlin("stdlib-jdk8")) + + implementation("com.github.ajalt.clikt:clikt:3.4.0") + implementation("org.apache.poi:poi:3.17") + implementation("org.apache.poi:poi-ooxml:3.17") + implementation("ca.uhn.hapi.fhir:hapi-fhir-structures-r4:5.4.0") + implementation("ca.uhn.hapi.fhir:hapi-fhir-validation:5.4.0") + implementation(kotlin("stdlib-jdk8")) + testImplementation(kotlin("test")) + testImplementation("io.mockk:mockk:1.13.7") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0") } tasks.test { useJUnitPlatform() } diff --git a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/TransformSupportServices.kt b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/TransformSupportServices.kt index e638a22..36403e0 100644 --- a/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/TransformSupportServices.kt +++ b/sm-gen/src/main/kotlin/org.smartregister.fhir.structuremaptool/TransformSupportServices.kt @@ -27,25 +27,25 @@ class TransformSupportServices constructor(val simpleWorkerContext: SimpleWorker println(message) } - @Throws(FHIRException::class) - override fun createType(appInfo: Any, name: String): Base { - return when (name) { - "RiskAssessment_Prediction" -> RiskAssessmentPredictionComponent() - "RiskAssessment\$RiskAssessmentPredictionComponent" -> RiskAssessmentPredictionComponent() - "Immunization_VaccinationProtocol" -> Immunization.ImmunizationProtocolAppliedComponent() - "Immunization_Reaction" -> Immunization.ImmunizationReactionComponent() - "EpisodeOfCare_Diagnosis" -> EpisodeOfCare.DiagnosisComponent() - "Encounter_Diagnosis" -> Encounter.DiagnosisComponent() - "Encounter_Participant" -> Encounter.EncounterParticipantComponent() - "CarePlan_Activity" -> CarePlan.CarePlanActivityComponent() - "CarePlan_ActivityDetail" -> CarePlan.CarePlanActivityDetailComponent() - "Patient_Link" -> Patient.PatientLinkComponent() - "Timing_Repeat" -> Timing.TimingRepeatComponent() - "PlanDefinition_Action" -> PlanDefinition.PlanDefinitionActionComponent() - "Group_Characteristic" -> Group.GroupCharacteristicComponent() - "Observation_Component" -> Observation.ObservationComponentComponent() - else -> ResourceFactory.createResourceOrType(name) - } + @Throws(FHIRException::class) + override fun createType(appInfo: Any, name: String): Base { + return when (name) { + "RiskAssessment_Prediction" -> RiskAssessmentPredictionComponent() + "RiskAssessment\$RiskAssessmentPredictionComponent" -> RiskAssessmentPredictionComponent() + "Immunization_AppliedProtocol" -> Immunization.ImmunizationProtocolAppliedComponent() + "Immunization_Reaction" -> Immunization.ImmunizationReactionComponent() + "EpisodeOfCare_Diagnosis" -> EpisodeOfCare.DiagnosisComponent() + "Encounter_Diagnosis" -> Encounter.DiagnosisComponent() + "Encounter_Participant" -> Encounter.EncounterParticipantComponent() + "CarePlan_Activity" -> CarePlan.CarePlanActivityComponent() + "CarePlan_ActivityDetail" -> CarePlan.CarePlanActivityDetailComponent() + "Patient_Link" -> Patient.PatientLinkComponent() + "Timing_Repeat" -> Timing.TimingRepeatComponent() + "PlanDefinition_Action" -> PlanDefinition.PlanDefinitionActionComponent() + "Group_Characteristic" -> Group.GroupCharacteristicComponent() + "Observation_Component" -> Observation.ObservationComponentComponent() + else -> ResourceFactory.createResourceOrType(name) + } } override fun createResource(appInfo: Any, res: Base, atRootofTransform: Boolean): Base { 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 new file mode 100644 index 0000000..6d4f460 --- /dev/null +++ b/sm-gen/src/test/kotlin/org/smartregister/fhir/structuremaptool/TransformSupportServicesTest.kt @@ -0,0 +1,137 @@ +package org.smartregister.fhir.structuremaptool + +import io.mockk.mockk +import org.hl7.fhir.exceptions.FHIRException +import org.hl7.fhir.r4.model.CarePlan +import org.hl7.fhir.r4.model.Encounter +import org.hl7.fhir.r4.model.EpisodeOfCare +import org.hl7.fhir.r4.model.Immunization +import org.hl7.fhir.r4.model.Observation +import org.hl7.fhir.r4.model.Patient +import org.hl7.fhir.r4.model.RiskAssessment +import org.hl7.fhir.r4.model.TimeType +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.BeforeEach +import kotlin.test.Test + +class TransformSupportServicesTest{ + lateinit var transformSupportServices: TransformSupportServices + + @BeforeEach + fun setUp() { + transformSupportServices = TransformSupportServices(mockk()) + } + + + @Test + fun `createType() should return RiskAssessmentPrediction when given RiskAssessment_Prediction`() { + assertTrue( + transformSupportServices.createType("", "RiskAssessment_Prediction") + is RiskAssessment.RiskAssessmentPredictionComponent, + ) + } + + @Test + fun `createType() should return ImmunizationProtocol when given Immunization_VaccinationProtocol`() { + assertTrue( + transformSupportServices.createType("", "Immunization_AppliedProtocol") + is Immunization.ImmunizationProtocolAppliedComponent, + ) + } + + @Test + fun `createType() should return ImmunizationReaction when given Immunization_Reaction`() { + assertTrue( + transformSupportServices.createType("", "Immunization_Reaction") + is Immunization.ImmunizationReactionComponent, + ) + } + + @Test + fun `createType() should return Diagnosis when given EpisodeOfCare_Diagnosis`() { + assertTrue( + transformSupportServices.createType("", "EpisodeOfCare_Diagnosis") + is EpisodeOfCare.DiagnosisComponent, + ) + } + + @Test + fun `createType() should return Diagnosis when given Encounter_Diagnosis`() { + assertTrue( + transformSupportServices.createType("", "Encounter_Diagnosis") + is Encounter.DiagnosisComponent, + ) + } + + @Test + fun `createType() should return EncounterParticipant when given Encounter_Participant`() { + assertTrue( + transformSupportServices.createType("", "Encounter_Participant") + is Encounter.EncounterParticipantComponent, + ) + } + + @Test + fun `createType() should return CarePlanActivity when given CarePlan_Activity`() { + assertTrue( + transformSupportServices.createType("", "CarePlan_Activity") + is CarePlan.CarePlanActivityComponent, + ) + } + + @Test + fun `createType() should return CarePlanActivityDetail when given CarePlan_ActivityDetail`() { + assertTrue( + transformSupportServices.createType("", "CarePlan_ActivityDetail") + is CarePlan.CarePlanActivityDetailComponent, + ) + } + + @Test + fun `createType() should return PatientLink when given Patient_Link`() { + assertTrue( + transformSupportServices.createType("", "Patient_Link") is Patient.PatientLinkComponent, + ) + } + + @Test + fun `createType() should return ObservationComponentComponent when given Observation_Component`() { + assertTrue( + transformSupportServices.createType("", "Observation_Component") + is Observation.ObservationComponentComponent, + ) + } + + @Test + fun `createType() should return Time when given time`() { + assertTrue(transformSupportServices.createType("", "time") is TimeType) + } + + @Test + fun `createResource() should add resource into output when given Patient and atRootOfTransForm as True`() { + assertEquals(transformSupportServices.outputs.size, 0) + transformSupportServices.createResource("", Patient(), true) + assertEquals(transformSupportServices.outputs.size, 1) + } + + @Test + fun `createResource() should not add resource into output when given Patient and atRootOfTransForm as False`() { + assertEquals(transformSupportServices.outputs.size, 0) + transformSupportServices.createResource("", Patient(), false) + assertEquals(transformSupportServices.outputs.size, 0) + } + + @Test + fun `resolveReference should throw FHIRException when given url`() { + assertThrows(FHIRException::class.java) { + transformSupportServices.resolveReference("", "https://url.com") + } + } + + @Test + fun `performSearch() should throw FHIRException this is not supported yet when given url`() { + assertThrows(FHIRException::class.java) { + transformSupportServices.performSearch("", "https://url.com") + } + } +} \ No newline at end of file