Array.push error object is not extensible

#1

Here a surprising behavior of array properties created via make function.

entity type EmrToC3Model schema name 'EoCoMODEL' {
    registerMeasurementSeries: [RegisterMeasurementSeries] schema name 'ETCReMeSe'
}

The following code, executed in the browser crashes:

etc = EmrToC3Model.make()
{serviceAgreements: Array(0), services: Array(0), servicePoints: Array(0), physicalMeasurementSeries: Array(0), measurements: Array(0), …}
rms = RegisterMeasurement.array()
[_type: {…}]
rms.push({start: new DateTime.now(), quantity: {value: 10}})
1
etc.measurements.push(rms)
Uncaught TypeError: Cannot add property 0, object is not extensible
at Array.push (<anonymous>)
at <anonymous>:1:18
(anonymous) @ VM11674:1

why?

I solved it with:

etc.measurements = RegisterMeasurement.array()
[_type: {…}]
etc.measurements.push(rms)
1

but I’ve the filling that I don’t understand ‘make’ function.

0 Likes

#2

It would be better to use foreign keys instead of manually filling your array of series, e.g.

remix type RegisterMeasurementSeries {
  parentETC: EmrToC3Model
}
entity type EmrToC3Model schema name 'EoCoMODEL' {
  registerMeasurementSeries: [RegisterMeasurementSeries](parentETC)
}

With the above example you will have registerMeasurementSeries filled by the system with all RegisterMeasurementSeries that have parentETC with id matching your EmrToC3Model.

0 Likes

#3

In first inspection, it is not possible (or simple) with our design.

In fact, I just develop an API to help me to create data structure corresponding to EMR application with main objective to create easyly a BillingAccount and all other data that EMR needs for testing.

So, I want API that does:
input : EMR data (EmrAccount, EmrService, EmrRegister, …) => EmrToC3Model.generate => efficiency data (BillingAccount, ServiceAgreement, Service, ServicePoint, …)

That will make my testing a lot simpler because EMR data is more simple.

In this structure, EmrToC3Model should be a non persistable type (I made it persistable to solve issue with make method, probably not necessary but no time for that issue).

Your proposition is not possible because in EMR application, RegisterMeasurementSeries has ServicePoint as parent and I can not change this without changing all the code, up to data integration.

And what about this ‘not extensible’ error. Does it mean that AnyType.make() returns a sort of ‘constant’ object. Or is it just for its array properties? Something else?

0 Likes

#4

This is why I called the field parentETC, it will not interfere with your existing code.

0 Likes