Create a Patient
In Cardinal, a patient is represented by the Patient
entity.
- Kotlin
- Python
- Typescript
- Dart
In the following example, the user reads a first name and last name from the standard input and instantiates a patient entity:
val firstName = readln().trim()
print("Last name: ")
val lastName = readln().trim()
val patient = DecryptedPatient(
id = UUID.randomUUID().toString(),
firstName = firstName,
lastName = lastName,
)
In the following example, the user reads a first name and last name from the standard input and instantiates a patient entity:
first_name = input("First name: ")
last_name = input("Last name: ")
patient = DecryptedPatient(
id=str(uuid.uuid4()),
first_name=first_name,
last_name=last_name,
)
In the following example, the user reads a first name and last name from the standard input and instantiates a patient entity:
const firstName = await readLn("First name: ")
const lastName = await readLn("Last name: ")
const patient = new DecryptedPatient({
id: uuid(),
firstName: firstName,
lastName: lastName,
})
In the following example, the user instantiates a patient entity using a firstName
and lastName
that are provided by
the UI:
final patient = DecryptedPatient(
generateUuid(),
firstName: firstName,
lastName: lastName,
);
A Patient
is an encryptable entity, meaning it will be encrypted on the device that creates it and then sent
encrypted to the cloud. Since it is decrypted at the moment of creation, a DecryptedPatient
is instantiated. Besides
firstName
and lastName
, the id
must also be set on the entity. Using a
UUID v4 is strongly recommended.
Next, the metadata required for the encryption of the entity must be initialized:
- Kotlin
- Python
- Typescript
- Dart
val patientWithMetadata = sdk.patient.withEncryptionMetadata(patient)
patient_with_metadata = sdk.patient.with_encryption_metadata_blocking(patient)
const patientWithMetadata = await sdk.patient.withEncryptionMetadata(patient)
final patientWithMetadata = await sdk.patient.withEncryptionMetadata(patient);
This step is mandatory and also shares the newly created Patient with the user creating it, who will initially be the only one able to read the entity's encrypted fields.
After this step, the entity can finally be encrypted and stored in the cloud:
- Kotlin
- Python
- Typescript
- Dart
val createdPatient = sdk.patient.createPatient(patientWithMetadata)
created_patient = sdk.patient.create_patient_blocking(patient_with_metadata)
const createdPatient = await sdk.patient.createPatient(patientWithMetadata)
final createdPatient = await sdk.patient.createPatient(patientWithMetadata);
- Kotlin
- Python
- Typescript
- Dart
Once created, the entity can be modified. In the following example, a date of birth is read from the standard input and added to the patient:
print("Date of birth (YYYYMMDD): ")
val dateOfBirth = readln().toInt()
val patientWithBirth = createdPatient.copy(
dateOfBirth = dateOfBirth
)
val updatedPatient = sdk.patient.modifyPatient(patientWithBirth)
Once created, the entity can be modified. In the following example, a date of birth is read from the standard input and added to the patient:
date_of_birth = int(input("Date of birth (YYYYMMDD): "))
created_patient.date_of_birth = date_of_birth
updated_patient = sdk.patient.modify_patient_blocking(created_patient)
Once created, the entity can be modified. In the following example, a date of birth is read from the standard input and added to the patient:
const dateOfBirth = parseInt((await readLn("Date of birth (YYYYMMDD): ")).trim())
const patientWithBirth = new DecryptedPatient({
...createdPatient,
dateOfBirth: dateOfBirth,
})
const updatedPatient = await sdk.patient.modifyPatient(patientWithBirth)
Once created, the entity can be modified. In the following example, a date of birth is retrieved from the UI and added to the patient:
int dateAsYYYYMMDD = // This is provided by the user through the UI
createdPatient.dateOfBirth = dateAsYYYYMMDD;
final updatedPatient = await sdk.patient.modifyPatient(createdPatient);
The date of birth in the patient is stored in the dateOfBirth
field as an integer in the YYYYMMDD
format. It is worth
noting that since the entity is already created and the encryption metadata are already initialized, there is no need
to call withEncryptionMetadata
again.
After creation, it is also possible to retrieve the entity from the cloud. In the following example, the patient is retrieved using its ID:
- Kotlin
- Python
- Typescript
- Dart
println("Retrieving patient by ID:")
val retrievedPatient = sdk.patient.getPatient(updatedPatient.id)
print("The retrieved patient is:")
retrieved_patient = sdk.patient.get_patient_blocking(updated_patient.id)
console.log("The retrieved patient is:")
const retrievedPatient = await sdk.patient.getPatient(updatedPatient.id)
final retrievedPatient = sdk.patient.getPatient(updatedPatient.id);
More advanced methods for retrieving entities are available and will be explained in another section of this tutorial and in more depth here.