This document describes the structure of document context provided by the Document Worker to the Jinja templates. Currently, the root object of DocumentContext must be created like this:
{%- set x = ctx|to_context_obj -%}
- All data types are using Python, e.g.,
str
is textual string,Optional[str]
is a string orNone
,list[str]
is a list of strings. - We use
snake_case
for naming of attributes and variables,PascalCase
is used for class names. datetime
is the standarddatetime.datetime
.- You can investigate the
context
module; however, constructs that are not documented here may change in any version without an explicit notice.
We provide the structure visualized on a class diagram: SVG.
Here is an interlinked description of each entity and its attributes and links. There are also aliases that are convenient shorthands to make template more concise.
config
(ContextConfig
)current_phase
(Optional[
Phase
]
)document
(Document
)km
(KnowledgeModel
)organization
(Organization
)package
(Package
)questionnaire
(Questionnaire
)report
(Report
)
Aliases:
e
(KnowledgeModelEntities
) - same askm.entities
doc
(Document
) - same asdocument
org
(Organization
) - same asorganization
pkg
(Package
) - same aspackage
qtn
(Questionnaire
) - same asquestionnaire
replies
(RepliesContainer
) - same asquestionnaire.replies
client_url
(str
) - base URL of the DSW instance (client app)
uuid
(str
)created_at
(datetime
)updated_at
(datetime
)
id
(str
)name
(str
)description
(Optional[str]
)affiliations
(list[str]
)
id
(str
) - full ID of KM Packageorganization_id
(str
)km_id
(str
)version
(str
)versions
(list[str]
)name
(str
)description
(Optional[str]
)created_at
(datetime
)
uuid
(str
)name
(str
)version
(Optional[
QuestionnaireVersion
]
)versions
(list[
QuestionnaireVersion
]
)phase
(Optional[
Phase
]
)replies
(RepliesContainer
)created_by
(User
)
uuid
(str
)event_uuid
(str
)name
(str
)description
(Optional[str]
)created_by
(SimpleAuthor
)created_at
(datetime
)updated_at
(datetime
)
uuid
(str
)first_name
(str
)last_name
(str
)email
(str
)role
(str
) - one of:admin
,dataSteward
,researcher
image_url
(Optional[str]
)affiliation
(Optional[str]
)permissions
(list[str]
)sources
(list[str]
)created_at
(datetime
)updated_at
(datetime
)
uuid
(str
)first_name
(str
)last_name
(str
)image_url
(Optional[str]
)gravatar_hash
(Optional[str]
)
uuid
(str
)total_report
(ReportItem
)chapter_reports
(list[
ReportItem
]
)created_at
(datetime
)updated_at
(datetime
)
indications
(list[
ReportIndication
]
)metrics
(list[
ReportMetric
]
)chapter
(Optional[
Chapter
]
) - set if it is a chapter report
indication_type
(str
) - one of:PhasesAnsweredIndication
,AnsweredIndication
(use alias)answered
(int
) - number of answered questionsunanswered
(int
) - number of unanswered questions
Aliases:
total
(int
) -answered
+unanswered
percentage
(float
) -answered
/total
(handles zero division, number between0.0
and1.0
)is_for_phase
(bool
) - if it is a phase-related indicationis_overall
(bool
) - if it is an overall indication (not phase-related)
measure
(float
) - number between0.0
and1.0
metric
(Metric
)
uuid
(str
)annotations
(dict[str,str]
)entities
(KnowledgeModelEntities
)chapters
(list[
Chapter
]
)integrations
(list[
Integration
]
)metrics
(list[
Metric
]
)phases
(list[
Phase
]
)tags
(list[
Tag
]
)
Aliases:
e
(KnowledgeModelEntities
) - same asentities
a
(dict[str,str]
) - same asannotations
💡 Equality of all KM entities is being done using the uuid
comparison under the hood.
💡 All KM entities that have annotations
have also the a
alias.
Container holding all types of Knowledge Model entities within UUID-key dictionaries:
answers
(dict[str,
Answer
]
)chapter
(dict[str,
Chapter
]
)choices
(dict[str,
Choice
]
)experts
(dict[str,
Expert
]
)integrations
(dict[str,
Integration
]
)metrics
(dict[str,
Metric
]
)phases
(dict[str,
Phase
]
)questions
(dict[str,
Question
]
)references
(dict[str,
Reference
]
)tags
(dict[str,
Tag
]
)
uuid
(str
)title
(str
)text
(Optional[str]
) - possibly Markdown textquestions
(list[
Question
]
)reports
(list[
ReportItem
]
)annotations
(dict[str,str]
)
Superclass with common attributes for all types of questions. You always get a more specific one and never just a Question
.
uuid
(str
)type
(str
)title
(str
)text
(Optional[str]
)required_phase
(Optional[
Phase
]
)is_required
(bool
) - if the question is required in the current phasereplies
(dict[str,
Reply
]
) - path-key dictionary of replies to the questionexperts
(list[
Expert
]
)references
(list[
Reference
]
)tags
(list[
Tag
]
)parent
(Union[
Chapter
,
ListQuestion
,
Answer
]
)annotations
(dict[str,str]
)
Aliases:
url_references
(list[
URLReference
]
)resource_page_references
(list[
ResourcePageReference
]
)
💡 Parent of a question can be of multiple kinds, you may use the of_type
test to check what it is if needed.
value_type
(str
) - type of value, use alias
Aliases:
is_string
(bool
)is_text
(bool
)is_number
(bool
)is_date
(bool
)
integration
(Integration
)props
(dict[str,str]
)
answers
(list[
Answer
]
)
choices
(list[
Choice
]
)
followups
(list[
Question
]
)
uuid
(str
)label
(str
)advice
(Optional[str]
) - possibly Markdown textmetric_measures
(list[
MetricMeasure
]
)followups
(list[
Question
]
)parent
(OptionsQuestion
)annotations
(dict[str,str]
)
Indication of how an answer affects a certain metric.
measure
(float
) - value between0.0
and1.0
(inclusive)weight
(float
) - value between0.0
and1.0
(inclusive)metric
(Metric
)
uuid
(str
)label
(str
)parent
(MultiChoiceQuestion
)annotations
(dict[str,str]
)
uuid
(str
)name
(str
)email
(str
)annotations
(dict[str,str]
)
As for the Question
class, Reference
is also a superclass and you will always get an object of its subclass.
uuid
(str
)type
(str
)annotations
(dict[str,str]
)
label
(str
)url
(str
)
short_uuid
(str
)url
(str
) - URL composed usingclient_url
fromContextConfig
uuid
(str
)title
(str
)abbreviation
(str
)description
(Optional[str]
) - possibly Markdown textannotations
(dict[str,str]
)
uuid
(str
)title
(str
)description
(Optional[str]
) - possibly Markdown textorder
(int
) - order of the phase within the KMannotations
(dict[str,str]
)
uuid
(str
)id
(str
)name
(str
)item_url
(str
)logo
(str
)props
(dict[str,str]
)rq_method
(str
)rq_url
(str
)rq_headers
(dict[str,str]
)rq_body
(str
)rs_list_field
(str
)rs_item_id
(str
)rs_item_template
(str
)annotations
(dict[str,str]
)
Operations:
item(item_id: str) -> str
- URL of an item identified by string ID
uuid
(str
)name
(str
)description
(Optional[str]
) - possibly Markdown textcolor
(str
)annotations
(dict[str,str]
)
Wrapper around a path-key dictionary of replies.
replies
(dict[str,
Reply
]
)
Operations:
X[path: str]
(Optional[
Reply
]
) - you can get a reply using square bracketslen(X)
(int
) - number of replies in the containerget(path: str) -> Optional[
Reply
]
iterate_by_prefix(path_prefix: str) -> Iterable[
Reply
]
- O(n) iteration with filteriterate_by_suffix(path_suffix: str) -> Iterable[
Reply
]
- O(n) iteration with filtervalues() -> Iterable[
Reply
]
keys() -> Iterable[str]
items() -> ItemsView[str,
Reply
]
Superclass with common attributes for all types of replies. You always get a more specific one and never just a Reply
.
path
(str
)fragments
(list[str]
) - UUIDs of the path (starting with chapter)type
(str
)created_at
(datetime
)created_by
(SimpleAuthor
)question
(Question
) - you can assume more specific type ofQuestion
based on a type ofReply
answer
(Answer
) - selected answer as the option
Aliases:
value
(str
) - UUID of the answer (answer.uuid
)
💡 question
is always OptionsQuestion
choices
(list[
Choice
]
) - selected answer as the option
Aliases:
value
(list[str]
) - list of UUIDs of the choices
💡 question
is always OptionsQuestion
💡 You can iterate directly over reply object (for choice in reply
)
value
(str
)
Aliases:
as_number
(Optional[float]
) - tries to cast the value to a numberas_datetime
(Optional[datetime]
) - tries to cast the value to a timestamp
💡 question
is always ValueQuestion
items
(list[str]
) - list of item UUIDs (used in reply paths)
Aliases:
value
(list[str]
) - same asitems
💡 question
is always ListQuestion
💡 You can iterate directly over reply object (for item in reply
)
value
(str
)item_id
(item_id
) - ID of item if selected usingIntegration
Aliases:
id
(str
) - same asitem_id
is_plain
(bool
) - entered by user ignoring the integrationis_integration
(bool
) - selected by user using the integrationurl
(Optional[str]
) - item URL basedIntegration
if selected from it
TBD
- The variable
ctx
is still the JSON-like document context provided from DSW described by the JSON Schema; fromv3.6.0
that will be changed andctx
will be an object ofDocumentContext
. For compatibility, the plain context will be also supplied with other name. - For deprecation warnings, search for
DEPRECATED
in this document. - If you think that something useful is missing in the context or its documentation, please let us know.
This document has been last revised for DSW Document Worker v3.4.0.