# Advanced data collection
URL: https://docs.awellhealth.com/docs/marketplace/collectdata

> For the complete documentation index, see [llms.txt](https://docs.awellhealth.com/llms.txt).



<img src="/marketplace/collectdata.png" width="48" height="48" />

This extension allows you to collect data from your users using a variety of advanced input types and data sources.

Category: Forms. Adds 3 actions to a care flow.

## Actions [#actions]

Advanced data collection adds these 3 actions to a care flow. Add one to a step, then fill in its inputs.

### Array fields test [#array-fields-test]

Just to show string and numeric array fields

This action can be previewed in Studio before you publish.

| Input         | Type            | Required | Description                                                                       |
| ------------- | --------------- | -------- | --------------------------------------------------------------------------------- |
| String Array  | `string_array`  | Yes      | Select a data point or enter comma separated strings. One of: One, Two, Three.    |
| Numeric Array | `numeric_array` | Yes      | Select a data point or enter comma separated numbers. One of: One, Two, Three.    |
| String Array  | `string_array`  | Yes      | Select a data point or enter comma separated strings. One of: Option 1, Option 2. |
| Numeric Array | `numeric_array` | Yes      | Select a data point or enter comma separated numbers. One of: Option 1, Option 2. |

Returns:

| Data point   | Type            |
| ------------ | --------------- |
| `allNumbers` | `numbers_array` |
| `allStrings` | `strings_array` |

### Collect medication [#collect-medication]

Collect medication from the user

| Input | Type     | Required | Description                                                  |
| ----- | -------- | -------- | ------------------------------------------------------------ |
| Label | `string` | No       | A label or description that will be shown above the question |

Returns:

| Data point             | Type     |
| ---------------------- | -------- |
| `medicationData`       | `json`   |
| `medicationDataString` | `string` |
| `prettyMedicationData` | `string` |

This action enables patients to list their medications. They can add multiple medications, providing the name, dosage, and any specific instructions for each one.

### Dynamic choice selector [#dynamic-choice-selector]

The dynamic choice selector allow you to set up a select question where the available choices are dynamically populated through an API lookup

| Input                        | Type      | Required | Description                                                                                                                                                                                  |
| ---------------------------- | --------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Select - Label               | `string`  | Yes      | Enter the label text that will be displayed before the selector.                                                                                                                             |
| Select - Response required?  | `boolean` | Yes      | The user must select an option before continuing.                                                                                                                                            |
| Options - Endpoint URL       | `string`  | Yes      | Enter the URL (starting with `https://`) where the options to display can be fetched. The endpoint must return an array of objects with the following properties: `id`, `label` and `value`. |
| Options - Headers            | `json`    | No       | Enter the headers to send to the options source URL. The headers must be in JSON format.                                                                                                     |
| Options - Search query param | `string`  | No       | Enter the key of the free text search query param if the endpoint supports this e.g. `search` for `https://example.com/options?search=foo`.                                                  |

Returns:

| Data point       | Type     |
| ---------------- | -------- |
| `label`          | `string` |
| `selectedOption` | `json`   |
| `value`          | `string` |

Standard select questions in Awell forms have a discrete set of choices to select from that are defined at the time that the form is created. If the list of choices to present to your responders isn't known at the time the form is being built, or changes often, this action allows you to load choices dynamically from a remote data source.

Dynamically-loaded choices must minimally adhere to the following format in a list form (i.e. an array):

```json
[
  {
    "id": "unique-id-1",
    "label": "Choice label 1",
    "value": "Choice value 1"
  },
  {
    "id": "unique-id-2",
    "label": "Choice label 2",
    "value": "Choice value 2"
  }
]
```

The `id`, `label`, and `value` fields are required. However, additional fields can be added to the object. Besides the `label` and `value`, which are available as distinct data points, the additional data of the selected choice will also be returned as a data point.

Example:

```json
[
  {
    "id": "unique-id-1",
    "label": "Choice label 1",
    "value": "Choice value 1",
    "additionalData": "Additional data",
    "nestedData": {
      "nested": "value"
    }
  }
]
```

Additionally, you can specify a free text search field (`Options - Search query param` field) to allow users to search through the choices. This is optional but highly recommended. If not specified, the choices will be fetched on question load and presented in a static list that cannot be filtered.

As an example, using the endpoint `https://example.com/choices` with a query parameter `search` (e.g. `https://example.com/choices?search=QUERY` where `QUERY` is whatever the user typed into the input), then the API is expected to return the choices based on that match the search term.

We recommend that your search logic returns an *alphabetically-sorted* list of all options where the *lowercase* label names *contain* the *lowercase* search term.

```js
// Example search logic
const searchTerm = req.query.search
const results = []

options.forEach((option) => {
  if (option.label.toLowerCase().includes(searchTerm.toLowerCase())) {
    results.push({
      label: option.label,
      value: option.value,
      id: option.id,
    })
  }
})

const sortedResults = results.sort((a, b) => a.label.localeCompare(b.label))
res.json(results)
```

## Setup and notes [#setup-and-notes]

This extension allows you to collect data from your users using a variety of more advanced input types and data sources.

### Extension settings [#extension-settings]

In order to set up this extension, no settings are required.

## Where this page comes from [#where-this-page-comes-from]

The settings, actions, inputs, outputs and webhooks above are generated from the
extension's own code, at `@awell-health/awell-extensions` v2.1.159. They match what the
platform actually does rather than a description of it.

Field-level detail also appears in Awell Studio when you configure the action.
Something wrong or missing? Email [support@awellhealth.com](mailto:support@awellhealth.com).
