📜 ⬆️ ⬇️

Dive into the blockchain technology: Ecosystem of digital dentistry

We present the second article from the series “Immersion in Blockchain Technology”. In this material, you will learn about the Digital Dentistry Exchange medical project, which is part of a digital dentistry ecosystem called Digital Dentistry Space.

We will talk about its technological features, answer the most frequent questions about smart contracts and share the team’s vision of what the future of blockchain technology is.



The series of articles "Immersion in technology blockchain"


1. A series of materials on Emer technology:
1.1. The secrets of EmerCoin .
1.2. Decentralized uncensored domain name system .
1.3. Worldwide public key infrastructure .
1.4. Decentralized password-free security system .
2. Fast and secure transactions .
3. Ecosystem of digital dentistry .
4. Combating counterfeit goods .
5. Mutual insurance of animals .
6. What is ICO and how to conduct it .
7. Loading ...
')

The problem of distribution of responsibility and improving the quality of complex services in the field of dentistry


In modern digital dentistry, there is a trend called CAD / CAM (Computer Aided Design and Computer Aided Manufacturing). It is used to create dental constructions such as crowns, veneers or tabs (a very cool type of fillings). The production process using a computer consists of several stages:

1. The doctor prepares the tooth for the dental unit, removes the impression and forms the work order:



2. The doctor agrees about the price with the patient, there is an advance payment.

3. The impression is scanned and a digital three-dimensional model of the patient's teeth is obtained:



4. With the help of a specialized design system (CAD) on the basis of this model, the design of a dental construction is constructed taking into account the wishes of the patient and the physician.

5. After confirmation, the three-dimensional model of the dental product is sent to the milling center, where it is materialized from the selected material (zirconium, titanium, polymer or ceramics).

6. The product is disinfected and placed on the patient.



Each stage is paid for separately, but if an error occurs at one of the stages, then all subsequent stages will be done in vain, although they have already been paid. It would seem that fixing it is simple: test every step and forget about the problem. But, for example, difficulties are detected at the stage of installing the product to the patient, and the previous stages (scanning, design and milling) are already paid. This means that the doctor loses money, time and nerves. The last two points also apply to the patient.

The logical solution is to create multilateral agreements that allow the distribution of responsibility between participants of the CAD / CAM process. A huge selection of different payout strategies appears here, for example:


As a result, transactions with several active parties can be presented in different ways, depending on this, prices for services will also be ranked.

This approach was not implemented previously for several reasons: it was impossible to create such forms of transactions due to the lack of a payment regulator, as well as due to the high complexity of formulating contracts with a large number of reservations.

Implementation of the idea


Note: Below is the actual code written in the framework of the hackathon.

The problem described above can be solved with the help of smart contracts: complex payment schemes are packaged in the "accept / decline / pay" buttons. To adjust the entire process, the system with the blockchain architecture will be the most reliable solution.

So the team had a certain background in development and design, for the back-end the Ruby on Rails (RoR) framework was chosen, for the front-end - the AngularJS JavaScript framework.

Writing smart contracts was a bit more difficult, since none of the participants had previously encountered a similar task. Therefore, the Ethereum platform was chosen (a tool for creating decentralized online services based on the blockchain) based on the Azure Blockchain as a Service. Smart contracts were programmed in a special language, Solidity.

Participants shared two questions that they had while working with this tool, and answers to them.

Where is the contract stored and who ensures its correct execution?
When a smart contract is written and debugged, it is placed in a chain of transaction blocks, and can be checked (but not changed!) By any user of the system, if he knows the address for which this smart contract is located. The correctness of the smart contract itself depends on how correctly the programmer wrote it. If the smart contract was described incorrectly, it cannot be corrected and you will have to place another smart contract at a different address.

What is the price of creating a smart contract?
To create a smart contract, you need to spend a certain amount of domestic currency (Eth), the higher its price, the higher it gets priority from miners (these machines calculate cryptoblocks). Miners are needed to ensure that the smart contract is processed and added to the blockchain. If the first installment is minimal, a situation may arise in which a smart contract will never be placed on the global blockchain. It is worth noting that you can also set the contract lifetime.

What you need to know to work with the Ethereum platform for the client side


First of all, you need to understand for which platform you are writing. As we wrote above, in this solution, the AngularJS framework was used, so all the logic was put into the controller, and all the work with web3.js took place there.

Note: in reality, it is better to keep such operations on a secure server away from the client.

Next, you need to initialize the connection to the program to communicate with the blockchain:

var Web3 = require('web3'); var web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider("http://_:8545")); var accounts = web3.eth.accounts; 

accounts are all accounts that are involved in the blockchain connection program (in our case, it is geth ).

Now we need a function to find out the balance of connected tokens:

  function getBalance(address){ var funds = web3.eth.getBalance(address); return funds; } 

Let's try to pay for something via a smart contract at contractAddress :

 function pay (amount, myToken, password, token, contractAddress){ web3.personal.unlockAccount(myToken,password); var contract = web3.eth.contract(abi).at(contractAddress); var res = contract.initDoctor.sendTransaction(token, {from:myToken, value:web3.toWei(amount,'ether')}); alert("you dropped to system with token "+token); } 

Note: for simplicity, a password in the plain text form was set, but this cannot be done on a real system.

These are the basic functions you need to know to call smart contracts. Details can be found on the official website of Ethereum .

What you need to know to write a smart contract in Solidity


There are online compilers as well as smart contract compilers supplied by Etherium. In this project, we decided to use this editor , as it is quite convenient and fast.



Further, in the blockchain, the code was used to write a smart contract:

 pragma solidity ^0.4.0; contract Dental { uint cadPrice = 10; uint millPrice = 10; uint digitizePrice = 10; mapping (address => uint) doctor_balances; mapping (address => uint) digitizer_balances; mapping (address => uint) cad_balances; mapping (address => uint) mill_balances; mapping (address => uint) statuses; //0 -start, //1 - digitizer initialized, //2 - cad initialized, //3 - mill initialized, //4 - digitizer ready, //5 - cad_ready, //6 - mill ready, //7 -payed mapping (address => address) digitizer_addresses; mapping (address => address) cad_addresses; mapping (address => address) mill_addresses; function initDoctor() { //  doctor_balances[ msg.sender ] += msg.value; statuses[msg.sender] = 0; } function initDigitizer(address digitizerAddr) { digitizer_addresses[msg.sender] = digitizerAddr; digitizer_balances[msg.sender] += msg.value; if (statuses[msg.sender] == 0) statuses[msg.sender] = 1; } function initCad(address cadAddr) { cad_addresses[msg.sender] = cadAddr; doctor_balances[ msg.sender ] -= cadPrice; cad_balances[msg.sender] += msg.value; if (statuses[msg.sender] == 1) statuses[msg.sender] = 1; } function initMill(address millAddr) { mill_addresses[msg.sender] = millAddr; mill_balances[msg.sender] += msg.value; if (statuses[msg.sender] == 2) statuses[msg.sender] = 3; } function digitizerDone() { if (statuses[msg.sender]==3) statuses[msg.sender] = 4; } function cadDone() { if (statuses[msg.sender]==4) statuses[msg.sender] = 5; } function millDone() { if (statuses[msg.sender]==5) statuses[msg.sender] = 6; } function doctorDone(bool happy) payable returns (bool) { if (statuses[msg.sender]!=6) return false; if (!happy){ doctor_balances[msg.sender] += digitizer_balances[msg.sender]; doctor_balances[msg.sender] += cad_balances[msg.sender]; doctor_balances[msg.sender] += mill_balances[msg.sender]; digitizer_balances[msg.sender] = 0; cad_balances[msg.sender] = 0; mill_balances[msg.sender] = 0; return false; } bool digitizerOk = digitizer_addresses[msg.sender].send(digitizer_balances[msg.sender]); digitizer_balances[msg.sender] = 0; bool cadOk = cad_addresses[msg.sender].send(cad_balances[msg.sender]); cad_balances[msg.sender] = 0; bool millOk = mill_addresses[msg.sender].send(mill_balances[msg.sender]); mill_balances[msg.sender] = 0; return (digitizerOk && cadOk && millOk); } } 

Let us examine it in more detail:

1. First, we indicate the version of Solidity and declare the contract:

 pragma solidity ^0.4.0; contract Dental { 

2. we set the cost of 3D scanning, design and milling services:

  uint cadPrice = 10; uint millPrice = 10; uint digitizePrice = 10; 

3. Create arrays of balances to pay for process participants:

  mapping (address => uint) doctor_balances; mapping (address => uint) digitizer_balances; mapping (address => uint) cad_balances; mapping (address => uint) mill_balances; 

4. Specify statuses:

  mapping (address => uint) statuses; //0 - start, //1 - digitizer initialized, //2 - cad initialized, //3 - mill initialized, //4 - digitizer ready, //5 - cad_ready, //6 - mill ready, //7 -payed 

5. Create arrays of accounts of participants in the process (without doctors):

  mapping (address => address) digitizer_addresses; mapping (address => address) cad_addresses; mapping (address => address) mill_addresses; 

6. Initialize the doctor, they will be considered the sender. Please note that he can take new orders only if he has the status "not yet started" or "order completed":

  function initDoctor() { //  if (statuses[msg.sender] == 0 || statuses[msg.sender] == 7){ doctor_balances[ msg.sender ] = msg.value; statuses[msg.sender] = 0; } } 

7. Initialize the scanner, which will be used if the doctor has the status of "not yet started":

  function initDigitizer(address digitizerAddr) { digitizer_addresses[msg.sender] = digitizerAddr; digitizer_balances[msg.sender] = msg.value; if (statuses[msg.sender] == 0) statuses[msg.sender] = 1; } 

8. Similarly, we repeat with the design:

  function initCad(address cadAddr) { cad_addresses[msg.sender] = cadAddr; doctor_balances[ msg.sender ] -= cadPrice; cad_balances[msg.sender] = msg.value; if (statuses[msg.sender] == 1) statuses[msg.sender] = 2; } 

9. Similarly, we repeat with the milling machine:

  function initMill(address millAddr) { mill_addresses[msg.sender] = millAddr; mill_balances[msg.sender] += msg.value; if (statuses[msg.sender] == 2) statuses[msg.sender] = 3; } 

10. Next, we confirm the work of the scanner:

  function digitizerDone() { if (statuses[msg.sender]==3) statuses[msg.sender] = 4; } 

11. We confirm the work of the designer:

  function cadDone() { if (statuses[msg.sender]==4) statuses[msg.sender] = 5; } 

12. We confirm the work of the milling machine:

  function millDone() { if (statuses[msg.sender]==5) statuses[msg.sender] = 6; } 

13. A doctor may or may not accept work. In the latter case, all the money will be returned to his account. ). If the work has not yet been milled, then nothing happens. If the doctor accepts the work, the money is sent to the accounts of the participants:

  function doctorDone(bool happy) payable returns (bool) { if (!happy){ doctor_balances[msg.sender] += digitizer_balances[msg.sender]; doctor_balances[msg.sender] += cad_balances[msg.sender]; doctor_balances[msg.sender] += mill_balances[msg.sender]; digitizer_balances[msg.sender] = 0; cad_balances[msg.sender] = 0; mill_balances[msg.sender] = 0; return true; } if (statuses[msg.sender]!=6) return false; bool digitizerOk = digitizer_addresses[msg.sender].send(digitizer_balances[msg.sender]); digitizer_balances[msg.sender] = 0; bool cadOk = cad_addresses[msg.sender].send(cad_balances[msg.sender]); cad_balances[msg.sender] = 0; bool millOk = mill_addresses[msg.sender].send(mill_balances[msg.sender]); mill_balances[msg.sender] = 0; if (digitizerOk && cadOk && millOk) statuses[msg.sender]=7; return (digitizerOk && cadOk && millOk); } } 


A word to the Digital Dentistry Exchange project team


We asked the project participants what kind of future they see in the blockchain technology:

“Blockchain technology is potentially the most appropriate technology for conducting transactions of any type, ranging from financial services to cooking. The only addition to the blockchain should be a modified proof-of-work mechanism that will benefit people or science (for example, the long-standing task of finding the integer values ​​of a, b, c in a ^ 3 + b ^ 3 + c ^ 3 = 33 ).

At the moment, the blockchain system can be perfectly integrated into the service delivery system, where results can be measured (integrated services in medicine, manufacturing, online sales or the achievement of certain metrics and, possibly, the judicial arbitration system).

The number of possible applications can be huge - the main thing is to test ideas, implementations and actively implement them. Also, it would not be superfluous to introduce legal regulation and an ISO standard for systems with a blockchain architecture. ”

In the photo below, the authors of the material: Konstantin Skobeltsyn, Vitaly Dementyev, Rinat Hatipov, Aydar Nigmatzhanov, Roman Barnabas.

Source: https://habr.com/ru/post/313130/


All Articles