-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert from doi to pmid and create imperative pmid fetch function
- Loading branch information
Showing
5 changed files
with
250 additions
and
126 deletions.
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
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
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
35 changes: 35 additions & 0 deletions
35
compose/neurosynth-frontend/src/hooks/external/useGetPubMedIdFromDOI.tsx
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios, { AxiosError, AxiosResponse } from 'axios'; | ||
import { useMutation } from 'react-query'; | ||
|
||
/** | ||
* NOTE: this is a get request but we use useMutation so that we can query the data imperatively. | ||
* This means that there is no smart refetching | ||
* https://github.com/TanStack/query/discussions/3675 | ||
*/ | ||
|
||
export interface IESearchResult { | ||
esearchresult: { | ||
count: string; | ||
idlist: string[]; | ||
}; | ||
header: { | ||
type: string; | ||
version: string; | ||
}; | ||
status: string; | ||
responseDate: string; | ||
} | ||
|
||
const ESEARCH_UR = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi'; | ||
|
||
const useGetPubMedIdFromDOI = () => { | ||
return useMutation<AxiosResponse<IESearchResult>, AxiosError, string, unknown>((doi) => | ||
axios.get<IESearchResult>(`${ESEARCH_UR}?db=pubmed&retmode=json&term=${doi}`, { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
}, | ||
}) | ||
); | ||
}; | ||
|
||
export default useGetPubMedIdFromDOI; |
Oops, something went wrong.