> For the complete documentation index, see [llms.txt](https://ipehr.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ipehr.gitbook.io/docs/reference/contracts/users.md).

# Users

## Functions

### userNew

```solidity
function userNew(
    address addr, 
    bytes32 IDHash, 
    Role role, 
    Attribute[] calldata attrs,
    address signer,
    uint deadline,
    bytes calldata signature
) external onlyAllowed(msg.sender)
```

New user registration

**Parameters**

<table><thead><tr><th width="152">Name</th><th width="197">Type</th><th width="394">Description</th></tr></thead><tbody><tr><td>addr</td><td>address</td><td>New user address</td></tr><tr><td>IDHash</td><td>bytes32</td><td>New user ID hash. Sha3(userID+systemID)</td></tr><tr><td>role</td><td><a data-mention href="#role">#role</a></td><td>New user role.</td></tr><tr><td>attrs</td><td><a data-mention href="#attribute">#attribute</a>[]</td><td>New user attributes.</td></tr><tr><td>signer</td><td>address</td><td>Address of the signer of the request</td></tr><tr><td>deadline</td><td>uint</td><td>Expiration timestamp of the request</td></tr><tr><td>signature</td><td>bytes</td><td>Cryptographic signature of the request performed by the signer's key</td></tr></tbody></table>

### getUser

<pre class="language-solidity"><code class="lang-solidity"><strong>function getUser(address addr) external view returns(User memory)
</strong></code></pre>

Getting ehrID for userID

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>addr</td><td>address</td><td>User address</td></tr></tbody></table>

#### Return Values:

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>user</td><td><a data-mention href="#user">#user</a></td><td></td></tr></tbody></table>

### getUserByCode

```solidity
function getUserByCode(uint64 code) external view returns(User memory)
```

Retrieving a user by unique code. Useful for searching for a doctor by numeric code.

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>code</td><td>uint64</td><td>User unique code</td></tr></tbody></table>

#### Return Values:

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>user</td><td><a data-mention href="#user">#user</a></td><td></td></tr></tbody></table>

### userGroupCreate

```solidity
function userGroupCreate(
    bytes32 groupIdHash, 
    Attribute[] calldata attrs, 
    address signer,
    uint deadline,
    bytes calldata signature
 ) external onlyAllowed(msg.sender) 
```

Creating a user group

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="208">Type</th><th width="386">Description</th></tr></thead><tbody><tr><td>groupIdHash</td><td>bytes32</td><td></td></tr><tr><td>attrs</td><td><a data-mention href="#attribute">#attribute</a>[]</td><td>User group attributes</td></tr><tr><td>signer</td><td>address</td><td>Address of the signer of the request</td></tr><tr><td>deadline</td><td>uint</td><td>Expiration timestamp of the request</td></tr><tr><td>signature</td><td>bytes</td><td>Cryptographic signature of the request performed by the signer's key</td></tr></tbody></table>

### groupAddUser

```solidity
function groupAddUser(GroupAddUserParams calldata p) external
```

Adding a user to a group

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="232">Type</th><th width="328">Description</th></tr></thead><tbody><tr><td>p</td><td><a data-mention href="#groupadduserparams">#groupadduserparams</a></td><td>User address</td></tr></tbody></table>

### groupRemoveUser

```solidity
function groupRemoveUser(
    bytes32 groupIDHash, 
    bytes32 userIDHash, 
    address signer,
    uint deadline,
    bytes calldata signature
) external
```

Removing a user from a group

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="208">Type</th><th width="386">Description</th></tr></thead><tbody><tr><td>groupIDHash</td><td>bytes32</td><td></td></tr><tr><td>userIDHash</td><td>bytes32</td><td></td></tr><tr><td>signer</td><td>address</td><td>Address of the signer of the request</td></tr><tr><td>deadline</td><td>uint</td><td>Expiration timestamp of the request</td></tr><tr><td>signature</td><td>bytes</td><td>Cryptographic signature of the request performed by the signer's key</td></tr></tbody></table>

### userGroupGetByID

```solidity
function userGroupGetByID(bytes32 groupIdHash) external view returns(UserGroup memory)
```

Getting a user group by ID

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>groupIDHash</td><td>bytes32</td><td>User group ID hash</td></tr></tbody></table>

#### Return Values:

<table><thead><tr><th width="152">Name</th><th width="178">Type</th><th width="373">Description</th></tr></thead><tbody><tr><td>userGroup</td><td><a data-mention href="#usergroup">#usergroup</a></td><td></td></tr></tbody></table>

### setAccess

```solidity
function setAccess(
    bytes32 accessID,
    IAccessStore.Access memory a,
    address signer,
    uint deadline,
    bytes calldata signature
) external
```

Sets the access level to the object

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="269">Type</th><th width="309">Description</th></tr></thead><tbody><tr><td>accessID</td><td>bytes32</td><td></td></tr><tr><td>a</td><td><a data-mention href="#iaccessstore.access">#iaccessstore.access</a></td><td></td></tr><tr><td>signer</td><td>address</td><td>Address of the signer of the request</td></tr><tr><td>deadline</td><td>uint</td><td>Expiration timestamp of the request</td></tr><tr><td>signature</td><td>bytes</td><td>Cryptographic signature of the request performed by the signer's key</td></tr></tbody></table>

## Models

### Role

```solidity
enum Role { Patient, Doctor }
```

### Attribute

```solidity
struct Attribute {
    Code  code;
    bytes value;
}
```

### AccessLevel

```solidity
enum AccessLevel { NoAccess, Owner, Admin, Read }
```

### User

```solidity
struct User {
    bytes32   IDHash;
    Role      role;
    Attribute[] attrs;
}
```

### UserGroup

```solidity
struct UserGroup {
    Attribute[] attrs;
    GroupMember[] members;  
}
```

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="190">Type</th><th width="393">Description</th></tr></thead><tbody><tr><td>attrs</td><td><a data-mention href="#attribute">#attribute</a>[]</td><td>User group attributes</td></tr><tr><td>members</td><td><a data-mention href="#groupmember">#groupmember</a>[]</td><td>Array of user group members</td></tr></tbody></table>

### GroupMember

```solidity
struct GroupMember {
    bytes32 userIDHash;
    bytes userIDEncr;
}
```

#### **Parameters**

<table><thead><tr><th width="152">Name</th><th width="126">Type</th><th width="452">Description</th></tr></thead><tbody><tr><td>userIDHash</td><td>bytes32</td><td>User id hash</td></tr><tr><td>userIDEncr</td><td>bytes</td><td>User ID encrypted by group key</td></tr></tbody></table>

### GroupAddUserParams

```solidity
struct GroupAddUserParams {
    bytes32 groupIDHash;
    bytes32 userIDHash;
    AccessLevel level;
    bytes userIDEncr;
    bytes keyEncr;
    address signer;
    uint deadline;
    bytes signature;
}
```

#### **Parameters:**

<table><thead><tr><th width="152">Name</th><th width="162">Type</th><th width="411">Description</th></tr></thead><tbody><tr><td>groupIDHash</td><td>bytes32</td><td></td></tr><tr><td>userIDHash</td><td>bytes32</td><td></td></tr><tr><td>level</td><td><a data-mention href="#accesslevel">#accesslevel</a></td><td></td></tr><tr><td>userIDEncr</td><td>bytes</td><td>userID encrypted by group key</td></tr><tr><td>keyEncr</td><td>bytes</td><td>group key encrypted by adding user public key</td></tr><tr><td>signer</td><td>address</td><td>Address of the signer of the request</td></tr><tr><td>deadline</td><td>uint</td><td>Expiration timestamp of the request</td></tr><tr><td>signature</td><td>bytes</td><td>Cryptographic signature of the request performed by the signer's key</td></tr></tbody></table>

### IAccessStore.Access

```solidity
struct Access {
    AccessKind   kind;
    bytes32      idHash;
    bytes        idEncr;    // id encrypted by access key
    bytes        keyEncr;   // access key encrypted by user private key
    AccessLevel  level;
}
```
