feat(api): add keyword filter for guarantor list
Parse `filter.any` separately from structured filters and pass it to the model query so generic search can match guarantor name and phone.
This commit is contained in:
@ -38,8 +38,13 @@ export class PatientGuarantorController {
|
||||
let param: Paging = await schema.validateAsync(req.query);
|
||||
|
||||
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||
let filterAny = filter.any && filter.any !== "" ? filter.any : "";
|
||||
|
||||
var query = await PatientGuarantorModel.list(filter);
|
||||
let filterObj = { ...filter } as any;
|
||||
delete filterObj.any;
|
||||
filterObj = { ...filterObj };
|
||||
|
||||
var query = await PatientGuarantorModel.list(filterObj, filterAny);
|
||||
|
||||
const offset = (param.page - 1) * param.limit;
|
||||
let limit = param.limit;
|
||||
@ -110,7 +115,7 @@ export class PatientGuarantorController {
|
||||
|
||||
var query = await PatientGuarantorModel.list(filter);
|
||||
const data = await query.getMany();
|
||||
|
||||
|
||||
const filename = "patient_guarantor.csv";
|
||||
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
@ -179,7 +184,8 @@ export class PatientGuarantorController {
|
||||
zip_code: Joi.string().max(10).required().label('Zip Code'),
|
||||
agreement_no: Joi.string().max(50).required().label('Agreement No.'),
|
||||
agreement_desc: Joi.string().max(512).optional().label('Agreement Description'),
|
||||
patient_group_id: Joi.string().guid({ version: 'uuidv4' }).required().label('Patient Group'), });
|
||||
patient_group_id: Joi.string().guid({ version: 'uuidv4' }).required().label('Patient Group'),
|
||||
});
|
||||
|
||||
const param: any = await schema.validateAsync(req.body);
|
||||
|
||||
|
||||
@ -4,13 +4,26 @@ import { OrmHelper } from "../helpers/orm";
|
||||
import { PatientGuarantor } from "entity";
|
||||
|
||||
export class PatientGuarantorModel {
|
||||
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
|
||||
static async list(filterObj = {}, filterAny: string = ""): Promise<SelectQueryBuilder<any>> {
|
||||
const repo = OrmHelper.DB.getRepository(PatientGuarantor);
|
||||
let whereAttr: string[] = [];
|
||||
let whereVal: any = {};
|
||||
if (filter && Object.keys(filter).length > 0) {
|
||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "patient_guarantor").whereAttr];
|
||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "patient_guarantor").whereVal };
|
||||
if (filterObj && Object.keys(filterObj).length > 0) {
|
||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filterObj, "patient_guarantor").whereAttr];
|
||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filterObj, "patient_guarantor").whereVal };
|
||||
}
|
||||
|
||||
if (filterAny && filterAny !== "" && filterAny !== null && filterAny !== undefined) {
|
||||
const filterResult = CommonHelper.handleFilter({
|
||||
filter: JSON.stringify({ any: filterAny }),
|
||||
col_any_eq: [],
|
||||
col_any_like: ["name", "phone"],
|
||||
});
|
||||
|
||||
if (filterResult.whereAttr && filterResult.whereAttr !== "") {
|
||||
whereAttr = [...whereAttr, filterResult.whereAttr];
|
||||
whereVal = { ...whereVal, ...filterResult.whereVal };
|
||||
}
|
||||
}
|
||||
|
||||
var query = repo.createQueryBuilder("patient_guarantor").leftJoinAndSelect("patient_guarantor.patient_group", "patient_group");
|
||||
|
||||
Reference in New Issue
Block a user