Advertisement
varun1729

Untitled

May 14th, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. pragma solidity >=0.4.21;
  2. import "./Roles.sol";
  3.  
  4. contract Contract {
  5. using Roles for Roles.Role;
  6.  
  7. Roles.Role private admin;
  8. Roles.Role private doctor;
  9. Roles.Role private patient;
  10.  
  11. struct Doctor {
  12. string drHash;
  13. }
  14.  
  15. struct Patient {
  16. string patHash;
  17. }
  18.  
  19. mapping(address => Doctor) Doctors;
  20. mapping(address => Patient) Patients;
  21.  
  22. address[] public Dr_ids;
  23. address[] public Patient_ids;
  24.  
  25. address accountId;
  26. address admin_id;
  27. address get_patient_id;
  28. address get_dr_id;
  29.  
  30. constructor() {
  31. admin_id = msg.sender;
  32. admin.add(admin_id);
  33. }
  34.  
  35. //get Admin
  36.  
  37. function getAdmin() public view returns (address) {
  38. return admin_id;
  39. }
  40.  
  41. function isAdmin() public view returns (bool) {
  42. return admin.has(msg.sender);
  43. }
  44.  
  45. //Add Doctor
  46.  
  47. function addDoctor(address _newdr) public {
  48. require(admin.has(msg.sender), "Only For Admin");
  49. doctor.add(_newdr);
  50. }
  51.  
  52. function addDrInfo(address dr_id, string memory _drInfo_hash) public {
  53. require(admin.has(msg.sender), "Only For Admin");
  54.  
  55. Doctor storage drInfo = Doctors[msg.sender];
  56. drInfo.drHash = _drInfo_hash;
  57. Dr_ids.push(msg.sender);
  58.  
  59. doctor.add(dr_id);
  60. }
  61.  
  62. function getAllDrs() public view returns (address[] memory) {
  63. return Dr_ids;
  64. }
  65.  
  66. function getDr(address _id) public view returns (string memory) {
  67. return (Doctors[_id].drHash);
  68. }
  69.  
  70. // check is Doctor
  71.  
  72. function isDr(address id) public view returns (string memory) {
  73. require(doctor.has(id), "Only for Doctors");
  74. return "1";
  75. }
  76.  
  77. // Check is Patient
  78.  
  79. function isPat(address id) public view returns (string memory) {
  80. require(patient.has(id), "Only for Doctors");
  81. return "1";
  82. }
  83.  
  84. /*
  85. Modifiers
  86. */
  87.  
  88. modifier onlyAdmin() {
  89. require(admin.has(msg.sender) == true, "Only Admin Can Do That");
  90. _;
  91. }
  92. modifier onlyDoctor() {
  93. require(doctor.has(msg.sender) == true, "Only Doctor Can Do That");
  94. _;
  95. }
  96. modifier onlyPatient() {
  97. require(patient.has(msg.sender) == true, "Only Admin Can Do That");
  98. _;
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement