0

我想在患者和医生之间创建一份合同,其中第一位患者填写他的详细信息,例如姓名、年龄和他面临的问题。一旦填写了上述详细信息,function createDoctor()就会调用并name, age and problems作为参数发送给 Doctor。考虑到患者填写的详细信息,医生设置医师并更新患者面临的问题(如果有)。但我无法弄清楚实现上述语句的方法。下面是我询问患者详细信息并将其发送给医生的代码。现在我无法实现 Doctor 部分。下面是代码:

病人.sol

pragma solidity ^0.4.6;
import './Doctor.sol';

contract Patient {
    bytes private name = "";
    bytes private dateOfBirth="NA";
    bytes private problemFaced = "";
    address public myDoctor;

    // Event that is fired when patient is changed
    event patientChanged(string whatChanged);

    function createDoctor() public {
        myDoctor = new Doctor(getName(), getDateOfBirth(), getGender(), problemFaced);
    }

    function ProblemFaced(string problems) public {
        problemFaced = bytes(problems);
    }

    function getName() internal view returns (bytes) {
        return name;  // First_Name Last_Name
    }
    function getDateOfBirth() internal view returns (bytes) {
        return dateOfBirth; // YYYYMMDD
    }

    function setName(string _name) public {
        name = bytes(_name);  // First_Name Last_Name
        emit patientChanged("name changed"); // fire the event
    }
    function setDateOfBirth(string _dateOfBirth) public {
        dateOfBirth = bytes(_dateOfBirth);   // YYYYMMDD
        emit patientChanged("dateOfBirth changed"); // fire the event
    }
}

医生.sol

pragma solidity ^0.4.6;
contract Doctor {
    // the address of the owner (the patient)
    address public owner;
    uint balance;
    // address of physician that can add allergies
    string public physician;
    // name of the patient LAST^FIRST
    string public patient_name;
    string public patient_dob;
    string public patient_gender;
    string public patient_problem = '';

    modifier isOwnerPatient {
        require(msg.sender == owner);
        _;
    }

    function Doctor(bytes _name, bytes _dob, bytes _gender, bytes _problems) {
        owner =  msg.sender;
        patient_name = string(_name);
        patient_dob = string(_dob);
        patient_gender = string(_gender);
        patient_problem = string(_problems);
    }

    function updateProblem(bytes _condition) {
        patient_problem = strConcat(patient_problem, string(_condition)); 
    }

    // allows owner to set the physician that can add allergies
    function SetPhysician(string _physician) isOwnerPatient {
        physician = _physician;
    }

    function strConcat(string _a, string _b) internal pure returns (string){
        bytes memory _ba = bytes(_a);
        bytes memory _bb = bytes(_b);
        string memory abcde = new string(_ba.length + 2 + _bb.length);
        delete abcde;
        bytes memory babcde = bytes(abcde);
        uint k = 0;
        for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
        babcde[k++] = ",";
        babcde[k++] = " ";
        for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
        return string(babcde);
    }
}

在执行上述问题陈述时是否有可能使用 owner 和 msg.sender 。

4

0 回答 0