Skip to content

Commit 6bdf78f

Browse files
authored
Merge pull request #1344 from WildMeOrg/fix_encounter_page_individual_name_search_issue
search individual on both individual id and name
2 parents bdc9371 + e977b96 commit 6bdf78f

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

frontend/src/__tests__/pages/Encounter/EncounterStore.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ describe("EncounterStore", () => {
242242

243243
axios.post.mockResolvedValue({ data: { hits: mockResults } });
244244

245-
await store.searchIndividualsByName("Whale");
245+
await store.searchIndividualsByNameAndId("Whale");
246246

247247
expect(axios.post).toHaveBeenCalledWith(
248248
"/api/v3/search/individual?size=20&from=0",
@@ -312,7 +312,9 @@ describe("EncounterStore", () => {
312312
it("should handle individual search error", async () => {
313313
axios.post.mockRejectedValue(new Error("Search failed"));
314314

315-
await expect(store.searchIndividualsByName("test")).rejects.toThrow();
315+
await expect(
316+
store.searchIndividualsByNameAndId("test"),
317+
).rejects.toThrow();
316318
expect(toast.error).toHaveBeenCalled();
317319
expect(store.individualSearchResults).toEqual([]);
318320
});

frontend/src/__tests__/pages/Encounter/IdentifySectionEdit.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const makeStore = (overrides = {}) => ({
5858
identificationRemarksOptions: ["auto", "manual"],
5959
individualOptions: [],
6060
setIndividualOptions: jest.fn(),
61-
searchIndividualsByName: jest.fn(),
61+
searchIndividualsByNameAndId: jest.fn(),
6262
searchSightingsById: jest.fn(),
6363
setFieldValue: jest.fn(),
6464
setEditIdentifyCard: jest.fn(),
@@ -134,7 +134,7 @@ describe("IdentifySectionEdit", () => {
134134

135135
test("INDIVIDUAL_ID loadOptions maps search results and sets individual options", async () => {
136136
const store = makeStore();
137-
store.searchIndividualsByName.mockResolvedValueOnce({
137+
store.searchIndividualsByNameAndId.mockResolvedValueOnce({
138138
data: {
139139
hits: [
140140
{ id: 5, displayName: "Ind5" },
@@ -148,7 +148,7 @@ describe("IdentifySectionEdit", () => {
148148
const props = global.__SEARCH_PROPS__["INDIVIDUAL_ID"];
149149
const res = await props.loadOptions("in");
150150

151-
expect(store.searchIndividualsByName).toHaveBeenCalledWith("in");
151+
expect(store.searchIndividualsByNameAndId).toHaveBeenCalledWith("in");
152152
expect(store.setIndividualOptions).toHaveBeenCalledWith([
153153
{ value: "5", label: "Ind5" },
154154
{ value: "6", label: "Ind6" },

frontend/src/pages/Encounter/IdentifySectionEdit.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const IdentifySectionEdit = observer(({ store }) => {
5555
onChange={(v) => store.setFieldValue("identify", "individualId", v)}
5656
options={store.individualOptions}
5757
loadOptions={async (q) => {
58-
const resp = await store.searchIndividualsByName(q);
58+
const resp = await store.searchIndividualsByNameAndId(q);
5959
const options = (resp.data.hits || []).map((it) => ({
6060
value: String(it.id),
6161
label: it.displayName,

frontend/src/pages/Encounter/stores/EncounterStore.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class EncounterStore {
260260

261261
debouncedSearchIndividuals = debounce(async (inputValue) => {
262262
if (inputValue && inputValue.length >= 2) {
263-
await this.searchIndividualsByName(inputValue);
263+
await this.searchIndividualsByNameAndId(inputValue);
264264
} else {
265265
this.clearIndividualSearchResults();
266266
}
@@ -1144,7 +1144,7 @@ class EncounterStore {
11441144
this._encounterData = nextEncounter;
11451145
}
11461146

1147-
async searchIndividualsByName(inputValue) {
1147+
async searchIndividualsByNameAndId(inputValue) {
11481148
this._searchingIndividuals = true;
11491149

11501150
try {
@@ -1161,6 +1161,8 @@ class EncounterStore {
11611161
},
11621162
]
11631163
: []),
1164+
],
1165+
should: [
11641166
{
11651167
wildcard: {
11661168
names: {
@@ -1169,7 +1171,16 @@ class EncounterStore {
11691171
},
11701172
},
11711173
},
1174+
{
1175+
wildcard: {
1176+
id: {
1177+
value: `*${inputValue}*`,
1178+
case_insensitive: true,
1179+
},
1180+
},
1181+
},
11721182
],
1183+
minimum_should_match: 1,
11731184
},
11741185
},
11751186
};

0 commit comments

Comments
 (0)