MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / searchTuss

Function searchTuss

services/tuss/index.js:16–40  ·  view source on GitHub ↗
({ name, tuss })

Source from the content-addressed store, hash-verified

14}
15
16export function searchTuss({ name, tuss }) {
17 let terms = getTussTerms();
18
19 const hasName = typeof name === 'string' && name.trim().length > 0;
20 const hasTuss = typeof tuss === 'string' && tuss.trim().length > 0;
21
22 if (!hasName && !hasTuss) {
23 return terms;
24 }
25
26 const nameQuery = hasName ? normalize(name) : null;
27 const tussQuery = hasTuss ? sanitizeCode(tuss) : null;
28
29 terms = terms.filter((item) => {
30 const itemName = normalize(item.name || item.nome || item.descricao);
31 const itemCode = sanitizeCode(item.tuss || item.codigo || item.codigo_tuss);
32
33 const matchName = hasName ? itemName.includes(nameQuery) : true;
34 const matchCode = hasTuss ? itemCode.startsWith(tussQuery) : true;
35
36 return matchName && matchCode;
37 });
38
39 return terms;
40}
41
42export function findTussByCodeExact(code) {
43 const query = sanitizeCode(code);

Callers 1

TussSearchFunction · 0.90

Calls 3

getTussTermsFunction · 0.85
normalizeFunction · 0.85
sanitizeCodeFunction · 0.85

Tested by

no test coverage detected