# vironix-schema

> A kit for creating web and mobile app surveys based on FHIR questionnaires

Latest version **1.1.0** (published 2023-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install vironix-schema
pnpm add vironix-schema
yarn add vironix-schema
bun add vironix-schema
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-08-30 |
| First published | 2023-08-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 102.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | vironix |
| Maintainers | a.tishkin |

## Links

- npm: https://www.npmjs.com/package/vironix-schema
- Repository: https://github.com/vironix-health/vironix-schema
- Homepage: https://github.com/vironix-health/vironix-schema#readme
- Issues: https://github.com/vironix-health/vironix-schema/issues
- npm.io page: https://npm.io/package/vironix-schema

## Recent versions

- 1.1.0 (latest) — 2023-08-30

## README

# Vironix FHIR Schema

A kit for creating web and mobile app surveys based on FHIR questionnaires.

## How it works

The `FormHandler` handles the interaction with the with an FHIR questionnaire. It has minimal exposed methods to allow for simple integration. It will store the answers submitted to the FormHandler and return the next question calculated based on the `enableWhen` defined in each question.

## API

The following methods are exposed:

- `hasStarted(): Boolean`. Returns `true` if the questionnaire has been started, otherwise `false`.
- `start(): GetQuestionResult`. Starts the questionnaire and returns the next question (`Item`) and a value indicating whether there are any more questions.
- `getNextQuestion(): GetQuestionResult`. Saves the answer to the current question and returns the next question (if there are questions left) and a value indicating whether there are any more questions.
- `getPreviousQuestion(): GetQuestionResult`. Navigates backwards to the previous question and returns the question and a value indicating whether there are any more questions.
- `getAnswers(): QuestionnaireAnswers`. Returns the currently answered questions and status.

## Conditional Questions

Questions will be returned in the same order they have been defined in the questionnaire, unless the question is only enabled based on previously answered questions. Conditional questions are defined using a list of `enableWhen` conditions inside of the form. The `enableWhen` is defined using the following schema:

```typescript
export type EnableWhen = {
  question: string;
  operator: "exists" | "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "notin";
  answer: any;
};
```

Properties:

- `question`. This is the Id of the question on which to apply the condition.
- `operator`. The type of condition to apply.
  - `exists`. This will return true if the specified question has been answered.
  - `=`. Compares the `answer` specified in this `enableWhen` to the answer supplied in the specified question.
  - `!"`. Checks to see if the `answer` specified in this `enableWhen` does **not** equal the answer supplied in the specified question.
  - `>`. Checks to see if the `answer` specified in this `enableWhen` is **greater** than the answer supplied in the specified question.
  - `<`. Checks to see if the `answer` specified in this `enableWhen` is **smaller** than the answer supplied in the specified question.
  - `>=`. Checks to see if the `answer` specified in this `enableWhen` is **greater or equal** to the answer supplied in the specified question.
  - `<=`. Checks to see if the `answer` specified in this `enableWhen` is **smaller or equal** to the answer supplied in the specified question.
  - `in`. Checks to see if the `answer` specified in this `enableWhen` is **in** the choices in the supplied answer. **Note:** This condition can only be used when the question type of the specified question is `choice` and the uiType is `checkbox`.
  - `notin`. Checks to see if the `answer` specified in this `enableWhen` is **not in** the choices in the supplied answer. **Note:** This condition can only be used when the question type of the specified question is `choice` and the uiType is `checkbox`.
- `answer`. The supplied answer that will be the source of comparison.

## Questionnaire Schema

Here is the schema definition for a Questionnaire / Form.
This is the schema you expect to be returned by the Vironix API when you request a questionnaire.

### Form

```typescript
export type Form = {
  id: string;
  version: string;
  name: string;
  title: string;
  status: "draft" | "active" | "retired" | "unknown";
  date: Date;
  description: string;
  items: [Item];
};
```

### Item

```typescript
export type Item = ItemBase & {
  subItems?: SubItem[];
};
```

### ItemBase

```typescript
export type ItemBase = {
  linkId: string;
  text: string;
  type:
    | "group"
    | "boolean"
    | "decimal"
    | "integer"
    | "date"
    | "datetime"
    | "time"
    | "string"
    | "text"
    | "url"
    | "choice";
  uiType: "slider" | "radio" | "checkbox" | "input" | "select";
  enableWhens?: EnableWhen[];
  enableWhenBehavior?: "all" | "any";
  uiOptions?: UiOptions;
  answerOptions?: AnswerOption[];
  units?: Units[];
  code?: Code | Code[] | null;
  required?: Boolean;
  skipLogic?: SkipLogic[];
};
```

### SubItem

```typescript
export type SubItem = ItemBase;
```

### EnableWhen

Conditions that if met, the question item is displayed. Otherwise, it is skipped and we move onto the next question.

The "in", ">", "<=" operators are commonly used.

```typescript
export type EnableWhen = {
  question: string;
  operator: "exists" | "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "notin";
  answer: any;
};
```

### UiOptions

```typescript
export type UiOptions = {
  min?: number;
  max?: number;
  interval?: number;
  length?: number;
};
```

### AnswerOption

```typescript
export type AnswerOption = {
  text: string; // Display text
  code: Code | null; // code to send back
  value: any | null; // value associated with choice; not always present
};
```

### Units

```typescript
export type Units = {
  name: string;
  text: string;
  uiOptions?: UiOptions | null;
  code: Code | null;
};
```

### Code

```typescript
export type Code = {
  code: string;
  codeSystem: string;
};
```

### SkipLogic

Conditions that if met, will result in terminating the questionnaire early and sending back responses up to this point.

```typescript
export type SkipLogic = {
  operator: "exists" | "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "notin";
  answer: any;
  skipTo: "end";
  unitName?: string;
};
```

## Questionnaire Response Schema

This is the schema that is produced by the SDK, and is sent back to the Vironix API for processing

### QuestionnaireAnswers

```typescript
export declare class QuestionnaireAnswers {
  questionnaireId: Number; // Obtained from Form.id
  questionnaire_name: string; // Obtained from Form.name
  questionnaire_version: string; // obtained from Form.version
  authored: Date; // Timestamp when submitted
  status: QuestionnaireStatus;
  items: Answer[]; // answers of the questionnaire, structured like how it is  presented within the Form
}
```

### QuestionnaireStatus

For most use-cases, please set to completed when sending back to the API.

```typescript
export declare type QuestionnaireStatus =
  | "in-progress"
  | "completed"
  | "amended"
  | "stopped"
  | "entered-in-error";
```

### Answer

```typescript
export declare class Answer {
  question: string; // from Item.linkId
  value: any;
  type: string; // from Item.type
  uiType: string | undefined; // from Item.uiType
  code?: Code | Code[] | undefined | null; // from Item.code
}
```

---
_Source: https://npm.io/package/vironix-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
