Adds properties and validation to form

This commit is contained in:
Aaron Louie 2019-12-20 14:32:04 -05:00
parent 8672a88116
commit dc13855593
2 changed files with 140 additions and 29 deletions

View File

@ -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

View File

@ -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)