I'm using the Fhir-dotnet API to interact with our Fhir server to syncronize patient records with our backend patient repository. I have two instances of the Patient resource: one that represents the version in our source repository and one that represents the patient in Fhir. I would like to apply a subset of changes from the source repository version of patient to the Fhir version of the patient and tried to use the CopyTo() method, but this also removes any data that only existed in the Fhir version of patient.
Ideally I only want to only update those properties in the Fhir version of Patient where I have data in the source repository version of Patient (fields that are non-null in the source version of patient) and leave any data that only existed in the Fhir repository. Any data that has been added to the Fhir version of patient as a result of them interacting with the API using their mobile app shoudl be left alone (unless they updated a property that I'm also trying to sync).
Since CopyTo() seems like a complete replacement from one resource to the other (not an additive copy and ignoring fields that are null in the soruce), I need to be able to compare two resources of the same type and get a list of property changes between them. It seems like there are some foundational classes to support this under IsMatch() using IDeepCopy and IDeepComparison and I also noticed on the GitHub notes section that there is support for detecting differences.
Helper classes to work with the specification metadata, most notably StructureDefinition and generation of differentials
So my question is whether or not there are existing classes in the Fhir DOTNET API that can give me a list of changes between two instances of the same resoruce type and if so, what classes would they be with a possible example? If not, then is there an existing pattern that I could use to give me the list of properties that are different between two instances of the same type that could be used to assign values between them. Seems like there would have to be a lot of reflection to generate a list of real properties and not just a list of name value pairs of strings. If there is no support for this in Fhir.NET API, then I would like to write in similar to pseudocode below...
You can use the NamedChildren()
function on any element to get the children by name. With this list, you could use the IsExactly()
method to compare them one by one! Of course, you'd have to deal with FHIR's nested groups (like Patient.contact) which may need different treatment.