1.1.0 • Published 9 months ago

vironix-schema v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

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:

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

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

Item

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

ItemBase

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

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.

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

UiOptions

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

AnswerOption

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

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

Code

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.

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

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.

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

Answer

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
}
1.1.0

9 months ago