WizarDoc
about
WizarDoc is a document-generation workflow tool for clinical study teams, developed as part of the EU GREG project. It addresses a largely manual, untooled process: research teams must answer long, structured questionnaires and produce standardized Word documents from those answers, traditionally via copy-paste workflows. WizarDoc replaces this with a structured wizard interface where users answer questions one at a time, and the system generates a populated DOCX file from a pre-defined template.
The application is organized around four entities: a Study acts as the top-level project container linking to a question pool and collaborators; a QuestionPool is a named, reusable collection of questions paired with an attached DOCX template defining the output format; a Question carries its text, metadata, and an optional table type for structured tabular answers; and an Assessment is an instance of answering a question pool within a study, tracking progress, status, answers, and answer provenance. Every answer is tagged as user-written, AI-generated, or AI-generated-then-edited, supporting auditability in regulated clinical contexts.
The system ships as two FastAPI services behind a Next.js 16 (React 19, TypeScript, Tailwind, Radix UI) frontend, orchestrated behind an Nginx reverse proxy, with MongoDB as the data store. The main API provides CRUD for studies, question pools, and assessments, DOCX template upload and download, and an optimistic locking system for concurrent editing: assessments can be locked, renewed, and released, with conflicting updates returning HTTP 423 and the current lock owner's details.
DOCX generation is the most technically involved component. For a given assessment, the system resolves the study and question pool, builds multiple parallel answer lookup maps (by question ID, by identifier, and by sanitized template-variable name), handles table-type questions by parsing their JSON answers into row lists for Jinja2 table iteration, assembles a flat rendering context, and renders the populated document via docxtpl, returning it as a downloadable file. This approach lets non-technical study coordinators design output documents directly in Microsoft Word using Jinja2 template syntax.
A separate AI assistance microservice provides Retrieval-Augmented Generation (RAG) based answer suggestions via a local Ollama LLM (llama3.1:8b with nomic-embed-text embeddings). Users can create a session, upload reference documents (PDF, DOCX, or text), which are parsed and chunked with overlapping windows and embedded for retrieval. When requesting a suggestion for a question, the service embeds the query, retrieves the most relevant document chunks by cosine similarity, and constructs a prompt incorporating the question, retrieved context, study context, and prior answers in the assessment. The response is streamed via Server-Sent Events as structured JSON containing ranked suggestions with rationale and source attribution, and if the user has a draft answer, suggestions are constrained to refine it. Idle sessions are cleaned up automatically after two hours.
The full stack is containerized with Docker Compose and Nginx, with a development configuration using a hardcoded user requiring no external identity provider, and a production configuration integrating Keycloak for authentication and role-based access control. WizarDoc underlies two research papers: "An AI-Driven Document Builder for Standardized Clinical Studies" (IEEE CBMS 2026) and "A Web Assistant for Risk Analysis Reliability in Observational Studies" (MIE/EFMI 2026).
highlights
- ·Designed and implemented the full stack (FastAPI/MongoDB backend, Next.js/React frontend) covering project, question pool, and assessment management with DOCX generation via docxtpl
- ·Built a Retrieval-Augmented Generation (RAG) pipeline using a local Ollama LLM to power AI-driven answer suggestions with response provenance tracking
- ·Implemented optimistic document-level session locking for collaborative authoring, with automatic release on inactivity
- ·Published in two papers: IEEE CBMS 2026 and MIE/EFMI 2026, with production deployment via Docker Compose, Nginx, and Keycloak
stack
Backend
Frontend
AI
Infrastructure