Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. pragma solidity >=0.4.19 <0.6.0;
  2. contract All_In_One {
  3.  
  4. struct paitent {
  5. bytes32 name;
  6. bytes32 addres;
  7. uint phoneNo;
  8. bytes32 bloodGroup;
  9. uint insuranceCompanyId;
  10. uint emergencyContact;
  11. bytes32 Precautions;
  12. uint [] treatmentId;
  13. }
  14.  
  15. mapping (uint => uint ) entitie;
  16. mapping (uint => paitent ) p_info;
  17. mapping (address => uint) addresstoId;
  18. mapping (uint => address) IdtoAdress;
  19. mapping(address => uint)balancesOfMoney;
  20.  
  21. function addPatientInfo (uint _adharCardNumber, bytes32 _name, bytes32 _addres,uint _phoneNo ,bytes32 _bloodGroup , uint _insuranceCompany, uint _emergencyContact) public {
  22. require(entitie[_adharCardNumber]==0 && addresstoId[msg.sender]==0);
  23. p_info[_adharCardNumber].name = _name;
  24. p_info[_adharCardNumber].addres = _addres;
  25. p_info[_adharCardNumber].phoneNo = _phoneNo;
  26. p_info[_adharCardNumber].bloodGroup = _bloodGroup;
  27. p_info[_adharCardNumber].insuranceCompanyId = _insuranceCompany;
  28. p_info[_adharCardNumber].emergencyContact = _emergencyContact;
  29. entitie[_adharCardNumber] = 1;
  30. addresstoId[msg.sender] = _adharCardNumber;
  31. IdtoAdress[_adharCardNumber] = msg.sender;
  32. }
  33.  
  34. function getPatientInfo(uint _adharCardNumber) public view returns(bytes32 name , bytes32 addres,uint phoneNo ,bytes32 bloodGroup , uint insuranceCompany, uint emergencyContacts, bytes32 Precautions){
  35. require(entitie[_adharCardNumber]==1 || entitie[_adharCardNumber]==2 );
  36. return(p_info[_adharCardNumber].name, p_info[_adharCardNumber].addres, p_info[_adharCardNumber].phoneNo, p_info[_adharCardNumber].bloodGroup, p_info[_adharCardNumber].insuranceCompanyId, p_info[_adharCardNumber].emergencyContact,p_info[_adharCardNumber].Precautions);
  37. }
  38.  
  39. function UpdatePrecautions( uint _adharCardNumber,bytes32 _Precautions ) public {
  40. require(entitie[_adharCardNumber]==1);
  41. p_info[_adharCardNumber].Precautions = _Precautions;
  42. }
  43.  
  44. //---------------------------------------------------------------------------------------------------------------------------------
  45. // Insurance is here
  46. struct insuranceCompany {
  47. bytes32 name ;
  48. uint phoneNo;
  49. bytes32 [] notCovered;
  50. }
  51.  
  52. mapping (uint => insuranceCompany)insu_info;
  53.  
  54. function addInsurancecompany (uint _companyId, bytes32 _name, uint phone_no) public{
  55. require(entitie[_companyId]==0 && addresstoId[msg.sender]==0);
  56. insu_info[_companyId].name = _name;
  57. insu_info[_companyId].phoneNo = phone_no;
  58. addresstoId[msg.sender] = _companyId;
  59. entitie[_companyId]=3;
  60. addresstoId[msg.sender] = _companyId;
  61. IdtoAdress[_companyId] = msg.sender;
  62. }
  63.  
  64. function getInsuranceCompany (uint Insu_id) public view returns (bytes32 name, uint phoneNo){
  65. uint val = addresstoId[msg.sender];
  66. require(entitie[val]==1 || entitie[Insu_id]==3);
  67. uint length = insu_info[Insu_id].notCovered.length;
  68. return(insu_info[Insu_id].name, insu_info[Insu_id].phoneNo);
  69. }
  70.  
  71. function addNotCoverdMedicationInInsurance(bytes32 _Medication) public{
  72. uint val = addresstoId[msg.sender];
  73. require(entitie[val]==3);
  74. insu_info[val].notCovered.push(_Medication);
  75. }
  76.  
  77. function applyForInsurance(uint64 _adharCardNumber) public view returns(bytes32 InsuranceStatus){
  78. uint val = addresstoId[msg.sender];
  79. require((entitie[_adharCardNumber]==1 || entitie[_adharCardNumber]==2) && (entitie[val]==1 || entitie[2]==2));
  80. uint insu_id = p_info[_adharCardNumber].insuranceCompanyId;
  81. uint latestTreatmentid = p_info[_adharCardNumber].treatmentId[p_info[_adharCardNumber].treatmentId.length-1];
  82. bool flag = true;
  83. for(uint j=0;j<insu_info[insu_id].notCovered.length;j++){
  84. if(flag!=true)
  85. break;
  86. else{
  87. for(uint i=0;i<tid[latestTreatmentid].InsuranceKeep.length;){
  88. if(keccak256(insu_info[insu_id].notCovered[j])==keccak256(tid[latestTreatmentid].InsuranceKeep[i]))
  89. {
  90. flag = false;
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. if(flag)
  97. return("success");
  98. //return (0x496e737572616e6365205375636365737366756c6c7920436c61696d6564);
  99. else
  100. return("fail");
  101. //return (0x496e737572616e636520436c61696d696e67204661696c6564);
  102. }
  103.  
  104. //---------------------------------------------------------------------------------------------------------------------------------
  105. // Treatment Structure here
  106. struct treatment {
  107. uint patient_id;
  108. uint doctor_id;
  109. bytes32 diagnosis;
  110. bytes32 test_conducted;
  111. uint bill;
  112. bytes32 medicine;
  113. bytes32 [] InsuranceKeep;
  114. }
  115.  
  116. mapping(uint=>treatment) tid;
  117.  
  118. function createTreatmentID(uint patient_id) public returns (uint){
  119. uint treatment_id = (142317*patient_id)%1000003;
  120. return treatment_id;
  121. }
  122.  
  123. function TreatPatient(uint patient_id,uint doctor_id,bytes32 diagnosis,bytes32 test_conducted,uint bill,bytes32 medicine) public returns (uint){
  124. uint val = addresstoId[msg.sender];
  125. require(entitie[patient_id]==1 || entitie[val]==2 );
  126. uint _tid = createTreatmentID(patient_id);
  127. tid[_tid].patient_id = patient_id;
  128. tid[_tid].doctor_id = doctor_id;
  129. tid[_tid].diagnosis = diagnosis;
  130. tid[_tid].test_conducted = test_conducted;
  131. tid[_tid].bill = bill;
  132. tid[_tid].medicine = medicine;
  133. p_info[patient_id].treatmentId.push(_tid); // pushing treatmentId to array in treatmentId.
  134. return _tid;
  135. }
  136.  
  137. function getTreatmentDetails(uint _tid) public view returns (uint p_id,uint d_id,bytes32 diagnosis,bytes32 test_conducted,uint bill,bytes32 medicine) {
  138. return (tid[_tid].patient_id,tid[_tid].doctor_id,tid[_tid].diagnosis,tid[_tid].test_conducted,tid[_tid].bill,tid[_tid].medicine);
  139. }
  140.  
  141. function addInsuranceKeep(uint p_id, bytes32 _medication) public {
  142. uint val = addresstoId[msg.sender];
  143. require(entitie[val]==2);
  144. uint _t_id = p_info[p_id].treatmentId[p_info[p_id].treatmentId.length-1];
  145. tid[_t_id].InsuranceKeep.push(_medication);
  146. }
  147.  
  148. //---------------------------------------------------------------------------------------------------------------------------------
  149. //Doctor starts here
  150.  
  151. struct doctor{
  152. uint doc_id;
  153. bytes32 name;
  154. bytes32 practice_type;
  155. bytes32 area_of_expertize;
  156. uint phone_no;
  157. bytes32 Address;
  158. }
  159.  
  160. mapping(uint=>doctor) did;
  161. mapping(uint => uint) Otp;
  162.  
  163. function addDoctor(uint doc_id,bytes32 name,bytes32 practice_type,bytes32 area_of_expertize,uint phone_no,bytes32 Address) public {
  164. require(entitie[doc_id]==0 || addresstoId[msg.sender]==0);
  165. did[doc_id] = doctor(doc_id,name,practice_type,area_of_expertize,phone_no,Address);
  166. entitie[doc_id]=2;
  167. addresstoId[msg.sender] = doc_id;
  168. IdtoAdress[doc_id] = msg.sender;
  169. }
  170.  
  171. function getDoctorDetails(uint _d_id) public constant returns (uint doc_id,bytes32 name,bytes32 practice_type,bytes32 area_of_expertize,uint phone_no,bytes32 Address){
  172. uint val = addresstoId[msg.sender];
  173. require(entitie[val]==2 || entitie[val]==1 );
  174. return( did[_d_id].doc_id,did[_d_id].name,did[_d_id].practice_type,did[_d_id].area_of_expertize,did[_d_id].phone_no,did[_d_id].Address);
  175. }
  176.  
  177. function requestAccessToPatient(uint _adharCardNumber) returns(uint){
  178. uint val = addresstoId[msg.sender];
  179. require(entitie[val]==2);
  180. uint otp = uint(keccak256(now*_adharCardNumber));
  181. Otp[_adharCardNumber] = otp;
  182. }
  183.  
  184. function getDetailsOfAllTID(uint _adharCardNumber, uint OTP) public returns(uint []){
  185. uint val = addresstoId[msg.sender];
  186. require(entitie[val]==2 && Otp[_adharCardNumber]==OTP);
  187. return(p_info[_adharCardNumber].treatmentId);
  188.  
  189. }
  190.  
  191.  
  192. //---------------------------------------------------------------------------------------------------------------------------------
  193. //Medical store
  194.  
  195. struct chemist {
  196. uint chemist_id;
  197. bytes32 Address;
  198. bytes32 name;
  199. uint phoneNo;
  200. bytes32 [] medicines;
  201. }
  202.  
  203. mapping(uint=>chemist) cid;
  204.  
  205. function addChemist(uint chem_id, bytes32 Address, bytes32 name,uint phone_no) public {
  206. require(entitie[chem_id]==0 || addresstoId[msg.sender]==0);
  207. cid[chem_id].chemist_id = chem_id;
  208. cid[chem_id].Address = Address;
  209. cid[chem_id].name = name;
  210. cid[chem_id].phoneNo = phone_no;
  211. entitie[chem_id]=4;
  212. addresstoId[msg.sender] = chem_id;
  213. IdtoAdress[chem_id] = msg.sender;
  214. }
  215.  
  216. function getchemistinfo(uint chem_id) public returns(bytes32 Address, bytes32 name,uint phone_no){
  217. require(entitie[chem_id]==4 || entitie[chem_id]==1);
  218. return( cid[chem_id].Address,cid[chem_id].name,cid[chem_id].phoneNo);
  219. }
  220.  
  221. function giveMedicines(uint p_id) public constant returns(bytes32){
  222. uint val = addresstoId[msg.sender];
  223. bytes32 medicatines = tid[p_info[p_id].treatmentId[p_info[p_id].treatmentId.length-1]].medicine;
  224. return(medicatines);
  225. }
  226.  
  227. //--------------------------------------------------------------------------------------------------------------------------
  228. //Identify
  229.  
  230. function Identify() public returns (uint val) {
  231. uint No = addresstoId[msg.sender];
  232. if(entitie[No]==0){
  233. return(0);
  234. }
  235. else
  236. return(entitie[No]);
  237. }
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement