diff --git a/src/Controllers/CalculatorController.ts b/src/Controllers/CalculatorController.ts index 3550ab2fb5b9b9dc796f27298370014a8cd42cf7..dbdf560b0567eb1f89dd47a8f69b5a8c83de48cf 100644 --- a/src/Controllers/CalculatorController.ts +++ b/src/Controllers/CalculatorController.ts @@ -1,17 +1,14 @@ import { Handler, Request, Response, Router, } from 'express'; -import AgeGroupJSON from '../DTOs/AgeGroupJSON'; import CalculatorService from '../Services/CalculatorService'; import CalculatorResponse from '../DTOs/CalculatorResponseDTO'; import logger from '../Logger/logger'; -import ExtraData from '../DTOs/ExtraDataDTO'; const router = Router(); const getREP: Handler = async (req: Request, res: Response) => { - const { groups } = req.body; - const { extraData } = req.body; + const { groups, extraData } = req.body; try { const EnergyReq: CalculatorResponse = CalculatorService.calculateEnergeticRequirement(groups, extraData); diff --git a/src/DTOs/AgeGroupJSON.ts b/src/DTOs/AgeGroupJSON.ts index 0a795b4df24d3df45c9aa7c1423b9a09db36477c..6459407ed0aac27ae9791ca069d5295b45137859 100644 --- a/src/DTOs/AgeGroupJSON.ts +++ b/src/DTOs/AgeGroupJSON.ts @@ -1,8 +1,8 @@ type AgeGroupJSON = { - age: string; + age: string; // TODO: check enum sex: string; - medianWeight: string; - population: string; + medianWeight: number; // TODO: check if it can be number again + population: number; // TODO: check if it can be number again }; export default AgeGroupJSON; diff --git a/src/DTOs/MinorPALDTO.ts b/src/DTOs/MinorPALDTO.ts index 9633fca698d9fbbdac8092cab49ae03f75467c11..75b39bd4b6272e007b03fcb2b22e2e3ccf7c8789 100644 --- a/src/DTOs/MinorPALDTO.ts +++ b/src/DTOs/MinorPALDTO.ts @@ -1,5 +1,5 @@ type MinorPAL = { - lowPalPrevalence: number; + lowPALPrevalence: number; moderatePALPrevalence: number; intensePALPrevalence: number; }; diff --git a/src/Services/ERCalculator.ts b/src/Services/ERCalculator.ts index b75ec53f40bcb868ec6a2e9939c9c8dec0399fd9..3a3513adfbb7360e8542761c3e07fc6c8c2d4973 100644 --- a/src/Services/ERCalculator.ts +++ b/src/Services/ERCalculator.ts @@ -28,7 +28,7 @@ const calculateTEE = (group: AgeGroup, params: number[], preval: MinorPAL): numb const teeLow: number = teeModerate - (teeModerate * params[4]) / 100; const teeIntense: number = teeModerate + (teeModerate * params[5]) / 100; - const ret: number = (teeLow * preval.lowPalPrevalence) / 100 + const ret: number = (teeLow * preval.lowPALPrevalence) / 100 + (teeModerate * preval.moderatePALPrevalence) / 100 + (teeIntense * preval.intensePALPrevalence) / 100; @@ -41,7 +41,7 @@ const calculateBMR = (group: AgeGroup, params: number[]): number => { return ret; }; -// PAL (Physical activity level) = NAF (Nivel de Actividad Fisica) +// PAL (Physical Activity Level) = NAF (Nivel de Actividad Fisica) const calculatePAL = (params: number[], popData: AdultPAL): number => { const ruralPAL: number = (popData.activeRuralPAL * params[2]) / 100 + (popData.lowRuralPAL * params[3]) / 100; diff --git a/src/Services/ParameterService.ts b/src/Services/ParameterService.ts index bd847cec4da5ff828c24962dc95fe798e2784760..30f6085b228efb7e6534bcad8818c630f1bf9916 100644 --- a/src/Services/ParameterService.ts +++ b/src/Services/ParameterService.ts @@ -328,7 +328,7 @@ const getEquationValues = (ageBracket: AgeBracket, sex: Sex): number[] => { } default: { - throw new Error('Parsing error, attribute edad does not respect format'); + throw new Error(`Parsing error, attribute edad does not respect format ${ageBracket}`); } } return res; diff --git a/src/Services/ParserService.ts b/src/Services/ParserService.ts index 1da2a272864adc5339d87164819123e381525493..dc7131b412cf5b78d381501b62d6d2073cf0ee03 100644 --- a/src/Services/ParserService.ts +++ b/src/Services/ParserService.ts @@ -169,8 +169,8 @@ const parseGroups = (groups: AgeGroupJSON[]): AgeGroup[] => { const group: AgeGroup = { age: ageGroup.age as AgeBracket, sex: ageGroup.sex as Sex, - medianWeight: parseFloat(ageGroup.medianWeight), - population: parseFloat(ageGroup.population), + medianWeight: ageGroup.medianWeight, + population: ageGroup.population, }; retGroups.push(group); }); @@ -181,8 +181,8 @@ const unparseGroup = (group: AgeGroup): AgeGroupJSON => { const retGroup: AgeGroupJSON = { age: group.age as string, sex: group.sex as string, - medianWeight: String(group.medianWeight), - population: String(group.population), + medianWeight: group.medianWeight, + population: group.population, }; return retGroup; }; diff --git a/swagger.yaml b/swagger.yaml index a531d9d80720a482901607fbe7aa5350473c9656..1adc477fc20beebe342c36d78a08df80e30b3a9f 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -46,19 +46,21 @@ paths: - BearerAuth: [] /repCalculator: - post: - tags: - - Calculation + post: + tags: + - Calculation summary: Given population data calculates its energetic requirement requestBody: content: application/json: schema: - $ref: '#/components/schemas/AgeGroupJSON' + $ref: '#/components/schemas/ReqCalculation' required: true responses: '200': description: Ok. + '400': + description: Bad request. security: - BearerAuth: [] components: @@ -107,11 +109,92 @@ components: type: string AgeGroupJSON: properties: - edad: + age: type: string - sexo: + sex: type: string - pesoMediano: + medianWeight: type: string - cantidad: - type: string \ No newline at end of file + population: + type: string + required: + - age + - sex + - medianWeight + - population + MinorPAL: + properties: + lowPALPrevalence: + type: number + moderatePALPrevalence: + type: number + intensePALPrevalence: + type: number + required: + - lowPALPrevalence + - moderatePALPrevalence + - intensePALPrevalence + AdultPAL: + properties: + urbanPercentage: + type: number + activeUrbanPAL: + type: number + lowUrbanPAL: + type: number + ruralPercentage: + type: number + activeRuralPAL: + type: number + lowRuralPAL: + type: number + required: + - urbanPercentage + - activeUrbanPAL + - lowUrbanPAL + - ruralPercentage + - activeRuralPAL + - lowRuralPAL + IndividualMaternity: + properties: + pregnantWomen: + type: number + lactatingWomen: + type: number + required: + - pregnantWomen + - lactatingWomen + PopulationMaternity: + properties: + countryBirthRate: + type: number + countryPopulation: + type: number + required: + - countryBirthRate + - countryPopulation + ExtraData: + properties: + minorPAL: + $ref: '#/components/schemas/MinorPAL' + adultPAL: + $ref: '#/components/schemas/AdultPAL' + maternity18to29: + oneOf: + - $ref: '#/components/schemas/IndividualMaternity' + - $ref: '#/components/schemas/PopulationMaternity' + maternity30to59: + oneOf: + - $ref: '#/components/schemas/IndividualMaternity' + - $ref: '#/components/schemas/PopulationMaternity' + ReqCalculation: + properties: + groups: + type: array + items: + $ref: '#/components/schemas/AgeGroupJSON' + extraData: + $ref: '#/components/schemas/ExtraData' + required: + - groups + - extraData \ No newline at end of file