Note
This documentation is for a work currently in progress and medjs 1.0 is not yet released.
Tutorial¶
This section handles several examples to use medjs.
var Medjs = require('medjs');
var medjs = Medjs.init(['http://localhost:9921']);
var Account = medjs.local.Account;
var Client = medjs.client;
var HealthData = medjs.healthData;
var Transaction = medjs.local.transaction;
send data upload transaction¶
// create a new account
var account = new Account();
// get account state
Client.getAccountState(account.pubKey, 'tail').then((res) => {
var nonce = parseInt(res.nonce, 10);
// calculate hash of the medical data file
HealthData.hashDataFromFile('/file/path', 'medical-fhir', 'observation').then((hash) => {
// creating a medical data payload
var healthDataPayload = Transaction.createDataPayload(hash);
// creating a medical data upload transaction
var tx = Transaction.dataUploadTx({
from: account.pubKey,
payload: healthDataPayload,
nonce: nonce + 1
});
// sign transaction
account.signTx(tx);
// send transaction
Client.sendTransaction(tx).then((res2) => {
// .. do something
});
});
});