spark
spark copied to clipboard
Fahrenheit cannot be converted to base units
Describe the bug When using Fahrenheit as a unit for a value, Spark cannot convert the value to its corresponding base unit.
To Reproduce Linked to this issue are FHIR bundles, generated by Synthea, that set up hospital and practitioner resources, to then insert a patient with an observation resource that has a value attached to it. So:
- Run Spark FHIR server on the latest version (1.5.13-r4)
- POST the hospital bundle, then the practitioner bundle
- POST the patient bundle
The server will then respond with a 500 and the following message:
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"diagnostics": "InvalidCastException: Quantity could not be converted to base units"
}
]
}
Expected behavior The server should be able to process Fahrenheit.
Spark version
- Version: 1.5.13-r4
Operating system + Database
- OS: Arch Linux with LTS Kernel 5.15.60-1
Container service / Cloud infrastructure:
- Container service:
sparkfhir/spark:v1.5.13-r4 - Database container service:
sparkfhir/mongo:v1.5.13-r4
This is the Compose file that I use:
version: "3.9"
services:
spark:
image: sparkfhir/spark:v1.5.13-r4
environment:
- StoreSettings__ConnectionString=mongodb://root:CosmicTopSecret@mongo:27017/spark?authSource=admin
- SparkSettings__Endpoint=http://localhost:8080/fhir
ports:
- "8080:80"
mongo:
image: sparkfhir/mongo:v1.5.13-r4
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=CosmicTopSecret
volumes:
- mongo-data:/data/db
volumes:
mongo-data:
Additional context This is an issue that I haven't encountered with other open-source FHIR servers. Therefore I think this is worth looking into to get consistent results across implementations.
It's also worth noting that changing the value to an integer (e.g. 102) changes nothing about this behavior. Changing the unit to Celsius, so setting both unit and code in the valueQuantity object to [degC], works. So this is an issue that, by my little bits of research, only affects Fahrenheit.
I found a simple workaround for the time being by editing QuantityExtensions as such:
public static Quantity Canonical(this Quantity input)
{
return input.Metric.Symbols switch
{
// TODO: Conversion of Celsius to its base unit Kelvin fails using the method SystemOfUnits::Canoncial
// Waiting for feedback on issue: https://github.com/FirelyTeam/Fhir.Metrics/issues/7
"Cel" => new Quantity(input.Value + 273.15m, System.Metric("K")),
"[degF]" => new Quantity((input.Value - 32)/1.8m + 273.15m, System.Metric("K")),
_ => System.Canonical(input),
};
}
If you can it would be nice if you want to give us a PR for the fix :)