c2-clinical 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare const MET_ACTIVITIES = "${MET_ACTIVITIES}";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MET_ACTIVITIES = void 0;
4
+ exports.MET_ACTIVITIES = "${MET_ACTIVITIES}";
@@ -0,0 +1,7 @@
1
+ import { IFormUnit } from "../../models/form/FormUnit";
2
+ import { IAnswer } from "../../models/IAnswer";
3
+ declare class GroupFormUnitsFlow {
4
+ execute(formUnits: IFormUnit[], answers: IAnswer[]): IFormUnit[];
5
+ }
6
+ declare const _default: GroupFormUnitsFlow;
7
+ export default _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BuildTreeFlowItem_1 = __importDefault(require("./item/BuildTreeFlowItem"));
7
+ const GetEnablesFormUnitsFlowItem_1 = __importDefault(require("./item/GetEnablesFormUnitsFlowItem"));
8
+ class GroupFormUnitsFlow {
9
+ execute(formUnits, answers) {
10
+ const questionsEnableds = GetEnablesFormUnitsFlowItem_1.default.execute(formUnits, answers);
11
+ const questionsWithOrganizedChilds = BuildTreeFlowItem_1.default.execute(questionsEnableds);
12
+ // const questionsGrouped = GroupListFlowItem.exec(questionsWithOrganizedChilds, "reference.group._id", "reference.group")
13
+ // const groups = BuildGroupsDTOFlow.exec(questionsGrouped, questionsAnswereds);
14
+ return questionsWithOrganizedChilds;
15
+ }
16
+ }
17
+ exports.default = new GroupFormUnitsFlow();
@@ -0,0 +1,7 @@
1
+ import { IFormUnit } from "../../../models/form/FormUnit";
2
+ declare class BuildTreeFlowItem {
3
+ execute(questions: IFormUnit[]): IFormUnit[];
4
+ private iterate;
5
+ }
6
+ declare const _default: BuildTreeFlowItem;
7
+ export default _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class BuildTreeFlowItem {
4
+ execute(questions) {
5
+ //extrai os elements raiz (sem parent)
6
+ const rootFormUnit = questions
7
+ .filter((q) => !q.parent)
8
+ .map((q) => {
9
+ return {
10
+ ...q,
11
+ children: []
12
+ };
13
+ });
14
+ //extrai os elements que tem algum parent
15
+ const children = questions.filter((q) => !!q.parent);
16
+ rootFormUnit?.forEach((q) => {
17
+ this.iterate(q, children);
18
+ });
19
+ return rootFormUnit;
20
+ }
21
+ iterate(parent, children) {
22
+ parent.children = children.filter((child) => child.parent.toString() === parent._id.toString());
23
+ parent.children.sort((a, b) => a.line - b.line);
24
+ if (parent.children.length > 0) {
25
+ parent.children.forEach((parentPossible) => {
26
+ this.iterate(parentPossible, children);
27
+ });
28
+ }
29
+ }
30
+ }
31
+ exports.default = new BuildTreeFlowItem();
@@ -0,0 +1,7 @@
1
+ import { IFormUnit } from "../../../models/form/FormUnit";
2
+ import { IAnswer } from "../../../models/IAnswer";
3
+ declare class GetEnablesFormUnitsFlowItem {
4
+ execute(formUnits: IFormUnit[], answers: IAnswer[]): IFormUnit[];
5
+ }
6
+ declare const _default: GetEnablesFormUnitsFlowItem;
7
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BuildFormulaFlowItem_1 = __importDefault(require("../../item/BuildFormulaFlowItem"));
7
+ const ExecFormulaFlowItem_1 = __importDefault(require("../../item/ExecFormulaFlowItem"));
8
+ class GetEnablesFormUnitsFlowItem {
9
+ execute(formUnits, answers) {
10
+ return formUnits?.filter((unit) => {
11
+ if (!unit.show)
12
+ return false;
13
+ if (!unit.active)
14
+ return false;
15
+ if (!unit.formulaToEnable)
16
+ return true;
17
+ //MONTAGEM DA FORMULA COM OS VALORES
18
+ let formulaToEnable = unit.formulaToEnable;
19
+ formulaToEnable = BuildFormulaFlowItem_1.default.execute(answers, formulaToEnable ?? "");
20
+ //TENTAR EXECUTAR A FORMULA
21
+ let enable = false;
22
+ enable = ExecFormulaFlowItem_1.default.exec(false, formulaToEnable);
23
+ return enable;
24
+ });
25
+ }
26
+ }
27
+ exports.default = new GetEnablesFormUnitsFlowItem();
@@ -0,0 +1,7 @@
1
+ import { IAnswer } from "../../models/IAnswer";
2
+ import { IMetActivityPatient } from "../../models/met-activity/IMetActivityPatient";
3
+ declare class BuildFormulaFlowItem {
4
+ execute(answers: IAnswer[], formula: string, metsActivities?: IMetActivityPatient[], replaceDefault?: string): string;
5
+ }
6
+ declare const _default: BuildFormulaFlowItem;
7
+ export default _default;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BuildFormulaMetsFlowItem_1 = __importDefault(require("./BuildFormulaMetsFlowItem"));
7
+ class BuildFormulaFlowItem {
8
+ execute(answers, formula, metsActivities, replaceDefault) {
9
+ if (!formula) {
10
+ console.error("formula is undefined");
11
+ return formula;
12
+ }
13
+ const formulaBefore = formula;
14
+ const matches = formula.match(/\$\{(?!\{)([^}]+)\}/g) ?? []; // padrao regex: ${ANYTHING}
15
+ const variables = [...new Set(matches)];
16
+ for (const variable of variables) {
17
+ const variablePure = variable.match(/\$\{([^}]+)\}/) ?? [];
18
+ const questionAnswered = answers.find((a) => a.reference.code === variablePure[1]);
19
+ if (questionAnswered?.answer !== undefined && questionAnswered?.answer !== "") {
20
+ formula = formula.replaceAll(variable, questionAnswered?.answer);
21
+ }
22
+ if (formula.includes(variable) && replaceDefault) {
23
+ formula = formula.replaceAll(variable, replaceDefault);
24
+ }
25
+ }
26
+ formula = formula.replaceAll(/\$\{\{([^}]+)\}\}/g, (_, match) => `\$\{${match}\}`);
27
+ if (metsActivities) {
28
+ formula = BuildFormulaMetsFlowItem_1.default.exec(answers, formula, metsActivities);
29
+ }
30
+ if (formula !== formulaBefore) {
31
+ return this.execute(answers, formula, metsActivities, replaceDefault);
32
+ }
33
+ return formula;
34
+ }
35
+ }
36
+ exports.default = new BuildFormulaFlowItem();
@@ -0,0 +1,7 @@
1
+ import { IAnswer } from "../../models/IAnswer";
2
+ import { IMetActivityPatient } from "../../models/met-activity/IMetActivityPatient";
3
+ declare class BuildFormulaMetsFlowItem {
4
+ exec(answers: IAnswer[], formula: string, metsActivities: IMetActivityPatient[]): string;
5
+ }
6
+ declare const _default: BuildFormulaMetsFlowItem;
7
+ export default _default;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const const_1 = require("../../config/const");
4
+ class BuildFormulaMetsFlowItem {
5
+ exec(answers, formula, metsActivities) {
6
+ if (!formula) {
7
+ return formula;
8
+ }
9
+ if (!formula.includes(const_1.MET_ACTIVITIES)) {
10
+ return formula;
11
+ }
12
+ const matches = formula.match(/\$\{([^}]+)\}/g) ?? []; // padrao regex: ${ANYTHING}
13
+ const variables = [...new Set(matches)];
14
+ for (const variable of variables) {
15
+ const variablePure = variable.match(/\$\{([^}]+)\}/) ?? [];
16
+ const questionAnswered = answers.find((aq) => aq.reference.code === variablePure[1]);
17
+ if (questionAnswered?.answer !== undefined && questionAnswered?.answer !== "") {
18
+ formula = formula.replaceAll(variable, questionAnswered?.answer);
19
+ }
20
+ }
21
+ if (formula.includes(const_1.MET_ACTIVITIES)) {
22
+ const metsActivitiesAux = metsActivities?.map((ma) => {
23
+ return {
24
+ met: { metValue: ma.met.metValue },
25
+ sundayTime: ma.sundayTime,
26
+ sundayTimeCoefficient: ma.sundayTimeCoefficient,
27
+ mondayTime: ma.mondayTime,
28
+ mondayTimeCoefficient: ma.mondayTimeCoefficient,
29
+ tuesdayTime: ma.tuesdayTime,
30
+ tuesdayTimeCoefficient: ma.tuesdayTimeCoefficient,
31
+ wednesdayTime: ma.wednesdayTime,
32
+ wednesdayTimeCoefficient: ma.wednesdayTimeCoefficient,
33
+ thursdayTime: ma.thursdayTime,
34
+ thursdayTimeCoefficient: ma.thursdayTimeCoefficient,
35
+ fridayTime: ma.fridayTime,
36
+ fridayTimeCoefficient: ma.fridayTimeCoefficient,
37
+ saturdayTime: ma.saturdayTime,
38
+ saturdayTimeCoefficient: ma.saturdayTimeCoefficient
39
+ };
40
+ });
41
+ formula = formula.replaceAll(const_1.MET_ACTIVITIES, JSON.stringify(metsActivitiesAux).replace(/"/g, "'"));
42
+ }
43
+ return formula;
44
+ }
45
+ }
46
+ exports.default = new BuildFormulaMetsFlowItem();
@@ -0,0 +1,5 @@
1
+ declare class ExecFormulaFlowItem {
2
+ exec(defaultResult: any, formula: string): any;
3
+ }
4
+ declare const _default: ExecFormulaFlowItem;
5
+ export default _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ExecFormulaFlowItem {
4
+ exec(defaultResult, formula) {
5
+ let result = defaultResult;
6
+ try {
7
+ result = eval(formula);
8
+ }
9
+ catch (error) {
10
+ result = defaultResult;
11
+ }
12
+ return result;
13
+ }
14
+ }
15
+ exports.default = new ExecFormulaFlowItem();
@@ -0,0 +1,8 @@
1
+ import { IFormUnit, IRequestGraphicData, IValidationQuestion } from "./form/FormUnit";
2
+ import { IDefault } from "./IDefault";
3
+ export interface IAnswer extends IDefault {
4
+ reference: IFormUnit;
5
+ validations: IValidationQuestion[];
6
+ requestGraphicData: IRequestGraphicData[];
7
+ answer: any;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ import { Types } from "mongoose";
2
+ import { IFormUnit } from "./form/FormUnit";
3
+ export interface IGroup {
4
+ _id: undefined | string | Types.ObjectId;
5
+ line: number;
6
+ description: undefined | string;
7
+ lines: ILineQuestionsOrGroup[];
8
+ type: "GROUP";
9
+ groupOrigin?: IFormUnit;
10
+ }
11
+ export interface ILineQuestionsOrGroup {
12
+ line: number;
13
+ type: "GROUP" | "QUESTIONS";
14
+ questions?: (IFormUnit & {
15
+ childs: IGroup[];
16
+ })[];
17
+ group?: IGroup;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -92,6 +92,7 @@ export interface IFormUnit extends IDefault {
92
92
  required: boolean;
93
93
  graphicData: any;
94
94
  requestGraphicData: IRequestGraphicData[];
95
+ children?: IFormUnit[];
95
96
  }
96
97
  export interface IQuestionOption {
97
98
  sequence: number;
@@ -0,0 +1,13 @@
1
+ import { IDefaultAdmin } from "../IDefault";
2
+ export declare enum MetTargetCondition {
3
+ ADULT = "ADULT",
4
+ OLD_ADULT = "OLD_ADULT",
5
+ WHEELCHAIR = "WHEELCHAIR"
6
+ }
7
+ export interface IMetActivity extends IDefaultAdmin {
8
+ activityName: string;
9
+ activityDescription: string;
10
+ activityCode: string;
11
+ metValue: number;
12
+ targetCondition: MetTargetCondition;
13
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetTargetCondition = void 0;
4
+ var MetTargetCondition;
5
+ (function (MetTargetCondition) {
6
+ MetTargetCondition["ADULT"] = "ADULT";
7
+ MetTargetCondition["OLD_ADULT"] = "OLD_ADULT";
8
+ MetTargetCondition["WHEELCHAIR"] = "WHEELCHAIR";
9
+ })(MetTargetCondition || (exports.MetTargetCondition = MetTargetCondition = {}));
@@ -0,0 +1,20 @@
1
+ import { IDefault } from "../IDefault";
2
+ import { IMetActivity } from "./IMetActivity";
3
+ export interface IMetActivityPatient extends IDefault {
4
+ patient: string;
5
+ met: IMetActivity;
6
+ sundayTime: string;
7
+ sundayTimeCoefficient: number;
8
+ mondayTime: string;
9
+ mondayTimeCoefficient: number;
10
+ tuesdayTime: string;
11
+ tuesdayTimeCoefficient: number;
12
+ wednesdayTime: string;
13
+ wednesdayTimeCoefficient: number;
14
+ thursdayTime: string;
15
+ thursdayTimeCoefficient: number;
16
+ fridayTime: string;
17
+ fridayTimeCoefficient: number;
18
+ saturdayTime: string;
19
+ saturdayTimeCoefficient: number;
20
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +1,8 @@
1
1
  import { Schema, Types } from "mongoose";
2
- import { IFormUnit, IValidationQuestion, IRequestGraphicData } from "../form/FormUnit";
3
- import { IDefault } from "../IDefault";
2
+ import { IAnswer } from "../IAnswer";
4
3
  import { IQPC } from "./QPC";
5
- export interface IQPCAnswer extends IDefault {
4
+ export interface IQPCAnswer extends IAnswer {
6
5
  qpc: Types.ObjectId | IQPC;
7
- reference: Types.ObjectId | IFormUnit;
8
- answer: any;
9
- messages: IValidationQuestion[];
10
- requestGraphicData: IRequestGraphicData[];
11
6
  }
12
7
  export declare const QPCAnswerSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
13
8
  timestamps: {
@@ -17,6 +12,19 @@ export declare const QPCAnswerSchema: Schema<any, import("mongoose").Model<any,
17
12
  }, {} & {
18
13
  account: any;
19
14
  reference: any;
15
+ validations: Types.DocumentArray<{
16
+ type: string;
17
+ typeOutput: string;
18
+ formulaToMessage: string;
19
+ }, Types.Subdocument<Types.ObjectId, any, {
20
+ type: string;
21
+ typeOutput: string;
22
+ formulaToMessage: string;
23
+ }> & {
24
+ type: string;
25
+ typeOutput: string;
26
+ formulaToMessage: string;
27
+ }>;
20
28
  requestGraphicData: Types.DocumentArray<{
21
29
  url: string;
22
30
  method: string;
@@ -34,26 +42,23 @@ export declare const QPCAnswerSchema: Schema<any, import("mongoose").Model<any,
34
42
  dataset?: any;
35
43
  }>;
36
44
  qpc: any;
37
- messages: Types.DocumentArray<{
38
- type?: string | null | undefined;
39
- content?: string | null | undefined;
40
- formula?: string | null | undefined;
41
- typeContent?: string | null | undefined;
42
- }, Types.Subdocument<Types.ObjectId, any, {
43
- type?: string | null | undefined;
44
- content?: string | null | undefined;
45
- formula?: string | null | undefined;
46
- typeContent?: string | null | undefined;
47
- }> & {
48
- type?: string | null | undefined;
49
- content?: string | null | undefined;
50
- formula?: string | null | undefined;
51
- typeContent?: string | null | undefined;
52
- }>;
53
45
  answer?: any;
54
46
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{} & {
55
47
  account: any;
56
48
  reference: any;
49
+ validations: Types.DocumentArray<{
50
+ type: string;
51
+ typeOutput: string;
52
+ formulaToMessage: string;
53
+ }, Types.Subdocument<Types.ObjectId, any, {
54
+ type: string;
55
+ typeOutput: string;
56
+ formulaToMessage: string;
57
+ }> & {
58
+ type: string;
59
+ typeOutput: string;
60
+ formulaToMessage: string;
61
+ }>;
57
62
  requestGraphicData: Types.DocumentArray<{
58
63
  url: string;
59
64
  method: string;
@@ -71,26 +76,23 @@ export declare const QPCAnswerSchema: Schema<any, import("mongoose").Model<any,
71
76
  dataset?: any;
72
77
  }>;
73
78
  qpc: any;
74
- messages: Types.DocumentArray<{
75
- type?: string | null | undefined;
76
- content?: string | null | undefined;
77
- formula?: string | null | undefined;
78
- typeContent?: string | null | undefined;
79
- }, Types.Subdocument<Types.ObjectId, any, {
80
- type?: string | null | undefined;
81
- content?: string | null | undefined;
82
- formula?: string | null | undefined;
83
- typeContent?: string | null | undefined;
84
- }> & {
85
- type?: string | null | undefined;
86
- content?: string | null | undefined;
87
- formula?: string | null | undefined;
88
- typeContent?: string | null | undefined;
89
- }>;
90
79
  answer?: any;
91
80
  }>, {}> & import("mongoose").FlatRecord<{} & {
92
81
  account: any;
93
82
  reference: any;
83
+ validations: Types.DocumentArray<{
84
+ type: string;
85
+ typeOutput: string;
86
+ formulaToMessage: string;
87
+ }, Types.Subdocument<Types.ObjectId, any, {
88
+ type: string;
89
+ typeOutput: string;
90
+ formulaToMessage: string;
91
+ }> & {
92
+ type: string;
93
+ typeOutput: string;
94
+ formulaToMessage: string;
95
+ }>;
94
96
  requestGraphicData: Types.DocumentArray<{
95
97
  url: string;
96
98
  method: string;
@@ -108,22 +110,6 @@ export declare const QPCAnswerSchema: Schema<any, import("mongoose").Model<any,
108
110
  dataset?: any;
109
111
  }>;
110
112
  qpc: any;
111
- messages: Types.DocumentArray<{
112
- type?: string | null | undefined;
113
- content?: string | null | undefined;
114
- formula?: string | null | undefined;
115
- typeContent?: string | null | undefined;
116
- }, Types.Subdocument<Types.ObjectId, any, {
117
- type?: string | null | undefined;
118
- content?: string | null | undefined;
119
- formula?: string | null | undefined;
120
- typeContent?: string | null | undefined;
121
- }> & {
122
- type?: string | null | undefined;
123
- content?: string | null | undefined;
124
- formula?: string | null | undefined;
125
- typeContent?: string | null | undefined;
126
- }>;
127
113
  answer?: any;
128
114
  }> & {
129
115
  _id: Types.ObjectId;
@@ -8,16 +8,7 @@ exports.QPCAnswerSchema = new mongoose_1.Schema({
8
8
  qpc: { type: mongoose_1.Types.ObjectId, ref: "qpc", required: true },
9
9
  reference: { type: mongoose_1.Types.ObjectId, ref: "form-unit", required: true },
10
10
  answer: { type: mongoose_1.Schema.Types.Mixed },
11
- messages: {
12
- type: [
13
- {
14
- type: { type: String, enum: FormUnit_1.TypeValidationEnum },
15
- formula: { type: String },
16
- typeContent: { type: String, enum: FormUnit_1.TypeOutputValidationEnum },
17
- content: { type: String }
18
- }
19
- ]
20
- },
11
+ validations: { type: [FormUnit_1.ValidationSchema] },
21
12
  requestGraphicData: { type: [FormUnit_1.RequestGraphicDataSchema] }
22
13
  }, {
23
14
  timestamps: { createdAt: "createdAtDateTime", updatedAt: "updatedAtDateTime" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-clinical",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Biblioteca Typescript para API NodeJS",
5
5
  "repository": "https://github.com/cabralsilva/c2-clinical.git",
6
6
  "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",