From dc1385559330c93c9666d2a2976995f97ec7a344 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Fri, 20 Dec 2019 14:32:04 -0500 Subject: [PATCH] Adds properties and validation to form --- crc/api.yml | 142 +++++++++++++++++++++++++++++++++++++++++--------- crc/models.py | 27 ++++++++-- 2 files changed, 140 insertions(+), 29 deletions(-) diff --git a/crc/api.yml b/crc/api.yml index 4d2ce056..b76bcacd 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -1,4 +1,4 @@ -openapi: "3.0.0" +openapi: "3.0.2" info: version: 1.0.0 title: Workflow Microservice @@ -369,58 +369,150 @@ components: properties: id: readOnly: true - type: integer - format: int64 + type: string name: type: string type: type: string - status: + state: type: string form: $ref: "#/components/schemas/Form" example: - { - id: study_identification, - name: "Study Identification", - state: "ready", - type: "form", - form: { - key: "oncology_form", - field: { - id: "is_adult_patient", - type: enum, - label: "Is this study treating adult oncology patients?", - options: ["yes", "no"], - value: "yes" - } - } - } + id: study_identification + name: Study Identification + type: form + state: ready + form: + "key": "irb_review_form" + "fields": + - "id": "irb_review_type" + "type": "enum" + "label": "Select IRB Review Type" + "options": + - id: "emergency_use" + name: "Emergency Use" + - id: "humanitarian_device" + name: "Humanitarian Device" + - id: "non_human" + name: "Non-Human" + - id: "non_uva_agent" + name: "Non-UVA Agent" + - id: "exempt" + name: "Exempt" + - id: "non_engaged" + name: "Non-Engaged" + - id: "expedited" + name: "Expedited" + - id: "full_board" + name: "Full Board" + "defaultValue": "Full Board" + "validation": + - name: "required" + config: "true" + "properties": + - id: "description" + value: "Description text goes here" + - id: "help" + value: "# Heading 1\n\nMarkdown help text goes here" + - id: "required_expression" + value: "model.my_boolean_field_id && model.my_enum_field_value !== 'something'" + - id: "hide_expression" + value: "model.my_enum_field_value === 'something'" Form: properties: + key: + type: string fields: type: array items: $ref: "#/components/schemas/Field" + example: + "key": "irb_review_form" + "fields": + - "id": "irb_review_type" + "type": "enum" + "label": "Select IRB Review Type" + "options": + - id: "emergency_use" + name: "Emergency Use" + - id: "humanitarian_device" + name: "Humanitarian Device" + - id: "non_human" + name: "Non-Human" + - id: "non_uva_agent" + name: "Non-UVA Agent" + - id: "exempt" + name: "Exempt" + - id: "non_engaged" + name: "Non-Engaged" + - id: "expedited" + name: "Expedited" + - id: "full_board" + name: "Full Board" + "defaultValue": "Full Board" + "validation": + - name: "required" + config: "true" + "properties": + - id: "description" + value: "Description text goes here" + - id: "help" + value: "# Heading 1\n\nMarkdown help text goes here" + - id: "required_expression" + value: "model.my_boolean_field_id && model.my_enum_field_value !== 'something'" + - id: "hide_expression" + value: "model.my_enum_field_value === 'something'" Field: properties: id: type: string readOnly: true - label: - type: string - readOnly: true type: type: enum - enum: ['text','number', 'enum'] + enum: ['string', 'long', 'boolean', 'date', 'enum'] + readOnly: true + label: + type: string readOnly: true options: type: array items: - type: string + $ref: "#/components/schemas/EnumFieldOption" readOnly: true + defaultValue: + type: string + validation: + type: array + items: + $ref: "#/components/schemas/FieldValidation" + readOnly: true + "properties": + type: array + items: + $ref: "#/components/schemas/FieldProperty" + readOnly: true + EnumFieldOption: + properties: + id: + type: string + name: + type: string + FieldValidation: + properties: + name: + type: string + config: + type: string + FieldProperty: + properties: + id: + type: string value: type: string + example: + id: "required_expression" + value: "model.should_require" Error: required: - code diff --git a/crc/models.py b/crc/models.py index a68dd6f3..2c0761d3 100644 --- a/crc/models.py +++ b/crc/models.py @@ -2,7 +2,7 @@ import enum from SpiffWorkflow import Task from flask_marshmallow.sqla import ModelSchema -from marshmallow import post_load, fields, Schema +from marshmallow import post_load, fields from marshmallow_enum import EnumField from sqlalchemy import func @@ -30,6 +30,7 @@ class StudyModel(db.Model): class StudySchema(ModelSchema): class Meta: model = StudyModel + protocol_builder_status = EnumField(ProtocolBuilderStatus) @@ -39,10 +40,12 @@ class WorkflowSpecModel(db.Model): display_name = db.Column(db.String) description = db.Column(db.Text) + class WorkflowSpecSchema(ModelSchema): class Meta: model = WorkflowSpecModel + class WorkflowStatus(enum.Enum): new = "new" user_input_required = "user_input_required" @@ -62,6 +65,7 @@ class WorkflowModel(db.Model): class WorkflowSchema(ModelSchema): class Meta: model = WorkflowModel + status = EnumField(WorkflowStatus) @@ -91,15 +95,31 @@ class OptionSchema(ma.Schema): fields = ["id", "name"] +class ValidationSchema(ma.Schema): + class Meta: + fields = ["name", "config"] + + +class PropertiesSchema(ma.Schema): + class Meta: + fields = ["id", "value"] + + class FieldSchema(ma.Schema): class Meta: - fields = ["id", "type", "label", "defaultValue", "options"] + fields = [ + "id", "type", "label", "defaultValue", "options", "validation", "properties" + ] + options = fields.List(fields.Nested(OptionSchema)) + validation = fields.List(fields.Nested(ValidationSchema)) + properties = fields.List(fields.Nested(PropertiesSchema)) class FormSchema(ma.Schema): class Meta: fields = ["key", "fields"] + fields = fields.List(fields.Nested(FieldSchema)) @@ -108,8 +128,7 @@ class TaskSchema(ma.Schema): fields = ["id", "name", "type", "state", "form"] form = fields.Nested(FormSchema) + @post_load def make_task(self, data, **kwargs): return Task(**data) - -