Files
study-tools/studies_base/models/study_study.py
2025-07-23 15:55:36 +02:00

110 lines
4.1 KiB
Python

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
from odoo import osv
from odoo.exceptions import UserError
import logging
_logger = logging.getLogger(__name__)
class StudyStudy(models.Model):
_name = "study.study"
title = fields.Char("Nom de l'étude")
name = fields.Char("Acronyme")
period_start = fields.Datetime("Début de l'étude")
period_end = fields.Datetime("Fin de l'étude")
progress_status_id = fields.Many2one(
"study.progress.status",
string="Avancement de l'étude",
domain="[('study_id', '=', id)]",
) # should be computed to actual progress status
progress_status = fields.One2many(
"study.progress.status", "study_id", "All progress status"
)
description_summary = fields.Char("Brève description de l'étude")
description = fields.Text("Description de l'étude")
keywords = fields.Many2many("study.keyword", string="Mots-clés")
primary_purpose_type = fields.Many2one(
"study.purpose.type", string="Objectif principal"
)
part_of = fields.Many2one("study.study", string="Fait partie de")
version = fields.Char("Version")
phase = fields.Many2one("study.phase", string="Phase")
status = fields.Many2one("study.status", string="Status de la publication")
site = fields.Many2one("res.partner", string="Lieu de l'étude")
identifier_author = fields.Char("ID plateforme")
identifier_primary_id = fields.Char(
"Identifiant Seintinelles", readonly=True, copy=False
)
recruitment_target_number = fields.Integer("Nombre de participants à recruter")
recruitment_max_number = fields.Integer("Nombre limite de participations")
recruitment_eligibility_gender = fields.Many2one("study.gender", string="Genre")
recruitment_eligibility_age_min = fields.Integer("Âge min")
recruitment_eligibility_age_max = fields.Integer("Âge max")
recruitment_eligibility_condition_clinical_status = fields.Many2many(
"study.eligibility.condition.clinical.status",
string="Statut de l'affectation (malade, ancien malade...)",
)
recruitment_eligibility_condition_body_site = fields.Many2many(
"study.eligibility.condition.body.site",
string="Localisation anatomique de l'affection",
)
recruitment_eligibility_study_incl = fields.Many2many(
"study.study",
"study_study_recruitment_eligibility_study_incl",
"base_study_id",
"incl_study_id",
string="Doit avoir participé aux études...",
)
recruitment_eligibility_study_excl = fields.Many2many(
"study.study",
"study_study_recruitment_eligibility_study_excl",
"base_study_id",
"excl_study_id",
string="Ne doit pas avoir participé aux études...",
)
recruitment_eligibility_description = fields.Text("Description de la cible")
recruitment_eligibility_topic = fields.Many2many(
"study.eligibility.topic", string="Thématique de recherche"
)
region = fields.Many2many("study.region", string="Zones géographiques étudiées")
note = fields.Text("Annotations")
created = fields.Datetime(
"Created", readonly=True, compute="_compute_created", store=True
)
updated = fields.Datetime(
"Updated", readonly=True, compute="_compute_updated", store=True
)
@api.depends("create_date")
def _compute_created(self):
for record in self:
if not record.created:
record.created = record.create_date
@api.depends("write_date")
def _compute_updated(self):
for record in self:
_logger.info(f"Record ID: {record.id}, write_date: {record.write_date}")
record.updated = record.write_date
active = fields.Boolean("Actif", default=True)
def copy(self, default=None):
default = dict(default or {}, identifier_primary_id=None)
return super().copy(default)
@api.depends("title", "name")
def name_get(self):
if not self.name:
return [(study.id, study.title) for study in self]
return [(study.id, f"[{study.name}] {study.title}") for study in self]