Define a data model
Data modelling is the process of defining how data is used and stored within the system.
When configuring your data model on Extra Horizon, you will start by creating data schemas. In these schemas you describe how your data is structured.
When you've created a schema, you can add one or multiple documents to it. Each one of those documents need to conform to the schema you've defined. In developer terms, if you squint a little, you can look at schemas as being a class, and documents being the class instances of that class.
Depending on your data model, a single schema might not be enough. That's okay since you can create as many schema's as you want. Think in advance about how the documents of these schemas will be used & queried most efficiently in your application and design them accordingly.
For the purpose of the tutorial, we keep it simple. So we will create a schema called blood-pressure-measurement
where each document represents a measurement.
In the tutorial repository, we'll be using the 1-data-model
directory if you want to try this out.
Defining properties for your data model
We need to create a data model to support the creation of blood pressure measurements. Therefore we will create a Schema with the following properties:
systolic
: A number defining the pressure during a heart beatdiastolic
: A number defining the pressure in between heart beatstimestamp
: The date and time the measurement was taken
For more detailed information regarding properties and their types please refer to the documentation.
In the example below you see how we defined the properties for our blood pressure measurements. We also gave our data Schema a sensible name and a description. The name is important because that is the 'friendly name' which can be used to refer to the schema throughout your application implementation.
In the schemas
directory of 1-data-model
, you will find this model in blood-pressure.json
.
We've added a single status created
& made a creationTransition
which just sets the initial status to created
. Finally we list our properties under properties
.
Please refer to the documentation here to learn more in detail about schemas.
Synchronize the Schema
We must now synchronize this schema to the ExH data service. This can be achieved by using the ExH CLI. In the 1-data-model
directory, do:
This is a global sync command available in the CLI, which will sync schemas, tasks, templates... you name it. It's a one-stop solution for syncing your entire project. By default, it makes a couple of assumptions about where these things are located. For example, it expects schemas to be in a schemas
directory, tasks in a tasks
directory, etc ...
This is fine for our purposes. If you want to customize this behaviour, your can create a repo-config.json
file to change the paths where it will look for things. More information, see here.
For our schema, exh sync
performs a couple of key operations:
Validation: It checks all JSON files within the
schemas
directory to verify that they are syntactically correct & consistent.Synchronization: Once validated, it syncs the local schemas with the ExH data service. In this instance, a new schema titled
blood-pressure-measurement
will be created in the data service.
Use the created Schema
In the examples
directory in the root of the repository, you can find the following scripts:
create-measurement.js
: creates new measurementsget-measurement.js
: retrieves a created measurementdelete-measurement.js
: deletes an existing measurement
Please familiarize yourself with the contents of these script. They will show you how to use the SDK to create, read & delete blood pressure measurements.
Example: create a new measurement. The script will prompt to enter a blood pressure measurement.
And then retrieve the measurement you've just created:
Last updated