Skip to main content

Using the SDK with Redux

The data models generated by the SDK are not serialisable. This means that they cannot be used as is with Redux.

Support for marshalling/unmarshalling of medical device SDK models to and from JS pojos

Some JS frameworks (like Redux) expect the models to be serialisable.

Our models use Set and Classes which are not serialisable.

The SDK provides a marshal method on each model to convert them to plain JS objects. This method is recursive and will convert all the models in the hierarchy to plain JS objects.

The constructor of the Model Classes now converts back those pojos to the full class Hierarchy.

const user = await api.userApi.getLogged()
const marshalledUser = User.toJSON(user)
const unmarshalledUser = User.fromJSON(marshalledUser)
user
{
"id": "17e392da-8e36-4e4e-abd7-7eef3e434395",
"rev": "2-f648b39ce5e04f1ee8e84c0e7ad77f2f",
"created": 1700058590776,
"name": "Master HCP",
"properties": {},
"roles": {},
"login": "master@3ed064.icure",
"groupId": "test-group",
"healthcarePartyId": "3ed06450-17e5-47b6-ba4f-7a0a084df56b",
"sharingDataWith": {},
"email": "master@3ed064.icure",
"authenticationTokens": {}
}
marshalledUser
{
"id": "17e392da-8e36-4e4e-abd7-7eef3e434395",
"rev": "2-f648b39ce5e04f1ee8e84c0e7ad77f2f",
"created": 1700058590776,
"name": "Master HCP",
"properties": [],
"roles": [],
"login": "master@3ed064.icure",
"groupId": "test-group",
"healthcarePartyId": "3ed06450-17e5-47b6-ba4f-7a0a084df56b",
"sharingDataWith": {},
"email": "master@3ed064.icure",
"authenticationTokens": {
"b70a9040-8f0f-4d90-af70-f3fd3473665f": {
"creationTime": 1700058590891,
"validity": 86400
}
}
}
unmarshalledUser
{
"id": "17e392da-8e36-4e4e-abd7-7eef3e434395",
"rev": "2-f648b39ce5e04f1ee8e84c0e7ad77f2f",
"created": 1700058590776,
"name": "Master HCP",
"properties": {},
"roles": {},
"login": "master@3ed064.icure",
"groupId": "test-group",
"healthcarePartyId": "3ed06450-17e5-47b6-ba4f-7a0a084df56b",
"sharingDataWith": {},
"email": "master@3ed064.icure",
"authenticationTokens": {}
}