ehn-dcc-development / eu-dcc-schema

Schema for the ehn DCC payload
Apache License 2.0
164 stars 59 forks source link

Use arrays over collection of objects #97

Closed skounis closed 3 years ago

skounis commented 3 years ago

Hi, is there any particular reason in our dataset we use collection of objects over an array of them?

"valueSetValues": {    
  "1232": {     
   "display": "Abbott Rapid Diagnostics, Panbio COVID-19 Ag Test",      
   "lang": "en",    
    }
...
}

Instead of

"valueSetValues": [    
   {
   "id": "1232",     
   "display": "Abbott Rapid Diagnostics, Panbio COVID-19 Ag Test",      
   "lang": "en",    
   }
...
]

https://github.com/ehn-dcc-development/ehn-dcc-schema/blob/main/valuesets/test-manf.json#L5

gabywh commented 3 years ago

None otther than that is how the Sematic SG script generates them. Could be changed. What would be the reason to change it to array, from your perspective?

skounis commented 3 years ago

map, reduce, filter and plenty of methods like these are availabe on or apply to map.

In similar situations, like the one we have, I always find my self start with:

var result = Object.keys(obj).map((key) => [Number(key), obj[key]]);

I expect these data to populate lists and select controls where arrays work a bit better.

gabywh commented 3 years ago

JS-specific: not neccessarily an Array, but one of the JS built-in iterables (String, Array,TypedArray, Map, Set) or more generically something that implements the iterator protocol -> but I agree I would keep to the built-in iterables here rather than also define a custom implementation of the iterator protocol, which I find to be a very over-engineered solution for this case.

Other language bindings (e.g. Python) will directly give you an iterable by loading the JSON as-is (collection of objects) and you can use e.g. map, reduce, filter style operations, so the issue is simply not present in at least some other languages. So this is really a language binding issue - all the same, a practical consideration which would make life easier for implementers using JS directly, so is worth looking into just for that.

If we change these generated valuesets to e.g. Array ( [] ), then it means we have a back-compatibility issue in that at least JS client code will have to be modified (at least, JS code) to work with either the collection of objects (as it is now) or the (admittedly far easier and more comfortable) built-in iterable type of e.g. Array.

Thoughts?

skounis commented 3 years ago

If we change these generated valuesets to e.g. Array ( [] ), then it means we have a back-compatibility issue

This already ansers it.

I do not see the need for further action.