Skip to content

Commit

Permalink
Handle insurance plan in indexing code (#924)
Browse files Browse the repository at this point in the history
* Handle insurance plan in indexing code
  • Loading branch information
epicadk committed Nov 23, 2021
1 parent 817a561 commit 6084de7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/SpotlessConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun Project.configureSpotless() {
}
// Creates one off SpotlessApply task for generated files
com.diffplug.gradle.spotless.KotlinExtension(this).apply {
target("**/*Generated.kt")
target("**/*_Generated.kt")
ktlint(ktlintVersion).userData(ktlintOptions)
ktfmt().googleStyle()
licenseHeaderFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ object SearchParameterRepositoryGenerator {

private const val indexPackage = "com.google.android.fhir.index"
private const val hapiPackage = "org.hl7.fhir.r4.model"
private const val generatedClassName = "SearchParameterRepositoryGenerated"
private const val generatedClassName = "SearchParameterRepository_Generated"
private const val indexTestPackage = "com.google.android.fhir.index"
private const val generatedTestHelperClassName = "SearchParameterRepositoryGeneratedTestHelper"
private const val generatedTestHelperClassName = "SearchParameterRepositoryTestHelper_Generated"
private const val generatedComment =
"This File is Generated from com.google.android.fhir.codegen.SearchParameterRepositoryGenerator all changes to this file must be made through the aforementioned file only"

Expand All @@ -63,7 +63,7 @@ object SearchParameterRepositoryGenerator {
val searchParameter = entry.resource as SearchParameter
if (searchParameter.expression.isNullOrEmpty()) continue

for (path in getResourceToPathMap(searchParameter.expression)) {
for (path in getResourceToPathMap(searchParameter)) {
val hashMapKey = path.key
if (!searchParamMap.containsKey(hashMapKey)) {
searchParamMap[hashMapKey] = CodeBlock.builder().add("%S -> listOf(", hashMapKey)
Expand Down Expand Up @@ -100,14 +100,12 @@ object SearchParameterRepositoryGenerator {
try {
Class.forName(resourceClass.reflectionName())
} catch (e: ClassNotFoundException) {
// TODO handle alias and name (InsurancePlan)
// https://github.com/google/android-fhir/issues/921
println("Class not found $resource ")
continue
}
function.addCode(searchParamMap[resource]!!.add(")\n").build())

if (resource != "Resource" && resource != "InsurancePlan") {
if (resource != "Resource") {
testHelperFunctionCodeBlock.add("%T(),\n", resourceClass)
}
}
Expand All @@ -131,21 +129,28 @@ object SearchParameterRepositoryGenerator {
}

/**
* @return the resource names mapped to their respective paths in the expression.
* @return the resource names mapped to their respective paths in the expression of [searchParam]
*
* @param expression an expression that contains the paths of a given search param
* @param searchParam the search parameter that needs to be mapped
*
* This is necessary because the path expressions are not necessarily grouped by resource type
*
* For example an expression of "AllergyIntolerance.code | AllergyIntolerance.reaction.substance |
* Condition.code" will return "AllergyIntolerance" -> "AllergyIntolerance.code |
* AllergyIntolerance.reaction.substance" , "Condition" -> "Condition.code"
*/
private fun getResourceToPathMap(expression: String): Map<String, String> {
return expression
.split("|")
.groupBy { splitString -> splitString.split(".").first().trim().removePrefix("(") }
.mapValues { it.value.joinToString(" | ") { join -> join.trim() } }
private fun getResourceToPathMap(searchParam: SearchParameter): Map<String, String> {
// the if block is added because of the issue https://jira.hl7.org/browse/FHIR-22724 and can be
// removed once the issue is resolved
return if (searchParam.base.size == 1) {
mapOf(searchParam.base.single().valueAsString to searchParam.expression)
} else {
searchParam
.expression
.split("|")
.groupBy { splitString -> splitString.split(".").first().trim().removePrefix("(") }
.mapValues { it.value.joinToString(" | ") { join -> join.trim() } }
}
}

private fun String.toHapiName() = if (this == "List") "ListResource" else this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,7 @@ internal fun getSearchParamList(resource: Resource): List<SearchParamDefinition>
Enumerations.SearchParamType.TOKEN,
"InsurancePlan.identifier"
),
SearchParamDefinition("name", Enumerations.SearchParamType.STRING, "name | alias"),
SearchParamDefinition(
"owned-by",
Enumerations.SearchParamType.REFERENCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import org.hl7.fhir.r4.model.Immunization
import org.hl7.fhir.r4.model.ImmunizationEvaluation
import org.hl7.fhir.r4.model.ImmunizationRecommendation
import org.hl7.fhir.r4.model.ImplementationGuide
import org.hl7.fhir.r4.model.InsurancePlan
import org.hl7.fhir.r4.model.Invoice
import org.hl7.fhir.r4.model.Library
import org.hl7.fhir.r4.model.Linkage
Expand Down Expand Up @@ -205,6 +206,7 @@ internal fun getAllResources(): List<Resource> {
SearchParameter(),
ActivityDefinition(),
Communication(),
InsurancePlan(),
Linkage(),
ImmunizationEvaluation(),
DeviceUseStatement(),
Expand Down

0 comments on commit 6084de7

Please sign in to comment.