Skip to content

Commit

Permalink
Merge branch 'main' into 199-validate-sm
Browse files Browse the repository at this point in the history
  • Loading branch information
sharon2719 authored Sep 13, 2024
2 parents 36a2a15 + 8bc646e commit 5aa2009
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 28 deletions.
23 changes: 14 additions & 9 deletions sm-gen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
}

0 comments on commit 5aa2009

Please sign in to comment.