Suite de l’article « Modélisation des données pour la grille AGGIR (Autonomie Gérontologique – Groupes Iso-Ressources)« http://blog.developpez.com/sqlpro/p9425/langage-sql-norme/modelisation-des-donnees-pour-la-grille/
6 – exemple
Voici un jeu d’essai pour tester la requête et le modèle.
DELETE FROM S_PAT.T_J_AGGIR_EVALUATION_PATIENT_VALEUR_EPV
GO
DELETE FROM S_PAT.T_E_AGGIR_EVALUATION_PATIENT_EVP;
GO
DECLARE @PAT_ID INT, @EVP_ID INT;
SET @PAT_ID = 1; -- ID d'un patien pour évalutation AGGIR
INSERT INTO S_PAT.T_E_AGGIR_EVALUATION_PATIENT_EVP (PRS_ID, EVP_DATE)
VALUES (@PAT_ID, '2000-01-01');
SET @EVP_ID = SCOPE_IDENTITY();
-- variables de test pour l'évalutation
INSERT INTO S_PAT.T_J_AGGIR_EVALUATION_PATIENT_VALEUR_EPV
(EVP_ID, VBL_ID, AVB_ID, EPV_OUI) VALUES
-- Cohérence / Communication
(@EVP_ID, 2, 1, 1 ), -- Spontanément
(@EVP_ID, 2, 2, 1 ), -- Totalement
(@EVP_ID, 2, 3, 1 ), -- Correctement
(@EVP_ID, 2, 4, 1 ), -- Habituellement
-- Cohérence / Comportement
(@EVP_ID, 3, 1, 1 ), -- Spontanément
(@EVP_ID, 3, 2, 1 ), -- Totalement
(@EVP_ID, 3, 3, 1 ), -- Correctement
(@EVP_ID, 3, 4, 1 ), -- Habituellement
-- Orientation / dans le temps
(@EVP_ID, 5, 1, 0 ), -- Spontanément
(@EVP_ID, 5, 2, 0 ), -- Totalement
(@EVP_ID, 5, 3, 0 ), -- Correctement
(@EVP_ID, 5, 4, 0 ), -- Habituellement
-- Orientation / dans l'espace
(@EVP_ID, 6, 1, 0 ), -- Spontanément
(@EVP_ID, 6, 2, 0 ), -- Totalement
(@EVP_ID, 6, 3, 1 ), -- Correctement
(@EVP_ID, 6, 4, 0 ), -- Habituellement
-- Toilette / du haut
(@EVP_ID, 8, 1, 0 ), -- Spontanément
(@EVP_ID, 8, 2, 0 ), -- Totalement
(@EVP_ID, 8, 3, 0 ), -- Correctement
(@EVP_ID, 8, 4, 1 ), -- Habituellement
-- Toilette / du bas
(@EVP_ID, 9, 1, 1 ), -- Spontanément
(@EVP_ID, 9, 2, 1 ), -- Totalement
(@EVP_ID, 9, 3, 0 ), -- Correctement
(@EVP_ID, 9, 4, 0 ), -- Habituellement
-- Habillage / du haut
(@EVP_ID, 11, 1, 1 ), -- Spontanément
(@EVP_ID, 11, 2, 0 ), -- Totalement
(@EVP_ID, 11, 3, 1 ), -- Correctement
(@EVP_ID, 11, 4, 0 ), -- Habituellement
-- Habillage / moyen
(@EVP_ID, 12, 1, 1 ), -- Spontanément
(@EVP_ID, 12, 2, 0 ), -- Totalement
(@EVP_ID, 12, 3, 0 ), -- Correctement
(@EVP_ID, 12, 4, 1 ), -- Habituellement
-- Habillage / du bas
(@EVP_ID, 13, 1, 0 ), -- Spontanément
(@EVP_ID, 13, 2, 1 ), -- Totalement
(@EVP_ID, 13, 3, 1 ), -- Correctement
(@EVP_ID, 13, 4, 0 ), -- Habituellement
-- Alimentation / se servir
(@EVP_ID, 15, 1, 0 ), -- Spontanément
(@EVP_ID, 15, 2, 1 ), -- Totalement
(@EVP_ID, 15, 3, 0 ), -- Correctement
(@EVP_ID, 15, 4, 1 ), -- Habituellement
-- Alimentation / manger
(@EVP_ID, 16, 1, 0 ), -- Spontanément
(@EVP_ID, 16, 2, 0 ), -- Totalement
(@EVP_ID, 16, 3, 1 ), -- Correctement
(@EVP_ID, 16, 4, 1 ), -- Habituellement
-- Elimination / urinaire
(@EVP_ID, 18, 1, 1 ), -- Spontanément
(@EVP_ID, 18, 2, 1 ), -- Totalement
(@EVP_ID, 18, 3, 1 ), -- Correctement
(@EVP_ID, 18, 4, 0 ), -- Habituellement
-- Elimination / fecale
(@EVP_ID, 19, 1, 1 ), -- Spontanément
(@EVP_ID, 19, 2, 0 ), -- Totalement
(@EVP_ID, 19, 3, 1 ), -- Correctement
(@EVP_ID, 19, 4, 1 ), -- Habituellement
-- Transferts
(@EVP_ID, 20, 1, 0 ), -- Spontanément
(@EVP_ID, 20, 2, 1 ), -- Totalement
(@EVP_ID, 20, 3, 1 ), -- Correctement
(@EVP_ID, 20, 4, 1 ), -- Habituellement
-- Déplacements internes
(@EVP_ID, 21, 1, 1 ), -- Spontanément
(@EVP_ID, 21, 2, 1 ), -- Totalement
(@EVP_ID, 21, 3, 0 ), -- Correctement
(@EVP_ID, 21, 4, 1 ), -- Habituellement
-- Déplacement externes
(@EVP_ID, 22, 1, 0 ), -- Spontanément
(@EVP_ID, 22, 2, 0 ), -- Totalement
(@EVP_ID, 22, 3, 0 ), -- Correctement
(@EVP_ID, 22, 4, 0 ), -- Habituellement
-- Alerter (Communication)
(@EVP_ID, 23, 1, 1 ), -- Spontanément
(@EVP_ID, 23, 2, 1 ), -- Totalement
(@EVP_ID, 23, 3, 1 ), -- Correctement
(@EVP_ID, 23, 4, 1 ); -- Habituellement
GO
7 – DDL de création des tables du MPD
USE master;
GO
DROP DATABASE DB_TEST_AGGIR;
GO
CREATE DATABASE DB_TEST_AGGIR;
GO
USE DB_TEST_AGGIR
GO
CREATE TYPE D_N_ID FROM INT;
GO
CREATE TYPE D_A_LETTRE FROM CHAR(1);
go
CREATE TYPE D_X_BIN16 FROM VARBINARY(16);
go
CREATE TYPE D_A_AGGIR_MASQUALFA FROM CHAR(8);
go
CREATE TYPE D_A_MOT FROM VARCHAR(32);
GO
CREATE TYPE D_N_SI_POS FROM INT;
GO
CREATE TYPE D_A_REF_CODE FROM CHAR(8)
GO
CREATE TYPE D_A_REF_LIB FROM VARCHAR(32)
GO
CREATE TYPE D_B_BOOL FROM BIT;
GO
CREATE TYPE D_N_INTPOS FROM INT;
GO
CREATE TYPE D_A_DESC_LONGUE FROM VARCHAR(4096);
GO
CREATE TYPE D_N_REALPOS FROM FLOAT;
GO
CREATE TYPE D_A_LIB FROM VARCHAR(32);
GO
CREATE TYPE D_T_DATE FROM DATE;
GO
CREATE SCHEMA S_XMD;
GO
CREATE SCHEMA S_REF;
GO
CREATE SCHEMA S_PAT;
GO
-- Table : T_X_AGGIR_ADVERBE_AVB
create table S_XMD.T_X_AGGIR_ADVERBE_AVB (
AVB_ID D_N_ID identity,
AVB_CODE D_A_LETTRE not null,
AVB_ADVERBE D_A_MOT not null,
AVB_ORDRE D_N_SI_POS not null,
constraint PK_T_X_AGGIR_ADVERBE_AVB primary key (AVB_ID)
)
go
-- Table : T_R_AGGIR_VARIABLE_TYPE_VBT
create table S_REF.T_R_AGGIR_VARIABLE_TYPE_VBT (
VBT_ID D_N_ID identity,
VBT_CODE D_A_REF_CODE not null,
VBT_LIBELLE D_A_REF_LIB not null,
VBT_BASE D_B_BOOL not null,
VBT_ORDRE D_N_INTPOS not null,
constraint PK_T_R_AGGIR_VARIABLE_TYPE_VBT primary key (VBT_ID)
)
go
-- Table : T_X_AGGIR_VARIABLE_VBL
create table S_XMD.T_X_AGGIR_VARIABLE_VBL (
VBL_ID D_N_ID identity,
VBL_ID_MERE D_N_ID null,
VBT_ID D_N_ID not null,
VBL_NOM D_A_LIB not null,
VBL_DESCRIPTION D_A_DESC_LONGUE null,
VBL_ORDRE_APA D_N_REALPOS not null,
VBL_ORDRE_CNAMTS D_N_REALPOS not null,
VBL_RESULTAT_LETTRE_DEFAUT D_A_LETTRE null,
VBL_AIDE_SAISIE VARCHAR(max) null,
constraint PK_T_X_AGGIR_VARIABLE_VBL primary key (VBL_ID)
)
go
--Table : T_X_AGGIR_RESULTAT_VARIABLE_LETTRE_RVL
create table S_XMD.T_X_AGGIR_RESULTAT_VARIABLE_LETTRE_RVL (
RVL_ID D_N_ID identity,
VBL_ID D_N_ID not null,
RVL_MASQUE_BIN D_X_BIN16 not null,
RVL_LETTRE D_A_LETTRE not null,
constraint PK_T_X_AGGIR_RESULTAT_VARIABLE primary key (RVL_ID)
)
go
-- Index : T_J_VBL_RLT_FK
create index T_J_VBL_RLT_FK on S_XMD.T_X_AGGIR_RESULTAT_VARIABLE_LETTRE_RVL (
VBL_ID
)
go
alter table S_XMD.T_X_AGGIR_RESULTAT_VARIABLE_LETTRE_RVL
add constraint FK_RVL_VBL foreign key (VBL_ID)
references S_XMD.T_X_AGGIR_VARIABLE_VBL (VBL_ID)
go
-- Table : T_X_AGGIR_RESULTAT_GROUPE_LETTRE_RGL
create table S_XMD.T_X_AGGIR_RESULTAT_GROUPE_LETTRE_RGL (
RGL_ID D_N_ID identity,
VBL_ID D_N_ID not null,
RGL_MASQUE_ALPHA D_A_AGGIR_MASQUALFA not null,
RGL_LETTRE_GROUPE D_A_LETTRE not null,
constraint PK_T_X_AGGIR_RESULTAT_GROUPE_L primary key (RGL_ID)
)
go
-- Index : T_J_VBL_RGL_FK
create index T_J_VBL_RGL_FK on S_XMD.T_X_AGGIR_RESULTAT_GROUPE_LETTRE_RGL (
VBL_ID
)
go
alter table S_XMD.T_X_AGGIR_RESULTAT_GROUPE_LETTRE_RGL
add constraint FK_RGL_VBL foreign key (VBL_ID)
references S_XMD.T_X_AGGIR_VARIABLE_VBL (VBL_ID)
go
-- Table : T_X_AGGIR_GROUPE_AGG
create table S_XMD.T_X_AGGIR_GROUPE_AGG (
AGG_ID D_N_ID identity,
AGG_VALEUR D_A_LETTRE not null,
constraint PK_T_X_AGGIR_GROUPE_AGG primary key (AGG_ID)
)
go
-- Table : T_X_AGGIR_ALGO_AGA
create table S_XMD.T_X_AGGIR_ALGO_AGA (
AGA_ID D_N_ID identity,
AGG_ID D_N_ID not null,
VBL_ID D_N_ID not null,
AGA_LETTRE D_A_LETTRE not null,
AGA_VALEUR D_N_INTPOS not null default 0,
constraint PK_T_X_AGGIR_ALGO_AGA primary key (AGA_ID)
)
go
-- Index : T_J_AGA_VLB_FK
create index T_J_AGA_VLB_FK on S_XMD.T_X_AGGIR_ALGO_AGA (
VBL_ID
)
go
-- Index : T_J_AGA_AGG_FK
create index T_J_AGA_AGG_FK on S_XMD.T_X_AGGIR_ALGO_AGA (
AGG_ID
)
go
alter table S_XMD.T_X_AGGIR_ALGO_AGA
add constraint FK_AGA_VBL foreign key (VBL_ID)
references S_XMD.T_X_AGGIR_VARIABLE_VBL (VBL_ID)
go
alter table S_XMD.T_X_AGGIR_ALGO_AGA
add constraint FK_AGA_AGG foreign key (AGG_ID)
references S_XMD.T_X_AGGIR_GROUPE_AGG (AGG_ID)
go
-- Table : T_X_AGGIR_RANG_ARG
create table S_XMD.T_X_AGGIR_RANG_ARG (
ARG_ID D_N_ID identity,
ARG_RANG_IN D_N_SI_POS not null,
ARG_RANG_OUT D_N_SI_POS null,
ARG_LIMITE D_N_INTPOS null,
ARG_REPORT D_N_SI_POS null,
constraint PK_T_X_AGGIR_RANG_ARG primary key (ARG_ID)
)
go
-- Table : T_X_AGGIR_GIR
create table S_XMD.T_X_AGGIR_GIR (
GIR_ID D_N_ID identity,
ARG_ID D_N_ID not null,
GIR_VALEUR D_N_SI_POS not null,
constraint PK_T_X_AGGIR_GIR primary key (GIR_ID)
)
go
-- Index : T_J_ARG_GIR_FK
create index T_J_ARG_GIR_FK on S_XMD.T_X_AGGIR_GIR (
ARG_ID
)
go
alter table S_XMD.T_X_AGGIR_GIR
add constraint FK_GIR_ARG foreign key (ARG_ID)
references S_XMD.T_X_AGGIR_RANG_ARG (ARG_ID)
go
En sus, tables des évaluations :
create table S_PAT.T_E_AGGIR_EVALUATION_PATIENT_EVP (
EVP_ID D_N_ID identity,
PRS_ID D_N_ID not null,
EVP_DATE D_T_DATE not null,
EVP_GIR_VALEUR D_N_SI_POS null,
constraint PK_EVP primary key (EVP_ID)
)
go
create table S_PAT.T_J_AGGIR_EVALUATION_PATIENT_VALEUR_EPV (
EVP_ID D_N_ID not null,
AVB_ID D_N_ID not null,
VBL_ID D_N_ID not null,
EPV_OUI D_B_BOOL not null,
constraint PK_EPV primary key (EVP_ID, AVB_ID, VBL_ID)
)
go
——–
Frédéric BROUARD, Spécialiste modélisation, bases de données, optimisation, langage SQL.
Le site sur le langage SQL et les S.G.B.D. relationnels : http://sqlpro.developpez.com/
Expert SQL Server http://www.sqlspot.com : audit, optimisation, tuning, formation
* * * * * Enseignant au CNAM PACA et à l’ISEN à Toulon * * * * *