-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update hpt-pharmaceuticals andnon- hpt-pharmaceuticals #152
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ function OrgDomainsList() { | |
const [subdomainMenuAnchor, setSubdomainMenuAnchor] = useState(null); | ||
const subdomainMenuOpen = Boolean(subdomainMenuAnchor); | ||
|
||
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL; | ||
|
||
const fetchConcepts = (subdomain) => { | ||
setIsLoadingConcepts(true); | ||
setIsLoading(true); | ||
|
@@ -108,39 +110,86 @@ function OrgDomainsList() { | |
}; | ||
|
||
const fetchDomainData = (page = 1) => { | ||
fetch("/api/domains/" + domain + "?includeConcepts=true&page=" + page) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (data) { | ||
setDomainData(data); | ||
setSubDomainData(data.data?.subdomains); | ||
let filteredConcepts = data?.data?.concepts?.filter( | ||
(concept) => concept.type === "Concept" | ||
); | ||
if (data?.data?.subdomains && data?.data?.subdomains.length > 0) { | ||
setSelectedSubdomain(data?.data?.subdomains[0]?.url); | ||
fetchConcepts(data?.data?.subdomains[0]?.url); | ||
// Check if the domain ID is `hpt-non-pharmaceuticals` or `hpt-pharmaceuticals` | ||
let cascadeUrl = null; | ||
|
||
if (domain === "hpt-non-pharmaceuticals") { | ||
// Use cascade query URL for HPT-non-pharmaceuticals | ||
cascadeUrl = `${API_BASE_URL}/orgs/MOH-KENYA/sources/PPB/concepts/10-00000-02/$cascade/?cascadeLevels=1&method=sourceToConcepts&view=hierarchy&reverse=true&includeRetired=false`; | ||
} else if (domain === "hpt-pharmaceuticals") { | ||
// Use cascade query URL for HPT-pharmaceuticals | ||
cascadeUrl = `${API_BASE_URL}/orgs/MOH-KENYA/sources/PPB/concepts/10-00000-01/$cascade/?cascadeLevels=1&method=sourceToConcepts&view=hierarchy&reverse=true&includeRetired=false`; | ||
} | ||
|
||
if (cascadeUrl) { | ||
fetch(cascadeUrl) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (data && data.entry) { | ||
// Set subdomains from API response | ||
const dynamicSubdomains = data.entry.entries.map((entry) => ({ | ||
id: entry.id, | ||
display_name: entry.display_name, | ||
url: entry.url, | ||
})); | ||
|
||
setSubDomainData(dynamicSubdomains); | ||
|
||
if (dynamicSubdomains.length > 0) { | ||
setSelectedSubdomain(dynamicSubdomains[0].url); | ||
fetchConcepts(dynamicSubdomains[0].url); | ||
} | ||
} else { | ||
setConcepts(filteredConcepts); | ||
setCurrentConcepts(filteredConcepts); | ||
setIsLoadingConcepts(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem removed from the new |
||
setSubDomainData([]); | ||
} | ||
setTotalPages(data?.data?.conceptsMeta?.pagecount ?? 1); | ||
setRowsPerPage(data?.data?.conceptsMeta?.pagesize ?? 20); | ||
setPage(data?.data?.conceptsMeta?.currentpage ?? 1); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error("error::", err); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}) | ||
.catch((err) => { | ||
console.error("error::", err); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
} else { | ||
// Default data fetching for other domains | ||
fetch("/api/domains/" + domain + "?includeConcepts=true&page=" + page) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (data) { | ||
setDomainData(data); | ||
setSubDomainData(data.data?.subdomains); // Set default subdomains | ||
let filteredConcepts = data?.data?.concepts?.filter( | ||
(concept) => concept.type === "Concept" | ||
); | ||
if (data?.data?.subdomains && data?.data?.subdomains.length > 0) { | ||
setSelectedSubdomain(data?.data?.subdomains[0]?.url); | ||
fetchConcepts(data?.data?.subdomains[0]?.url); | ||
} else { | ||
setConcepts(filteredConcepts); | ||
setCurrentConcepts(filteredConcepts); | ||
setIsLoadingConcepts(false); | ||
} | ||
setTotalPages(data?.data?.conceptsMeta?.pagecount ?? 1); | ||
setRowsPerPage(data?.data?.conceptsMeta?.pagesize ?? 20); | ||
setPage(data?.data?.conceptsMeta?.currentpage ?? 1); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error("error::", err); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lucyjemutai - Can we extract this to the domains json and reference them here as an attribute of a domain instead of directly referencing them this way? like
domain.cascadeUrl