dcarbone / php-fhir

Tools for consuming data from a FHIR server with PHP
Apache License 2.0
126 stars 40 forks source link

Option to set or clear an array field #134

Closed Aravind-MJ closed 1 month ago

Aravind-MJ commented 1 month ago

Let's take questionnaire as an example. There is items which is an array and there's enableWhen, which is also an array, for each of those items. There are only 2 ways to manipulate these fields, get (getItem()/getEnableWhen()) or add (addItem()/addEnableBehaviour()). This is fine except for when we want to update something.

How I handle update is first fetching all data into an array and find the corresponding entry from it (Either by id or index) and then updating it. It's a lot of work but it works fine for most cases. When it comes to Questionnaire, this approach faced an issue. In Questionnaire we have to keep the questions in order that they will be attended in. So when we add a question in between, replacing data at the index of item works fine but then I have no way to clear the applied enableWhen condition at that index. There is no option to insert at index either. It would be super helpful if there is also a function that can clear, set or insert on that field directly.

For now I know I can re build the JSON structure for that resource and clear it like that but then what's the point of using the classes 😄

dcarbone commented 1 month ago

Ah! I could have sworn I had this at one point! Thank you for the PR, I will review ASAP!

Aravind-MJ commented 1 month ago

@dcarbone you do, but only for contained field. Which is common for all domain resources.

dcarbone commented 1 month ago

@Aravind-MJ: I've released v3.1.0, please let me know if this fits your need!

Aravind-MJ commented 1 month ago

@dcarbone Yes it does. Thanks!