Skip to content

Conversation

ellykits
Copy link
Collaborator

@ellykits ellykits commented Aug 6, 2025

Fixes #36

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits ellykits requested a review from jingtang10 August 6, 2025 12:58
Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ellykits!

As discussed earlier today, can you please see if you can write equality tests for all the example resources we have? so load all the example resources, for each resource load twice and check that they are equal.

I'm not sure how to check inequality... seems like we should, but I don't have a good idea how to do that systematically.

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Fixed equality checks for the FhirDate and FhirDateTime classes we
generate by making them data classes.

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits
Copy link
Collaborator Author

@jingtang10 I have implemented the round-trip test for the resource comparison for R4 via this commit message - 0ca74e1c8a (investigating NullPointer exception for R4B and R5), as a placeholder inside the current file SerializationRoundTripTest, to reuse some of the logic we need for running the round-trip tests. We could have it this way and rename the file, or implement this in a separate file and extract the shared code. What do you think?

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits
Copy link
Collaborator Author

@jingtang10 I have implemented the round-trip test for the resource comparison for R4 via this commit message - 0ca74e1c8a (investigating NullPointer exception for R4B and R5), as a placeholder inside the current file SerializationRoundTripTest, to reuse some of the logic we need for running the round-trip tests. We could have it this way and rename the file, or implement this in a separate file and extract the shared code. What do you think?

NullPointerException resolved. I've added the test cases for R4B and R5.

@jingtang10
Copy link
Collaborator

@jingtang10 I have implemented the round-trip test for the resource comparison for R4 via this commit message - 0ca74e1c8a (investigating NullPointer exception for R4B and R5), as a placeholder inside the current file SerializationRoundTripTest, to reuse some of the logic we need for running the round-trip tests. We could have it this way and rename the file, or implement this in a separate file and extract the shared code. What do you think?

I think should be in a separate file - and extract the common utilities.

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits
Copy link
Collaborator Author

@jingtang10 I have implemented the round-trip test for the resource comparison for R4 via this commit message - 0ca74e1c8a (investigating NullPointer exception for R4B and R5), as a placeholder inside the current file SerializationRoundTripTest, to reuse some of the logic we need for running the round-trip tests. We could have it this way and rename the file, or implement this in a separate file and extract the shared code. What do you think?

I think should be in a separate file - and extract the common utilities.

Done!

Renamed EqualityCheckTest to EqualityTest.
Separate exclusion list for the test cases

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@jingtang10
Copy link
Collaborator

Thanks Elly for addressing the comments - the only thing remaining is the SecurityLabel.kt file I think.

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits
Copy link
Collaborator Author

From my investigations:

  • The security labels enum has a similar issue we were facing when generating the enum class from PublicationStatus enum, where two value sets were used with the same common binding name. Refer to the README-> Excluded value sets from enum generation.
  • To resolve the above, we excluded one of the value set URLs that was causing problems, then used one that generated enum constants matching R4 and R4B.
  • The reason why the security label issue could not be reproduced earlier is that there are many instances where the SecurityLabel name is used for these value set URLs: http://hl7.org/fhir/ValueSet/security-labels and http://hl7.org/fhir/ValueSet/security-label-examples. Depending on the order in which they are loaded, the Kotlin Poet library would overwrite the filespec during code generation.
  • The workaround would be to exclude the http://hl7.org/fhir/ValueSet/security-label-examples (it has fewer constants compared to R4 and R4B) and update the documentation in the README to resolve the problem.

Here as the structure definitions that use common binding name "SecurityLabels" with different value sets.

Structure definition AuditEvent specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels
Structure definition Meta specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-labels with binding name SecurityLabels
Structure definition Consent specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels
Structure definition DocumentReference specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@jingtang10
Copy link
Collaborator

From my investigations:

  • The security labels enum has a similar issue we were facing when generating the enum class from PublicationStatus enum, where two value sets were used with the same common binding name. Refer to the README-> Excluded value sets from enum generation.
  • To resolve the above, we excluded one of the value set URLs that was causing problems, then used one that generated enum constants matching R4 and R4B.
  • The reason why the security label issue could not be reproduced earlier is that there are many instances where the SecurityLabel name is used for these value set URLs: http://hl7.org/fhir/ValueSet/security-labels and http://hl7.org/fhir/ValueSet/security-label-examples. Depending on the order in which they are loaded, the Kotlin Poet library would overwrite the filespec during code generation.
  • The workaround would be to exclude the http://hl7.org/fhir/ValueSet/security-label-examples (it has fewer constants compared to R4 and R4B) and update the documentation in the README to resolve the problem.

Here as the structure definitions that use common binding name "SecurityLabels" with different value sets.

Structure definition AuditEvent specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels
Structure definition Meta specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-labels with binding name SecurityLabels
Structure definition Consent specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels
Structure definition DocumentReference specifies ValueSet with url http://hl7.org/fhir/ValueSet/security-label-examples with binding name SecurityLabels

Thanks for the very detailed explanation @ellykits!

Is it possible to change the codegen so that in such cases we throw an exception? Just so that we're not relying on finding such problems by chance.

@jingtang10
Copy link
Collaborator

A couple of additional points: according to this https://chat.fhir.org/#narrow/channel/179166-implementers/topic/Kotlin.20FHIR.20model.20code.20generation.20questions, i wonder if we should use the name of the valueset instead of the binding name extension. @ellykits mentioned there was some issues with that approach for us - please doublecheck and let's document them.

So the approach taken here is that we pick the valueset that is the superset of the other conflicting valuesets, and ignore those valuests... the problem here is that we're actually increasing the number of possible values for fields referring to the smaller valuesets. Another problem is that this is just not a very scalable and robust approach since it requires us inspecting the conflicts. This still might be ok if these are the only cases we're dealing with. (We might find out these aren't after we add the exception in my previous comment).

An alternative approach is to generate local enums for conflicts. So if two bindings are conflicting. We simply avoid generating global enums. I'm not saying we should definitely do it, let's do the investigation above - and have this approach in our back pocket.

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving - but pls merge only after #44 is merged this is updated (and verify that the changes in SecurityLabels.kt are reverted).

ellykits and others added 3 commits August 21, 2025 17:50
Co-authored-by: Jing Tang <jingtang@google.com>
Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
@ellykits ellykits merged commit ae9db21 into google:main Aug 21, 2025
1 of 5 checks passed
@ellykits ellykits deleted the fix-equality-strings branch August 21, 2025 16:11
Comment on lines +138 to +140
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought i commented on this :/ let's remove this in a subsequent PR (probably no need to send a 1 line change)

@ellykits
Copy link
Collaborator Author

ellykits commented Aug 21, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Equality for non-data classes
3 participants