Skip to content

Commit

Permalink
Merge pull request #81 from REAN-Foundation/search_for_types
Browse files Browse the repository at this point in the history
Search for types
  • Loading branch information
dattatraya-inflection authored Oct 14, 2024
2 parents 37a2b44 + efc9164 commit ce6a9b9
Show file tree
Hide file tree
Showing 36 changed files with 2,013 additions and 1,591 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/navbar/sidebar/sidebar.menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function addAdministrationMenus(
name : 'Person-Role',
title : 'User Roles',
icon : 'material-symbols:person-search-outline-rounded',
link : `/users/${userId}/person-role-types`,
link : `/users/${userId}/user-roles`,
children: []
};
menuList.push(personRoleMenu);
Expand Down Expand Up @@ -565,7 +565,7 @@ function addClinicalMenus(
name : 'Lab-Records',
title : 'Lab Records',
icon : 'material-symbols:lab-research-outline-rounded',
link : `/users/${userId}/lab-record-types`,
link : `/users/${userId}/lab-records`,
children: []
};
menuList.push(labRecordType);
Expand Down
15 changes: 15 additions & 0 deletions src/lib/utils/user.active.role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function setActiveRoles(userRoles) {
userRoles.forEach((userRoleType) => {
if (userRoleType.RoleName === 'System admin' ||
userRoleType.RoleName === 'System user' ||
userRoleType.RoleName === 'Tenant admin' ||
userRoleType.RoleName === 'Tenant user' ||
userRoleType.RoleName === 'Patient' ||
userRoleType.RoleName === 'Doctor') {
userRoleType.isActive = true;
} else {
userRoleType.isActive = false;
}
});
return userRoles;
}
2 changes: 1 addition & 1 deletion src/routes/api/server/goals/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DELETE = async (event: RequestEvent) => {
);
}
throw redirect(
successMessage(response.Message),
successMessage('Goal deleted successfully!'),
event
);
};
5 changes: 2 additions & 3 deletions src/routes/api/server/goals/search/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ export const GET = async (event: RequestEvent) => {
itemsPerPage,
pageIndex
};
console.log('Search parms: ', searchParams);

const response = await searchGoals(sessionId, searchParams);
const items = response.Data.GoalType.Items;
const items = response.Data.GoalTypes;
console.log('data==/////', response);

return new Response(JSON.stringify(items));
} catch (err) {
console.error(`Error retriving goal: ${err.message}`);
Expand Down
39 changes: 39 additions & 0 deletions src/routes/api/server/lab-record-types/search/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { searchLabRecordTypes } from "$routes/api/services/reancare/lab-record-types";
import type { RequestEvent } from "@sveltejs/kit";

//////////////////////////////////////////////////////////////

export const GET = async (event: RequestEvent) => {

const sessionId = event.locals.sessionUser.sessionId;
const searchParams: URLSearchParams = event.url.searchParams;
const typeName = searchParams.get('typeName') ?? undefined
const displayName = searchParams.get('displayName') ?? undefined
const sortBy = searchParams.get('sortBy') ?? 'CreatedAt';
const sortOrder = searchParams.get('sortOrder') ?? 'ascending';
const itemsPerPage_ = searchParams.get('itemsPerPage');
const itemsPerPage = itemsPerPage_ ? parseInt(itemsPerPage_) : 10;
const pageIndex_ = searchParams.get('pageIndex');
const pageIndex = pageIndex_ ? parseInt(pageIndex_) : 0;

try {
const searchParams = {
typeName,
displayName,
orderBy: sortBy,
order: sortOrder,
itemsPerPage,
pageIndex,
};
console.log("Search parms: ", searchParams);
const response = await searchLabRecordTypes(sessionId, searchParams);
const labRecords = response.Data.LabRecordTypes;
console.log("labRecords", JSON.stringify(response, null, 2));
return new Response(JSON.stringify(labRecords));
} catch (err) {
console.error(`Error retriving lab records: ${err.message}`);
return new Response(err.message);
}
};


39 changes: 39 additions & 0 deletions src/routes/api/server/person-role-types/search/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { setActiveRoles } from "$lib/utils/user.active.role";
import { searchRoleTypes } from "$routes/api/services/reancare/person-role-types";
import type { RequestEvent } from "@sveltejs/kit";

//////////////////////////////////////////////////////////////

export const GET = async (event: RequestEvent) => {

const sessionId = event.locals.sessionUser.sessionId;
const searchParams: URLSearchParams = event.url.searchParams;
const roleName = searchParams.get('roleName') ?? undefined
const sortBy = searchParams.get('sortBy') ?? 'CreatedAt';
const sortOrder = searchParams.get('sortOrder') ?? 'ascending';
const itemsPerPage_ = searchParams.get('itemsPerPage');
const itemsPerPage = itemsPerPage_ ? parseInt(itemsPerPage_) : 10;
const pageIndex_ = searchParams.get('pageIndex');
const pageIndex = pageIndex_ ? parseInt(pageIndex_) : 0;

try {
const searchParams = {
name:roleName,
orderBy: sortBy,
order: sortOrder,
itemsPerPage,
pageIndex,
};
console.log("Search parms: ", searchParams);
const response = await searchRoleTypes(sessionId, searchParams);
const roles = response.Data.Roles;
roles.Items = setActiveRoles(roles.Items ?? []);
console.log("roles", JSON.stringify(response, null, 2));
return new Response(JSON.stringify(roles));
} catch (err) {
console.error(`Error retriving roles: ${err.message}`);
return new Response(err.message);
}
};


16 changes: 6 additions & 10 deletions src/routes/api/server/priorities/search/+server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RequestEvent } from '@sveltejs/kit';
import { page } from '$app/stores';
import { searchPriorities } from '../../../services/reancare/priorities';
import { searchPriorities } from '$routes/api/services/reancare/priorities';

//////////////////////////////////////////////////////////////

Expand All @@ -12,28 +11,25 @@ export const GET = async (event: RequestEvent) => {
const tags = searchParams.get('tags') ?? undefined;
const sortBy = searchParams.get('sortBy') ?? 'CreatedAt';
const sortOrder = searchParams.get('sortOrder') ?? 'ascending';
const itemsPerPage_ = searchParams.get('pageIndex');
const itemsPerPage = itemsPerPage_ ? parseInt(itemsPerPage_) : 25;
const itemsPerPage_ = searchParams.get('itemsPerPage');
const itemsPerPage = itemsPerPage_ ? parseInt(itemsPerPage_) : 10;
const pageIndex_ = searchParams.get('pageIndex');
const pageIndex = pageIndex_ ? parseInt(pageIndex_) : 0;

try {
const searchParams = {
type,
tags,
tags: tags,
orderBy: sortBy,
order: sortOrder,
itemsPerPage,
pageIndex
};
console.log('Search parms: ', searchParams);
const response = await searchPriorities(sessionId, searchParams);
const items = response.Data.Items;
console.log('data==/////', response);

const items = response.Data.PriorityTypes;
return new Response(JSON.stringify(items));
} catch (err) {
console.error(`Error retriving priority: ${err.message}`);
console.error(`Error retriving priorities: ${err.message}`);
return new Response(err.message);
}
};
2 changes: 1 addition & 1 deletion src/routes/api/services/reancare/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const searchGoals = async (sessionId: string, searchParams?: any) => {
searchString += params.join('&');
}
}
const url = BACKEND_API_URL + `/types/goal-types/`;
const url = BACKEND_API_URL + `/types/goal-types/search${searchString}`;
return await get(sessionId, url, true, API_CLIENT_INTERNAL_KEY);
};

Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/services/reancare/lab-record-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export const searchLabRecordTypes = async (sessionId: string, searchParams?: any
params.push(param);
}
}
searchString += params.join('&');
}
}
const url = BACKEND_API_URL + `/types/lab-records`;
const url = BACKEND_API_URL + `/types/lab-records/search${searchString}`;
console.log(url);
return await get(sessionId, url, true, API_CLIENT_INTERNAL_KEY);
};
Expand Down
20 changes: 20 additions & 0 deletions src/routes/api/services/reancare/person-role-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ export const searchPersonRoleTypes = async (sessionId: string) => {
return await get(sessionId, url, true, API_CLIENT_INTERNAL_KEY);
};

export const searchRoleTypes = async (sessionId: string, searchParams?: any) => {
let searchString = '';
if (searchParams) {
const keys = Object.keys(searchParams);
if (keys.length > 0) {
searchString = '?';
const params = [];
for (const key of keys) {
if (searchParams[key]) {
const param = `${key}=${searchParams[key]}`;
params.push(param);
}
}
searchString += params.join('&');
}
}
const url = BACKEND_API_URL + `/roles/search${searchString}`;
return await get(sessionId, url, true, API_CLIENT_INTERNAL_KEY);
};

export const updatePersonRoleType = async (
sessionId: string,
personRoleTypeId: string,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/services/reancare/priorities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const searchPriorities = async (sessionId: string, searchParams?: any) =>
searchString += params.join('&');
}
}
const url = BACKEND_API_URL + `/types/priorities/`;
const url = BACKEND_API_URL + `/types/priorities/search${searchString}`;
return await get(sessionId, url, true, API_CLIENT_INTERNAL_KEY);
};

Expand Down
5 changes: 4 additions & 1 deletion src/routes/users/[userId]/goals/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { searchGoals } from '../../../api/services/reancare/goals';
export const load: PageServerLoad = async (event: ServerLoadEvent) => {
const sessionId = event.cookies.get('sessionId');
event.depends('app:goals');
const response = await searchGoals(sessionId);
const response = await searchGoals(sessionId,{
orderBy: 'Type',
order : 'ascending'
});
if (response.Status === 'failure' || response.HttpCode !== 200) {
throw error(response.HttpCode, response.Message);
}
Expand Down
Loading

0 comments on commit ce6a9b9

Please sign in to comment.