-
Notifications
You must be signed in to change notification settings - Fork 12
TM - Formulario terapéutico: nuevo esquema y api #2146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fabio-Ramirez
wants to merge
2
commits into
master
Choose a base branch
from
TM-42
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,148 +1,28 @@ | ||
| import { toArray } from './../../../utils/utils'; | ||
| import * as express from 'express'; | ||
| import * as formularioTerapeutico from '../schemas/formularioTerapeutico'; | ||
| import * as mongoose from 'mongoose'; | ||
| import * as utils from '../../../utils/utils'; | ||
| import * as formularioCtrl from '../controller/formularioTerapeutico'; | ||
| import { MongoQuery, ResourceBase } from '@andes/core'; | ||
| import { Auth } from './../../../auth/auth.class'; | ||
| import { FormularioTerapeutico } from '../schemas/formularioTerapeutico'; | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| router.get('/formularioTerapeutico/:id?', async (req, res, next) => { | ||
| if (mongoose.Types.ObjectId.isValid(req.params.id)) { | ||
| formularioTerapeutico.findById(req.params.id, (err, data) => { | ||
| if (err) { | ||
| return next(err); | ||
| } | ||
| res.json(data); | ||
| }); | ||
| } else { | ||
| let query; | ||
| const opciones = {}; | ||
| if (req.query.padre) { | ||
| const arr = await formularioCtrl.getPadres(req.query.padre, []); | ||
| res.json(arr); | ||
| } else { | ||
| if (req.query.nombreMedicamento) { | ||
| // Parámetro texto ingresado | ||
| if (isNaN(req.query.nombreMedicamento)) { | ||
|
|
||
| opciones['$and'] = []; | ||
| const words = String(req.query.nombreMedicamento).split(' '); | ||
| words.forEach((word) => { | ||
| // normalizamos cada una de las palabras como hace SNOMED para poder buscar palabra a palabra | ||
| word = word.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').replace(/\x08/g, '\\x08'); | ||
| const expWord = '^' + utils.removeDiacritics(word) + '.*'; | ||
| // agregamos la palabra a la condicion | ||
| // opciones['$and'].push({ 'subcapitulos.medicamentos.concepto.words': { '$regex': expWord } }); | ||
| opciones['$and'].push({ 'concepto.words': { $regex: '(?i)' + expWord } }); | ||
| }); | ||
| } | ||
| } | ||
| // Parámetro Especialidad | ||
| if (req.query.especialidad) { | ||
| opciones['lespecialidades'] = String(req.query.especialidad); | ||
| } | ||
| // Parámetro Carro de Emergencia | ||
| if (req.query.carro) { | ||
| opciones['carro'] = Boolean(req.query.carro); | ||
| } | ||
| // Parámetro Nivel de Complejidad | ||
| if (req.query.nivel) { | ||
| opciones['nivelComplejidad'] = req.query.nivel; | ||
| } | ||
|
|
||
| opciones['borrado'] = { $exists: true }; | ||
|
|
||
| // Parámetro vista de arbol | ||
| if (req.query.tree) { // llevarlo a lado del controlador | ||
| let data; | ||
| let out = []; | ||
| if (req.query.root) { | ||
| data = await toArray(formularioTerapeutico.aggregate( | ||
| [ | ||
| { $match: { idpadre: mongoose.Types.ObjectId('5ac6512111764e32b35ad416'), borrado: { $exists: false } } }, | ||
| { | ||
| $graphLookup: { | ||
| from: 'formularioTerapeutico', | ||
| startWith: '$_id', | ||
| connectFromField: 'idpadre', | ||
| connectToField: 'idpadre', | ||
| as: 'arbol' | ||
| } | ||
| } | ||
| ] | ||
| ).cursor({}).exec()); | ||
| out = []; | ||
| data.forEach((nodo, indiceNodo) => { | ||
| out.push(nodo); | ||
| }); | ||
| } else { | ||
| const idpadre = req.query.idpadre; | ||
| data = await toArray(formularioTerapeutico.aggregate( | ||
| [ | ||
| { $match: { idpadre: mongoose.Types.ObjectId(idpadre), borrado: { $exists: false } } }, | ||
| { | ||
| $graphLookup: { | ||
| from: 'formularioTerapeutico', | ||
| startWith: '$_id', | ||
| connectFromField: 'idpadre', | ||
| connectToField: 'idpadre', | ||
| as: 'arbol' | ||
| } | ||
| } | ||
| ] | ||
| ).cursor({}).exec()); | ||
| out = []; | ||
| data.forEach((nodo, indiceNodo) => { | ||
| out.push(nodo); | ||
| }); | ||
| } | ||
| res.json(out); | ||
| } else { | ||
| query = formularioTerapeutico.find(opciones); | ||
| if (!Object.keys(query).length) { | ||
| res.status(400).send('Debe ingresar al menos un parámetro'); | ||
| return next(400); | ||
| } | ||
| if (req.query.nombreMedicamento) { | ||
| try { | ||
| const data = await formularioTerapeutico.find({ descripcion: RegExp('^.*' + req.query.nombreMedicamento + '.*$', 'i') }); | ||
| res.json(data); | ||
| } catch (error) { | ||
| return next(error); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| }); | ||
|
|
||
|
|
||
| router.post('/formularioTerapeutico', Auth.authenticate(), (req, res, next) => { | ||
| req.body.descripcion = req.body.concepto.term; | ||
| const newFormTera = new formularioTerapeutico(req.body); | ||
| Auth.audit(newFormTera, req); | ||
| newFormTera.save((errSave) => { | ||
| if (errSave) { | ||
| return next(errSave); | ||
| } | ||
| res.status(201).json(newFormTera); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| router.put('/formularioTerapeutico/:id', Auth.authenticate(), (req, res, next) => { | ||
| const idPadre = mongoose.Types.ObjectId(req.body.idpadre); | ||
| req.body.idpadre = idPadre; | ||
| formularioTerapeutico.findByIdAndUpdate(req.params.id, req.body, { new: true }, (err, data) => { | ||
| if (err) { | ||
| return next(err); | ||
| } | ||
| res.json(data); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| export = router; | ||
| class FormularioTerapeuticoResource extends ResourceBase { | ||
| Model = FormularioTerapeutico; | ||
| resourceName = 'formularioTerapeutico'; | ||
| keyId = '_id'; | ||
| searchFields = { | ||
| ftpSistema: MongoQuery.partialString, | ||
| ftpFuncion: MongoQuery.partialString, | ||
| ftpGrupoFarmacologico: MongoQuery.partialString, | ||
| nivelComplejidad: MongoQuery.partialString, | ||
| especialidad: MongoQuery.partialString, | ||
| carroEmergencia: MongoQuery.partialString, | ||
| medicamento: MongoQuery.partialString, | ||
| principioActivo: MongoQuery.partialString, | ||
| via: MongoQuery.partialString, | ||
| formaFarmaceutica: MongoQuery.partialString, | ||
| snomed: MongoQuery.partialString | ||
| }; | ||
| middlewares = [Auth.authenticate()]; | ||
| } | ||
| export const FormularioTerapeuticoCtr = new FormularioTerapeuticoResource({}); | ||
| export const FormularioTerapeuticoRouter = FormularioTerapeuticoCtr.makeRoutes(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,35 @@ | ||
| import * as mongoose from 'mongoose'; | ||
| import { AuditPlugin } from '@andes/mongoose-plugin-audit'; | ||
| import { model, Schema } from 'mongoose'; | ||
|
|
||
| const schema = new mongoose.Schema({ | ||
| idpadre: { | ||
| type: mongoose.Schema.Types.ObjectId, | ||
|
|
||
| export const formularioTerapeuticoSchema = new Schema({ | ||
| ftpSistema: { | ||
| _id: { type: Schema.Types.ObjectId }, | ||
| nombre: String | ||
| }, | ||
| ftpFuncion: { | ||
| _id: { type: Schema.Types.ObjectId }, | ||
| nombre: String | ||
| }, | ||
| ftpGrupoFarmacologico: { | ||
| _id: { type: Schema.Types.ObjectId }, | ||
| nombre: String | ||
| }, | ||
| descripcion: String, | ||
| nivelComplejidad: String, | ||
| especialidades: [String], | ||
| especialidad: String, | ||
| requisitos: String, | ||
| carroEmergencia: String, | ||
| recomendaciones: String, | ||
| medicamento: String, | ||
| indicaciones: String, | ||
| comentario: String, | ||
| conceptId: String, | ||
| borrado: Boolean, | ||
| concepto: Object | ||
| // padre: { | ||
| // nombre: String, | ||
| // conceptId: String, | ||
| // }, | ||
| // nombre: String, | ||
| // conceptId: String, | ||
| // capitulo: Number, | ||
| // nombre: String, | ||
| // medicamentos: [{ | ||
| // clasificacion: String, | ||
| // numero: Number, | ||
| // nivelComplejidad: String, | ||
| // recomendaciones: String, | ||
| // especialidades: [String], // enum? | ||
| // requisitos: String, // enum | ||
| // carroEmergencia: Boolean, | ||
| // indicaciones: String, // estandarizar? | ||
| // comentario: String, // estandarizar? | ||
| // concepto: { | ||
| // conceptId: String, | ||
| // term: String, | ||
| // fsn: String, | ||
| // semanticTag: String, | ||
| // words: [String] | ||
| // } | ||
| // }] | ||
| // }] | ||
| recomendacionesDeUso: String, | ||
| principioActivo: String, | ||
| via: String, | ||
| formaFarmaceutica: String, | ||
| potencia: String, | ||
| unidades: String, | ||
| presentacion: String, | ||
| atcVia: String, | ||
| snomed: String | ||
| }); | ||
|
|
||
| // Habilitar plugin de auditoría | ||
| schema.plugin(AuditPlugin); | ||
|
|
||
| // Exportar modelo | ||
| const model = mongoose.model('formularioTerapeutico', schema, 'formularioTerapeutico'); | ||
| export const FormularioTerapeutico = model('formulario-terapeutico', formularioTerapeuticoSchema, 'formulario-terapeutico'); | ||
|
|
||
| export = model; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as mongoose from 'mongoose'; | ||
|
|
||
| const ftpFuncionSchema = new mongoose.Schema({ | ||
| nombre: String | ||
| }); | ||
|
|
||
| export const FtpFuncion = mongoose.model('ftpFuncion', ftpFuncionSchema, 'ftpFuncion'); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as mongoose from 'mongoose'; | ||
|
|
||
| const ftpGrupoFarmacologicoSchema = new mongoose.Schema({ | ||
| nombre: String | ||
| }); | ||
|
|
||
| export const FtpGrupoFarmacologico = mongoose.model('ftpGrupoFarmacologico', ftpGrupoFarmacologicoSchema, 'ftpGrupoFarmacologico'); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import * as mongoose from 'mongoose'; | ||
|
|
||
| const ftpSistemaSchema = new mongoose.Schema({ | ||
| nombre: String | ||
| }); | ||
|
|
||
| export const FtpSistema = mongoose.model('ftpSistema', ftpSistemaSchema, 'ftpSistema'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
este atributo es correcto o se coló con algun error de tipeo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compa, el atributo está definido de esta manera porque refleja exactamente el nombre utilizado en la planilla original.