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

Start saving local lastUpdated to resources for search operations. #2030

Merged
merged 17 commits into from
Jul 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into ak/localLastUpdated
  • Loading branch information
aditya-07 authored Jul 19, 2023
commit 64a93a9b288afe78fcb1c7dc576f0688878d6278
Original file line number Diff line number Diff line change
Expand Up @@ -111,72 +111,14 @@ internal class ResourceIndexer(
}

companion object {

/**
* Manually add indexes for [SearchParameter]s defined in [Resource] class. This is because:
* 1. There is no clear way defined in the search parameter definitions to figure out the class
* hierarchy of the model classes in codegen.
* 2. Common [SearchParameter]'s paths are defined for [Resource] class e.g even for the
* [Patient] model, the [SearchParameter] expression for id would be `Resource.id` and
* [FHIRPathEngine.evaluate] doesn't return anything when [Patient] is passed to the function.
*/
private fun <R : Resource> addIndexesFromResourceClass(
resource: R,
indexBuilder: ResourceIndices.Builder
) {
indexBuilder.addTokenIndex(
TokenIndex(
"_id",
arrayOf(resource.fhirType(), "id").joinToString(separator = "."),
null,
resource.logicalId
)
)
// Add 'lastUpdated' index to all resources.
if (resource.meta.hasLastUpdated()) {
val lastUpdatedElement = resource.meta.lastUpdatedElement
indexBuilder.addDateTimeIndex(
createLastUpdatedIndex(resource.resourceType, lastUpdatedElement)
)
}

if (resource.meta.hasProfile()) {
resource.meta.profile
.filter { it.value != null && it.value.isNotEmpty() }
.forEach {
indexBuilder.addReferenceIndex(
ReferenceIndex(
"_profile",
arrayOf(resource.fhirType(), "meta", "profile").joinToString(separator = "."),
it.value
)
)
}
}

if (resource.meta.hasTag()) {
resource.meta.tag
.filter { it.code != null && it.code!!.isNotEmpty() }
.forEach {
indexBuilder.addTokenIndex(
TokenIndex(
"_tag",
arrayOf(resource.fhirType(), "meta", "tag").joinToString(separator = "."),
it.system ?: "",
it.code
)
)
}
}
}


private fun numberIndex(searchParam: SearchParamDefinition, value: Base): NumberIndex? =
when (value.fhirType()) {
"integer" ->
NumberIndex(searchParam.name, searchParam.path, BigDecimal((value as IntegerType).value))
"decimal" -> NumberIndex(searchParam.name, searchParam.path, (value as DecimalType).value)
else -> null
}
when (value.fhirType()) {
"integer" ->
NumberIndex(searchParam.name, searchParam.path, BigDecimal((value as IntegerType).value))
"decimal" -> NumberIndex(searchParam.name, searchParam.path, (value as DecimalType).value)
else -> null
}

private fun dateIndex(searchParam: SearchParamDefinition, value: Base): DateIndex {
val date = value as DateType
Expand Down Expand Up @@ -318,24 +260,37 @@ internal class ResourceIndexer(
"code",
"Coding" -> {
val coding = value as ICoding
listOf(TokenIndex(searchParam.name, searchParam.path, coding.system ?: "", coding.code))
if (coding.code != null) {
listOf(TokenIndex(searchParam.name, searchParam.path, coding.system ?: "", coding.code))
} else {
listOf()
}
}
"id" -> {
val id = value as IdType
if (id.value != null) {
listOf(TokenIndex(searchParam.name, searchParam.path, null, id.idPart ?: id.value))
} else {
listOf()
}
}
else -> listOf()
}

private fun referenceIndex(searchParam: SearchParamDefinition, value: Base): ReferenceIndex? {
return when (value) {
is Reference -> value.reference
is CanonicalType -> value.value
is UriType -> value.value
else -> throw UnsupportedOperationException("Value $value is not readable by SDK")
}?.let { ReferenceIndex(searchParam.name, searchParam.path, it) }
return if (!value.isEmpty) {
when (value) {
is Reference -> value.reference
is CanonicalType -> value.value
is UriType -> value.value
else -> throw UnsupportedOperationException("Value $value is not readable by SDK")
}?.let { ReferenceIndex(searchParam.name, searchParam.path, it) }
} else {
null
}
}

private fun quantityIndex(
searchParam: SearchParamDefinition,
value: Base
): List<QuantityIndex> =
private fun quantityIndex(searchParam: SearchParamDefinition, value: Base): List<QuantityIndex> =
when (value.fhirType()) {
"Money" -> {
val money = value as Money
Expand Down Expand Up @@ -365,8 +320,7 @@ internal class ResourceIndexer(
var canonicalValue = quantity.value
if (quantity.system == ucumUrl && quantity.code != null) {
try {
val ucumUnit =
UnitConverter.getCanonicalForm(UcumValue(quantity.code, quantity.value))
val ucumUnit = UnitConverter.getCanonicalForm(UcumValue(quantity.code, quantity.value))
canonicalCode = ucumUnit.code
canonicalValue = ucumUnit.value
} catch (exception: ConverterException) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.