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