update
This commit is contained in:
@ -3,6 +3,8 @@ import { NextFunction, Response } from "express";
|
||||
import { Request } from "express-jwt";
|
||||
import Joi from "joi";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Brackets } from "typeorm";
|
||||
import { validate as validateUuid } from "uuid";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import { ReturnHelper } from "../helpers/express/return";
|
||||
import { Language } from "../langs/lang";
|
||||
@ -23,7 +25,7 @@ export class DiagnosticProcedureController {
|
||||
"bearerAuth": []
|
||||
}]
|
||||
#swagger.parameters['filter'] = {
|
||||
description: 'Filter: plain text (like %name%) or JSON object with status, code, etc.',
|
||||
description: 'Filter: JSON object; DiagnosticProcedure.code and DiagnosticProcedure.diagnosticProcedure are combined with OR; other fields use AND.',
|
||||
in: 'query',
|
||||
type: 'string',
|
||||
}
|
||||
@ -68,9 +70,49 @@ export class DiagnosticProcedureController {
|
||||
|
||||
let param: Paging = await schema.validateAsync(req.query);
|
||||
|
||||
let filter = JSON.parse(param.filter);
|
||||
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||
|
||||
var query = await DiagnosticProcedureModel.list(filter);
|
||||
const codeKey = "DiagnosticProcedure.code";
|
||||
const procedureKey = "DiagnosticProcedure.diagnosticProcedure";
|
||||
const orCode = filter[codeKey];
|
||||
const orProcedure = filter[procedureKey];
|
||||
const restFilter = { ...filter };
|
||||
delete restFilter[codeKey];
|
||||
delete restFilter[procedureKey];
|
||||
|
||||
var query = await DiagnosticProcedureModel.list(restFilter);
|
||||
|
||||
if (orCode !== undefined || orProcedure !== undefined) {
|
||||
query.andWhere(
|
||||
new Brackets((qb) => {
|
||||
let isFirst = true;
|
||||
const addOr = (column: string, paramKey: string, raw: any) => {
|
||||
const op = isFirst ? "where" : "orWhere";
|
||||
isFirst = false;
|
||||
if (Array.isArray(raw)) {
|
||||
(qb as any)[op](`${column} IN (:...${paramKey})`, { [paramKey]: raw });
|
||||
return;
|
||||
}
|
||||
const f = String(raw);
|
||||
if (validateUuid(f)) {
|
||||
(qb as any)[op](`${column} = :${paramKey}`, { [paramKey]: f });
|
||||
return;
|
||||
}
|
||||
if (f === "null") {
|
||||
(qb as any)[op](`${column} IS NULL`);
|
||||
return;
|
||||
}
|
||||
if (f.includes("%")) {
|
||||
(qb as any)[op](`${column} ILIKE :${paramKey}`, { [paramKey]: f });
|
||||
return;
|
||||
}
|
||||
(qb as any)[op](`${column} = :${paramKey}`, { [paramKey]: f });
|
||||
};
|
||||
if (orCode !== undefined) addOr("DiagnosticProcedure.code", "dp_or_code", orCode);
|
||||
if (orProcedure !== undefined) addOr("DiagnosticProcedure.diagnosticProcedure", "dp_or_procedure", orProcedure);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const offset = (param.page - 1) * param.limit;
|
||||
let limit = param.limit;
|
||||
|
||||
Reference in New Issue
Block a user