Skip to main content

Sharing data automatically with other data owners

iCure allows to share data between different data owners, as explained in the guide How to share data between data owners, however this requires to perform an explicit request every time we want to share a new entity.

In some cases you may need to always share all data created by a data owner with other data-owners, for example you may want to always share all data created by a patient with their general practitioner. In these situations it may be more convenient to use the automatic-sharing feature of iCure.

note

In the following examples we use different instances of MedTechApis, to perform the requests as different users. The api we use are hcp1Api and hcp2Api to act as two different healthcare practitioners data owners (hcp1 and hcp2, respectively) and pApi to act as a patient data owner (p).

Start sharing data with another user

You can use the shareAllFutureDataWith method from the userApi to start sharing all new data the user creates with another user. The following example shows how to automatically share all new entities which will be created by hcp1 with hcp2.

await hcp1Api.userApi.shareAllFutureDataWith('medicalInformation', [
hcp1Api.dataOwnerApi.getDataOwnerIdOf(hcp2User),
])
Data creation example
const note = 'Winter is coming'
const patient = await hcp1Api.patientApi.createOrModifyPatient(
new Patient({ firstName: 'John', lastName: 'Snow', note }),
)
// hcp2 can already access patient
const contentString = 'Hello world'
const dataSample = await hcp1Api.dataSampleApi.createOrModifyDataSampleFor(
patient.id,
new DataSample({
labels: new Set([new CodingReference({ type: 'IC-TEST', code: 'TEST' })]),
content: { en: { stringValue: contentString } },
}),
)
// hcp2 can already access dataSample

No automatic share on modify

The automatic data sharing applies only on entity creation, and not on modification. If a user is sharing data with another user and modifies an entity that is not yet shared with that user the updated entity won't automatically be shared with them.

const contentNotOnModify = "Won't automatically update who the data is shared with on modify"
const dataSampleNotOnModify = await hcp1Api.dataSampleApi.createOrModifyDataSampleFor(
patient.id,
new DataSample({
...existingDataSample,
content: { en: { stringValue: contentNotOnModify } },
}),
)

Uni-directional

Note that the auto-share is uni-directional: if hcp1 is automatically sharing data with hcp2 it does not mean that hcp2 will automatically data with hcp1. Anything created by hcp2 won't be accessible to hcp1 until hcp2 shares it.

const contentNotSharedBy2 = 'Hcp 2 is not sharing automatically with 1'
const dataSampleNotSharedBy2 = await hcp2Api.dataSampleApi.createOrModifyDataSampleFor(
patient.id,
new DataSample({
labels: new Set([new CodingReference({ type: 'IC-TEST', code: 'TEST' })]),
content: { en: { stringValue: contentNotSharedBy2 } },
}),
)

Stop sharing

You can stop the automatic data share using the stopSharingDataWith method.

await hcp1Api.userApi.stopSharingDataWith('medicalInformation', [
hcp1Api.dataOwnerApi.getDataOwnerIdOf(hcp2User),
])
Data creation example
const contentNotSharedAnymore = 'Hcp 1 stopped sharing data automatically with 2'
const dataSampleNotSharedAnymore = await hcp1Api.dataSampleApi.createOrModifyDataSampleFor(
patient.id,
new DataSample({
labels: new Set([new CodingReference({ type: 'IC-TEST', code: 'TEST' })]),
content: { en: { stringValue: contentNotSharedAnymore } },
}),
)

Non-retroactivity

Both the shareAllFutureDataWith and stopSharingDataWith methods are not retroactive. This means that when a user starts sharing data with another user they will not give access to already existing data, and when they stop sharing data they will not revoke access to shared data.

Applicable to all data owners

Any data owner can automatically share data with any other data owner, regardless of their type (patient, healthcare professional, or medical device).

No chaining of automatic data share

The automatic data sharing applies only to entities created by the user which is sharing the data. If hcp1 shares all data with p and p shares all data with hcp2 when hcp1 creates a new entity it will only be shared with p, and not also with hcp2.

await hcp1Api.userApi.shareAllFutureDataWith('medicalInformation', [
hcp1Api.dataOwnerApi.getDataOwnerIdOf(pUser),
])
await pApi.userApi.shareAllFutureDataWith('medicalInformation', [
pApi.dataOwnerApi.getDataOwnerIdOf(hcp2User),
])

const contentNoChaining =
"Even if hcp1 shares with p and p shares with hcp2, hcp2 won't have automatic access to the data"
const dataSampleNoChaining = await hcp1Api.dataSampleApi.createOrModifyDataSampleFor(
patient.id,
new DataSample({
labels: new Set([new CodingReference({ type: 'IC-TEST', code: 'TEST' })]),
content: { en: { stringValue: contentNoChaining } },
}),
)