This repository contains the example code used in the real-time communication tutorial.
It shows the use case of a patient-oriented application that publishes medical data and a backend service that has to perform an analysis whenever a new piece of information is created.
The patient application is simulated by the Publisher. The Publisher logs in as a healthcare party, creates a patient user, and uses the patient user to simulate the creation of samples by a device that measures the sugar level in blood. Each one of these samples is also shared of with the healthcare party.
The backend service is simulated by the Subscriber. The Subscriber logs in as a healthcare party and opens a websocket to listen to all the creation events of the entities shared with them with a specific tag. Whenever a new entity is created, the Subscriber assigns a tag to it.
The tutorial code is available in Kotlin, Python, and TypeScript. Below you will find instructions for running the code in all three languages. For further explanations and examples, check the Cardinal documentation.
To run the tutorial in Kotlin, clone this repository:
git clone https://github.com/icure/cardinal-real-time-analysis-tutorial.gitThen, open the folder in IntelliJ. Run the Subscriber, and then the Publisher.
To run the tutorial in Python, clone this repository:
git clone https://github.com/icure/cardinal-real-time-analysis-tutorial.git
cd cardinal-real-time-analysis-tutorialIt is recommended to use a virtual environment, to avoid conflicting dependencies. The minimum supported Python version is 3.12.
cd python
python3 -m venv venv
source venv/bin/activateThen, install the Cardinal SDK from PyPI.
pip install cardinal-sdkRun the Subscriber.
python src/subscriber.pyThen open a new terminal, navigate to the python directory of this repository, and launch the publisher.
source venv/bin/activate
python src/publisher.pyTo run the tutorial in Typescript, clone this repository:
git clone https://github.com/icure/cardinal-real-time-analysis-tutorial.git
cd cardinal-real-time-analysis-tutorialThe minimum supported Node version is 19. You can install it using nvm.
nvm install 19
nvm use 19Then, you can navigate to the typescript directory and install the required dependencies using yarn.
cd typescript
yarn installRun the Subscriber code using yarn:
yarn ts-node --esm src/subscriber.tsFinally, open another terminal, navigate to the typescript and run the Publisher:
nvm use 19
yarn ts-node --esm src/publisher.ts