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

Bug on handling conversion from a choice type #570

Open
baseTwo opened this issue Sep 24, 2024 · 2 comments
Open

Bug on handling conversion from a choice type #570

baseTwo opened this issue Sep 24, 2024 · 2 comments
Assignees
Labels

Comments

@baseTwo
Copy link
Collaborator

baseTwo commented Sep 24, 2024

Also follow discussion on cql choice types #604

The following cql results in the following c#:

define "Initial Population":
  (AgeInYearsAt(start of "Measurement Period") >= 16) and exists("Injury due to falling rock within measurement period")
	private IEnumerable<Condition> Injury_due_to_falling_rock_within_measurement_period_Value()
	{
		CqlValueSet a_ = this.Injury_due_to_falling_rock();
		IEnumerable<Condition> b_ = context.Operators.RetrieveByValueSet<Condition>(a_, default);
		bool? c_(Condition C)
		{
			DataType e_ = C?.Onset;
			object f_ = context.Operators.LateBoundProperty<object>(e_, "value"); // REF#1
			CqlInterval<CqlDateTime> g_ = this.Measurement_Period();
			bool? h_ = context.Operators.In<CqlDateTime>(f_ as CqlDateTime /* REF#2 */, g_, default);

			return h_;
		};
		IEnumerable<Condition> d_ = context.Operators.Where<Condition>(b_, c_);
		return d_;
	}

The latebound property returns a choice type (REF#1). At this stage we do not have a C# equivalent type for this, so object is used. Unfortunately this can easily allow one to make assumptions when casting, such as at REF#2, where a safe cast is made to CqlDateTime. At runtime, the actual type was a string, so this did not work.

Instead, when choice types are to be converted, the runtime ICqlOperators.Convert<T>(object) must be invoked.

@EvanMachusak
Copy link
Collaborator

EvanMachusak commented Sep 26, 2024

The CQL in the issue doesn't match the generated C#. What is the CQL for "Injury due to falling rock within measurement period"?

I don't believe the proposed fix is correct.

Specifically:

At runtime, the actual type was a string, so this did not work.

Things are allowed to not work if the runtime type is not correct. I do not think invoking any kind of conversion is correct in this case.

My memory is hazy but I do notice that value is the property being accessed. There is a lot of weirdness with value property accessors on FHIR types that created issues like these in the past. I think we had some code in 1.0 to ignore accesses to value properties in some cases because it causes type confusion.

In the Firely model, what does Condition.Onset.value return? Is it a string? What is Condition.Onset? Is it a FHIR dateTime? Why isn't FHIRHelpers.ToDateTime being invoked so that In can be called?

There are a lot of questions here.

@alexzautke
Copy link
Member

RR23_LIB_Umbrella_Measure.json

Here’s the library that we used for testing

@baseTwo baseTwo removed the bug Something isn't working label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants