Clinical form templates give ClinicFlow a schema-driven extensibility point: instead of hardcoding specialty-specific fields, an administrator defines aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/0Crazy-0/ClinicFlow/llms.txt
Use this file to discover all available pages before exploring further.
ClinicalFormTemplate with a JSON Schema definition. The template is then attached to one or more AppointmentTypeDefinition entities as a required form. When a doctor completes an encounter, the system validates every submitted DynamicClinicalDetail payload against its template’s schema before the record is saved.
The ClinicalFormTemplate Entity
ClinicalFormTemplate extends SoftDeletableEntity, so deactivation uses the same soft-delete pattern as doctors — the record remains in the database but is filtered out of active queries.
| Field | Type | Constraints |
|---|---|---|
Code | string | Required; unique; no public setter — treated as immutable after creation |
Name | string | Required; unique |
Description | string | Optional |
JsonSchemaDefinition | string | Must be valid JSON Schema draft-07; defaults to "{}" |
The
Code field is a natural key — it is what IClinicalDetailRecord.TemplateCode references. Once a template is used in a medical record, changing its Code would orphan those historical records. The field has a private set accessor; it is set once by ClinicalFormTemplate.Create and no public mutation method exposes it afterward.How Templates Are Attached to Appointment Types
Templates become mandatory for an appointment type through two application-layer commands:AddRequiredTemplateToAppointmentType— associates aClinicalFormTemplate(byTemplateId) with anAppointmentTypeDefinition. From that point forward, everyCompleteMedicalEncounterrequest for that appointment type must include aDynamicClinicalDetailDtowhoseTemplateCodematches the attached template.RemoveRequiredTemplateFromAppointmentType— detaches the template, making it optional for future encounters (historical records are unaffected).
MetadataFormValidationPolicy (an IMedicalRecordValidationPolicy implementation) iterates over AppointmentTypeDefinition.RequiredTemplates and verifies that the submitted Details list contains an entry for every required template code.
Schema Validation Interfaces
Two distinct interfaces guard the schema at different lifecycle stages.IJsonSchemaDefinitionValidator
Used at template creation time (inCreateClinicalFormTemplateCommandValidator) to verify that the JsonSchemaDefinition string itself is a structurally valid JSON Schema. The implementation lives in the Infrastructure layer.
IJsonSchemaValidator
Used at encounter time (inMedicalEncounterService.AppendClinicalDetail) to validate a submitted JSON data payload against a stored schema.
Commands
CreateClinicalFormTemplate
Guid — the new ClinicalFormTemplate.Id.
The handler checks for duplicate Code and Name before creating the entity. CreateClinicalFormTemplateCommandValidator calls IJsonSchemaDefinitionValidator.IsValidSchema to reject malformed schemas before the command even reaches the handler.
If JsonSchemaDefinition is null or whitespace, the domain falls back to "{}" (an empty schema that accepts any JSON object).
UpdateClinicalFormTemplate
UpdatesName, Description, and JsonSchemaDefinition for an existing template. The Code is not updatable.
ClinicalFormTemplate.UpdateDetails(name, description) and ClinicalFormTemplate.UpdateSchema(jsonSchemaDefinition) separately, so each can throw its own validation error.
DeactivateClinicalFormTemplate
Soft-deletes the template so it no longer appears in active queries. ThrowsAlreadyInactive if the template is already deactivated.
ReactivateClinicalFormTemplate
Restores a soft-deleted template. ThrowsAlreadyActive if the template is currently active.
Queries
GetClinicalFormTemplateByCode
Fetches a single template by its natural keyCode. This is the query used internally by AddClinicalDetailToMedicalRecordCommandHandler to load the schema for validation.
GetAllActiveClinicalFormTemplates
Returns every non-soft-deleted template. Intended for admin UIs and frontend form builders.ClinicalFormTemplateDto
Example JSON Schema
The following accordion shows a completeJsonSchemaDefinition for a simple blood-pressure template. The frontend uses this schema to render the form; the backend uses it to validate submitted payloads via IJsonSchemaValidator.
Example: BLOOD_PRESS template schema (JSON Schema draft-07)
Example: BLOOD_PRESS template schema (JSON Schema draft-07)
DynamicClinicalDetail.JsonDataPayload submitted during an encounter would look like:"systolic": 400) throws a BusinessRuleValidationException with the specific validation error message returned by IJsonSchemaValidator.Both
IJsonSchemaDefinitionValidator and IJsonSchemaValidator explicitly target the JSON Schema draft-07 specification. Infrastructure implementations (e.g., using NJsonSchema or JsonSchema.Net) must conform to draft-07 semantics. Using a different draft may cause silent validation discrepancies.Soft-Delete and Lifecycle
- Active
- Deactivated
- Reactivated
Templates with
IsDeleted = false appear in GetAllActiveClinicalFormTemplates and can be attached to appointment types. New DynamicClinicalDetail entries can reference their Code.