Skip to content

Commit

Permalink
refactor: study categorization and template factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimozkn committed Sep 6, 2024
1 parent d0b553a commit 0817f29
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
44 changes: 40 additions & 4 deletions core/lib/src/models/tables/study.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,15 @@ class Study extends SupabaseObjectFunctions<Study>
}

StudyType get type {
return studyType ?? StudyType.standalone;
if (templateConfiguration != null && parentTemplateId == null) {
return StudyType.template;
}

if (parentTemplateId != null) {
return StudyType.subStudy;
}

return StudyType.standalone;
}

bool get isStandalone => type == StudyType.standalone;
Expand Down Expand Up @@ -363,7 +371,37 @@ class Template extends Study {

Template.create(String userId) : super(const Uuid().v4(), userId) {
templateConfiguration = TemplateConfiguration();
studyType = StudyType.template;
}

factory Template.fromStudy(Study study) {
return Template(study.id, study.userId)
..title = study.title
..description = study.description
..participation = study.participation
..resultSharing = study.resultSharing
..contact = study.contact
..iconName = study.iconName
..status = study.status
..questionnaire = study.questionnaire
..eligibilityCriteria = study.eligibilityCriteria
..consent = study.consent
..interventions = study.interventions
..observations = study.observations
..schedule = study.schedule
..reportSpecification = study.reportSpecification
..collaboratorEmails = study.collaboratorEmails
..registryPublished = study.registryPublished
..participantCount = study.participantCount
..endedCount = study.endedCount
..activeSubjectCount = study.activeSubjectCount
..missedDays = study.missedDays
..createdAt = study.createdAt
..repo = study.repo
..invites = study.invites
..participants = study.participants
..participantsProgress = study.participantsProgress
..templateConfiguration =
study.templateConfiguration; // Make sure to include this
}
}

Expand All @@ -378,8 +416,6 @@ class TemplateSubStudy extends Study {
}
parentTemplateId = template.id;

studyType = StudyType.subStudy;

templateConfiguration = template.templateConfiguration!.copyWith(
title: template.title,
description: template.description,
Expand Down
12 changes: 9 additions & 3 deletions designer_v2/lib/features/dashboard/dashboard_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ class DashboardState extends Equatable {
case StudyType.standalone:
result.add(StudyGroup.standalone(study));
case StudyType.template:
final List<Study> subStudies =
studies.where((s) => s.parentTemplateId == study.id).toList();
result.add(StudyGroup.template(study as Template, subStudies));
final List<Study> subStudies = studies
.where((s) => s.parentTemplateId == study.id)
.map((subStudy) {
subStudy.templateConfiguration = study.templateConfiguration;
return subStudy;
}).toList();

result
.add(StudyGroup.template(Template.fromStudy(study), subStudies));
case StudyType.subStudy:
break;
}
Expand Down
2 changes: 0 additions & 2 deletions supabase/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ DECLARE
BEGIN
user_id := mockup.create_user(email, password);

-- Insert for the "template" table based on template_rows.csv
INSERT INTO "public"."template" ("id", "contact", "title", "description", "icon_name", "published", "status", "registry_published", "questionnaire", "eligibility_criteria", "observations", "interventions", "consent", "schedule", "report_specification", "results", "created_at", "updated_at", "user_id", "participation", "result_sharing", "collaborator_emails", "locked_contact", "locked_participation", "locked_schedule", "locked_registry")
VALUES (
'53446580-ad3b-452e-bb4b-094a18f27903',
Expand Down Expand Up @@ -54,7 +53,6 @@ BEGIN
true
);

-- Insert for the "study" table based on study_rows.csv
INSERT INTO "public"."study" ("id", "contact", "title", "description", "icon_name", "published", "status", "registry_published", "questionnaire", "eligibility_criteria", "observations", "interventions", "consent", "schedule", "report_specification", "results", "created_at", "updated_at", "user_id", "participation", "result_sharing", "collaborator_emails", "parent_id")
VALUES
(
Expand Down

0 comments on commit 0817f29

Please sign in to comment.