Skip to content

Bug : takeUserHistory stores incorrect userId in PatientHistory struct #63

Description

@ayuxsh009

Description

In UserSide.sol, the takeUserHistory function initializes a PatientHistory struct using the global counter totalUsers as the userId field instead of the _userId parameter passed to the function.

As a result, the userId stored inside the struct does not correspond to the actual patient whose history is being recorded.


Location

MedETH/foundry/src/UserSide.sol

Function: takeUserHistory(...)


Current Code

function takeUserHistory(uint256 _userId, ...) public {
    PatientHistory memory pt1 = PatientHistory(
        totalUsers,   // wrong userId
        _isHandicap,
        _isBp,
        _isDiabetes,
        _userExp
    );

    userIdtoPatientHistory[_userId] = pt1;
}

Expected Behavior

The userId field inside PatientHistory should store the _userId argument passed to the function.


Actual Behavior

The struct stores totalUsers instead of _userId.

This causes the embedded userId field to contain the wrong value, potentially misleading frontend applications or future contract logic that reads patientHistory.userId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions