A medical center in the smart cities of the future needs data security and confidentiality to treat patients accurately. One mechanism for sending medical data is to send information to other medical centers without preserving confidentiality. This method is not impressive because in treating people, the privacy of medical information is a principle. In the proposed framework, the opinion of experts from other medical centers for the treatment of patients is received and consider the best therapy. The proposed method has two layers. In the first layer, data transmission uses blockchain. In the second layer, blocks related to patients’ records analyze by machine learning methods. Patient records place in a block of the blockchain. Block of patient sends to other medical centers. Each treatment center can recommend the proposed type of treatment and blockchain attachment and send it to all nodes and treatment centers. Each medical center receiving data of the patients, then predicts the treatment using data mining methods. Sending medical data between medical centers with blockchain and maintaining confidentiality is one of the innovations of this article. The proposed method is a binary version of the HHO algorithm for feature selection. Another innovation of this research is the use of majority voting learning in diagnosing the type of disease in medical centers. Implementation of the proposed system shows that the blockchain preserves data confidentiality of about 100%. The reliability and reliability of the proposed framework are much higher than the centralized method. The result shows that the accuracy, sensitivity, and precision of the proposed method for diagnosing heart disease are 92.75%, 92.15%, and 95.69%, respectively. The proposed method has a lower error in diagnosing heart disease from ANN, SVM, DT, RF, AdaBoost, and BN.