# `Dose`

An amount of a medicine: `500 mg` or `5 ml`.

Use it for a single dose. For how and how often to take one, use [`DosageInstruction`](/docs/types/type-dosage-instruction.md).

## Shape

One of these, each with its own fields:

| Variant | Field | Type | Required? |
|---|---|---|---|
| `Dose.mass` | `amount` | [`Mass`](/docs/types/type-mass.md) | Yes |
| `Dose.volume` | `amount` | [`Volume`](/docs/types/type-volume.md) | Yes |

## Example

```jadpo
Dose.mass { amount: 500mg }
```

## Good to know

- The other variant is `Dose.volume { amount: ... }`.
- It must be above zero.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

An object of its variant's name, as `tag`, and the variant's fields, in a request, a response or `json.write`:

```json
{"tag":"mass","amount":{"value":"0.0005","unit":"kg"}}
{"tag":"mass","amount":{"value":"0.000000125","unit":"kg"}}
{"tag":"mass","amount":{"value":"0.001","unit":"kg"}}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Dose` is in the group Health, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

It is stored in 2 columns, each named for the field, `_` and its suffix. This is `{"tag":"mass","amount":{"value":"0.001","unit":"kg"}}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_kind` | `text` | `'mass'` |
| `<field>_amount` | `numeric(38, 9)` | `0.001` |

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"tag":"mass","amount":{"value":"500","unit":"mg"}}` | `500 mg` |
| `{"tag":"mass","amount":{"value":"125","unit":"mcg"}}` | `0.125 mg` |
| `{"tag":"mass","amount":{"value":"1","unit":"g"}}` | `1,000 mg` |
| `{"tag":"volume","amount":{"value":"5","unit":"ml"}}` | `5 ml` |

### Operations

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
