fixing filter diagnosis

This commit is contained in:
Narul Hidayah
2026-05-29 13:34:51 +09:00
parent 3cbdfb7c7b
commit cbfa943614

View File

@ -89,16 +89,17 @@ export class DiagnosisController {
query.andWhere(
new Brackets((qb) => {
let isFirst = true;
const addOr = (column: string, paramKey: string, raw: any) => {
const addOr = (column: string, paramKey: string, raw: any, castText = false) => {
const op = isFirst ? "where" : "orWhere";
isFirst = false;
const colExpr = castText ? `CAST(${column} AS TEXT)` : column;
if (Array.isArray(raw)) {
(qb as any)[op](`${column} IN (:...${paramKey})`, { [paramKey]: raw });
(qb as any)[op](`${colExpr} IN (:...${paramKey})`, { [paramKey]: raw });
return;
}
const f = String(raw);
if (validateUuid(f)) {
(qb as any)[op](`${column} = :${paramKey}`, { [paramKey]: f });
(qb as any)[op](`${colExpr} = :${paramKey}`, { [paramKey]: f });
return;
}
if (f === "null") {
@ -106,14 +107,14 @@ export class DiagnosisController {
return;
}
if (f.includes("%")) {
(qb as any)[op](`${column} ILIKE :${paramKey}`, { [paramKey]: f });
(qb as any)[op](`${colExpr} ILIKE :${paramKey}`, { [paramKey]: f });
return;
}
(qb as any)[op](`${column} = :${paramKey}`, { [paramKey]: f });
(qb as any)[op](`${colExpr} = :${paramKey}`, { [paramKey]: f });
};
if (orCode !== undefined) addOr("Diagnosis.code", "diag_or_code", orCode);
if (orDiagnosis !== undefined) addOr("Diagnosis.diagnosis", "diag_or_diagnosis", orDiagnosis);
if (orType !== undefined) addOr("Diagnosis.type", "diag_or_type", orType);
if (orType !== undefined) addOr("Diagnosis.type", "diag_or_type", orType, true);
}),
);
}