// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.8.0; contract BirthCert { address public gov; constructor() { gov = msg.sender; } struct HospitalModel{ string name; string location; string contact; address pubadd; } struct MuncipalityModel{ string location; string contact; uint pincode; address pubadd; } struct BirthCertificateModel{ string name; string fathersName; string mothersName; string dob; uint hospitalId; uint muncipalityId; } mapping (uint=>HospitalModel) public hospital; mapping (uint=>MuncipalityModel) public muncipality; mapping (uint=>BirthCertificateModel) public bc; mapping (uint=>bool) public bcApprove; mapping (bytes32=>uint) verifyedBc; uint public hID = 256; uint public mID = 512; uint public bCID = 1024; modifier onlyGov(){ require(gov == msg.sender,"only Gov"); _; } modifier onlyHospital(uint id){ require(hospital[id].pubadd == msg.sender,"only Hospital"); _; } modifier onlyMuncipality(uint id){ require(muncipality[id].pubadd == msg.sender,"only Muncipality"); _; } function setHospital( string memory _name, string memory _location, string memory _contact, address _pubadd) public onlyGov{ hospital[hID] = HospitalModel( _name, _contact, _location, _pubadd); hID++; } function setMuncipality( string memory _location, string memory _contact, uint _pincode, address _pubadd) public onlyGov{ muncipality[mID] = MuncipalityModel( _contact, _location, _pincode, _pubadd); mID++; } function newBirth( string memory _name, string memory _fatherName, string memory _motherName, string memory _dob, uint _hopitalId, uint _muncipalityId ) public onlyHospital(_hopitalId) { bc[bCID]= BirthCertificateModel( _name, _fatherName, _motherName, _dob, _hopitalId, _muncipalityId ); bCID++; } function approveBc(uint _bcId,uint _mId) public onlyMuncipality(_mId) { require(bc[_bcId].muncipalityId==_mId,"BirthCertificate Id Shoud be Valid"); require(bcApprove[_bcId]==false,"Already Approved"); bcApprove[_bcId]==true; bytes memory hashingData = abi.encodePacked(bc[_bcId].name,bc[_bcId].fathersName,bc[_bcId].mothersName,bc[_bcId].dob); bytes32 hash = keccak256(hashingData); verifyedBc[hash]=_bcId; } function birthCertificate( string memory _name, string memory _fatherName, string memory _motherName, string memory _dob ) public view returns(uint _bcId){ bytes memory hashingData = abi.encodePacked(_name,_fatherName,_motherName,_dob); bytes32 hash = keccak256(hashingData); return verifyedBc[hash]; } }
0.7.1