Skip to content

Commit

Permalink
fix airlock
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Apr 11, 2024
1 parent 232723e commit 06d88bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
10 changes: 5 additions & 5 deletions backend/src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def to_camelcase(s: str) -> str:
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
return "".join([s[0].lower(), s[1:]])

def load_cohort_dict_file(dict_path: str, cohort_id: str, airlock: bool) -> Dataset:
def load_cohort_dict_file(dict_path: str, cohort_id: str) -> Dataset:
"""Parse the cohort dictionary uploaded as excel or CSV spreadsheet, and load it to the triplestore"""
# print(f"Loading dictionary {dict_path}")
# df = pd.read_csv(dict_path) if dict_path.endswith(".csv") else pd.read_excel(dict_path)
Expand Down Expand Up @@ -219,8 +219,6 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, airlock: bool) -> Data
g = init_graph()
g.add((cohort_uri, RDF.type, ICARE.Cohort, cohort_uri))
g.add((cohort_uri, DC.identifier, Literal(cohort_id), cohort_uri))
# Preview goes to mapping graph because it is defined in the explorer UI
g.add((cohort_uri, ICARE.previewEnabled, Literal(str(airlock).lower(), datatype=XSD.boolean), get_cohort_mapping_uri(cohort_id)))

# Record all errors and raise them at the end
errors = []
Expand Down Expand Up @@ -358,7 +356,9 @@ async def upload_cohort(
shutil.copyfileobj(cohort_dictionary.file, buffer)

try:
g = load_cohort_dict_file(metadata_path, cohort_id, airlock)
g = load_cohort_dict_file(metadata_path, cohort_id)
# Airlock preview setting goes to mapping graph because it is defined in the explorer UI
g.add((get_cohort_uri(cohort_id), ICARE.previewEnabled, Literal(str(airlock).lower(), datatype=XSD.boolean), get_cohort_mapping_uri(cohort_id)))
# Delete previous graph for this file from triplestore
delete_existing_triples(get_cohort_uri(cohort_id))
publish_graph_to_endpoint(g)
Expand Down Expand Up @@ -467,7 +467,7 @@ def init_triplestore() -> None:
for file in glob.glob(os.path.join(folder_path, "*_datadictionary.*")):
# NOTE: default airlock preview to false if we ever need to reset cohorts,
# admins can easily ddl and reupload the cohorts with the correct airlock value
g = load_cohort_dict_file(file, folder, False)
g = load_cohort_dict_file(file, folder)
g.serialize(f"{settings.data_folder}/cohort_explorer_triplestore.trig", format="trig")
if publish_graph_to_endpoint(g):
print(f"💾 Triplestore initialization: added {len(g)} triples for cohorts {file}.")
Expand Down
14 changes: 1 addition & 13 deletions frontend/src/components/CohortsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ export const CohortsProvider = ({children}: any) => {
const [userEmail, setUserEmail]: [string | null, any] = useState('');
const worker: MutableRefObject<Worker | null> = useRef(null);

// Update cohorts data with a web worker in the background for smoothness
// const worker = new Worker('/cohortsWorker.js');
// worker.onmessage = (event) => {
// // Update your state with the new data
// const data = event.data;
// if (!data.error) {
// setCohortsData(data);
// console.log('Updated context with data', data);
// } else {
// console.error('Error fetching data in worker:', data.error);
// }
// };

useEffect(() => {
setDataCleanRoom(JSON.parse(sessionStorage.getItem('dataCleanRoom') || '{"cohorts": {}}'));

Expand Down Expand Up @@ -61,6 +48,7 @@ export const CohortsProvider = ({children}: any) => {
// Fetch cohorts data from the API using the web worker
const fetchCohortsData = () => {
worker.current?.postMessage({apiUrl});
// console.log(cohortsData)
};

// Update the metadata of a specific cohort in the context
Expand Down
18 changes: 3 additions & 15 deletions frontend/src/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ export function Nav() {

const toggleTheme = () => {
const newTheme = theme === 'light' ? 'dark' : 'light';
// console.log("NEW THEME", newTheme)
sessionStorage.setItem('theme', newTheme);
setTheme(newTheme);
// document.querySelector('html')?.setAttribute('data-theme', newTheme);
// document.documentElement.setAttribute("data-theme", newTheme);
};

const handleLogout = () => {
Expand All @@ -63,27 +60,18 @@ export function Nav() {
const sendCohortsToDecentriq = async () => {
setIsLoading(true);
// Replace with actual API endpoint and required request format
console.log('Sending request to Decentriq', dataCleanRoom);
const requestBody = dataCleanRoom;
// const requestBody = {cohorts: {}};
// for (const cohortId of dataCleanRoom.cohorts as string[]) {
// // @ts-ignore
// // requestBody.cohorts[cohortId] = cohortsData[cohortId];
// // NOTE: variables is left empty for now, placeholder for later when users will be able to select also variables
// requestBody.cohorts[cohortId] = {"variables": []};
// }
console.log('requestBody', requestBody);
// console.log('Sending request to Decentriq', dataCleanRoom);
try {
const response = await fetch(`${apiUrl}/create-dcr`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
body: JSON.stringify(dataCleanRoom)
});
const res = await response.json();
console.log(res);
// console.log(res);
setPublishedDCR(res);
setIsLoading(false);
// Handle response
Expand Down

0 comments on commit 06d88bc

Please sign in to comment.