60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import { TrizRisConfig } from '@ohif/core/src/config/TrizRisConfig';
|
|
const BASE_URL = `${TrizRisConfig.apiBaseUrl}/layout/current`;
|
|
|
|
export type SavedLayout = {
|
|
numRows: number;
|
|
numCols: number;
|
|
};
|
|
|
|
export async function saveLayoutPreference(
|
|
numRows: number,
|
|
numCols: number,
|
|
studyInstanceUID: string
|
|
): Promise<void> {
|
|
const response = await fetch(BASE_URL, {
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
},
|
|
|
|
credentials: 'include',
|
|
|
|
body: JSON.stringify({
|
|
numRows,
|
|
numCols,
|
|
studyInstanceUID,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Erreur sauvegarde layout TrizRis : ${response.status}`);
|
|
}
|
|
}
|
|
|
|
export async function getLayoutPreference(studyInstanceUID: string): Promise<SavedLayout | null> {
|
|
const response = await fetch(
|
|
`${BASE_URL}?studyInstanceUID=${encodeURIComponent(studyInstanceUID)}`,
|
|
{
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
Accept: 'application/json',
|
|
},
|
|
|
|
credentials: 'include',
|
|
}
|
|
);
|
|
|
|
if (response.status === 204) {
|
|
return null;
|
|
}
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Erreur récupération layout TrizRis : ${response.status}`);
|
|
}
|
|
|
|
return response.json();
|
|
}
|