MayJuun / fhir

A Dart/Flutter package for working with FHIR resources.
MIT License
41 stars 29 forks source link

How to change data in complex depth attributes of models? #58

Open jessicamrbr opened 1 year ago

jessicamrbr commented 1 year ago

Considering a case where I have a patient with 3 names, and I want to change the "use" of the second index in the list. Working with copyWith can be tricky.

Looking at examples in other elements where the depth can be even greater, the complexity of manipulating the elements can get worse.

Dokotela commented 1 year ago

Your question is a good one, but unfortunately not one I have a great answer to. Freezed has many benefits, but since it is immutable you do run into these issues. I've considered trying to allow a search/edit function of the fhir_path package, but it would certainly require quite a bit of work.

There are times I've resorted to turning something into the Json map editing that, and then turning it back into the Dart class. It's definitely not the most elegant though.

I'm sorry I don't have a better solution at the moment. I'll leave this open though in case anyone else wants to chime in with suggestions.