-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #845 from BIDMCDigitalPsychiatry/self-help
Self-help changes
- Loading branch information
Showing
17 changed files
with
1,809 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import ImportActivity from "./Researcher/ActivityList/ImportActivity" | |
import PreventPage from "./PreventPage" | ||
import { sensorEventUpdate } from "./BottomMenu" | ||
import TwoFA from "./TwoFA" | ||
import demo_db from "../demo_db.json" | ||
import self_help_db from "../self_help_db.json" | ||
|
||
function ErrorFallback({ error }) { | ||
const [trace, setTrace] = useState([]) | ||
|
@@ -129,6 +131,11 @@ function AppRouter({ ...props }) { | |
const serverAddressFro2FA = ["api-staging.lamp.digital", "api.lamp.digital"] | ||
|
||
useEffect(() => { | ||
if (localStorage.getItem("demo_mode") === "try_it") { | ||
LAMP.initializeDemoDB(demo_db) | ||
} else if (localStorage.getItem("demo_mode") === "self_help") { | ||
LAMP.initializeDemoDB(self_help_db) | ||
} | ||
let query = window.location.hash.split("?") | ||
if (!!query && query.length > 1) { | ||
let src = Object.fromEntries(new URLSearchParams(query[1]))["src"] | ||
|
@@ -276,7 +283,9 @@ function AppRouter({ ...props }) { | |
}, [state]) | ||
|
||
let reset = async (identity?: any) => { | ||
Service.deleteUserDB() | ||
if (identity?.id != "[email protected]") { | ||
Service.deleteUserDB() | ||
} | ||
Service.deleteDB() | ||
if (typeof identity === "undefined" && LAMP.Auth._type === "participant") { | ||
await sensorEventUpdate(null, (state.identity as any)?.id ?? null, null) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { useTranslation } from "react-i18next" | |
import LAMP from "lamp-core" | ||
import { useSnackbar } from "notistack" | ||
import { sensorEventUpdate } from "./BottomMenu" | ||
import { Service } from "./DBService/DBService" | ||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
backdrop: { | ||
|
@@ -129,6 +130,11 @@ export default function EmbeddedActivity({ participant, activity, name, onComple | |
data["timestamp"] = activityTimestamp | ||
data["duration"] = new Date().getTime() - activityTimestamp | ||
setData(data) | ||
if (LAMP.Auth._auth.id === "[email protected]") { | ||
setTimeout(() => { | ||
Service.addUserDBRow("activityEvents", data) | ||
}, 500) | ||
} | ||
setEmbeddedActivity(undefined) | ||
setSettings(null) | ||
} else { | ||
|
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 |
---|---|---|
|
@@ -330,6 +330,7 @@ import zhLocale from "date-fns/locale/zh-CN" | |
import esLocale from "date-fns/locale/es" | ||
import enLocale from "date-fns/locale/en-US" | ||
import hiLocale from "date-fns/locale/hi" | ||
import { getSelfHelpAllActivityEvents } from "./Participant" | ||
|
||
const userLanguages = ["en-US", "es-ES", "hi-IN", "de-DE", "da-DK", "fr-FR", "ko-KR", "it-IT", "zh-CN"] | ||
|
||
|
@@ -470,7 +471,10 @@ export default function Feed({ | |
date.setSeconds(0) | ||
let startTime = date.getTime() | ||
let endTime = startTime + 86400000 | ||
let activityEvents = await LAMP.ActivityEvent.allByParticipant(participant.id, null, startTime, endTime, null, true) | ||
let activityEvents = | ||
LAMP.Auth._auth.id === "[email protected]" | ||
? await getSelfHelpAllActivityEvents(startTime, endTime) | ||
: await LAMP.ActivityEvent.allByParticipant(participant.id, null, startTime, endTime, null, true) | ||
return activityEvents | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,17 +93,52 @@ async function getHiddenEvents(participant: ParticipantObj): Promise<string[]> { | |
return !!_hidden.error ? [] : (_hidden.data as string[]) | ||
} | ||
|
||
export async function getSelfHelpActivityEvents(activityId: string, from: number, to: number) { | ||
let result = [] | ||
return await Service.getActivityEventData("activityEvents", activityId).then((res) => { | ||
if (res) { | ||
result = res | ||
if (from != null) { | ||
result = res?.filter((val) => val.timestamp >= from) | ||
} | ||
if (to != null) { | ||
result = res?.filter((val) => val?.timestamp <= to) | ||
} | ||
} | ||
return result.reverse() | ||
}) | ||
} | ||
|
||
export async function getSelfHelpAllActivityEvents(from?: number, to?: number) { | ||
let result = [] | ||
return await Service.getAllTags("activityEvents").then((res) => { | ||
if (res) { | ||
result = res | ||
if (from != null) { | ||
result = res.filter((val) => val.timestamp >= from) | ||
} | ||
if (to != null) { | ||
result = res.filter((val) => val?.timestamp <= to) | ||
} | ||
} | ||
return result | ||
}) | ||
} | ||
|
||
export async function getEvents(participant: any, activityId: string) { | ||
let from = new Date() | ||
from.setMonth(from.getMonth() - 6) | ||
let activityEvents = await LAMP.ActivityEvent.allByParticipant( | ||
participant?.id ?? participant, | ||
activityId, | ||
from.getTime(), | ||
new Date().getTime(), | ||
null, | ||
true | ||
) | ||
let activityEvents = | ||
LAMP.Auth._auth.id === "[email protected]" | ||
? await getSelfHelpActivityEvents(activityId, from.getTime(), new Date().getTime()) | ||
: await LAMP.ActivityEvent.allByParticipant( | ||
participant?.id ?? participant, | ||
activityId, | ||
from.getTime(), | ||
new Date().getTime(), | ||
null, | ||
true | ||
) | ||
let dates = [] | ||
let streak = 0 | ||
activityEvents.map((activityEvent, i) => { | ||
|
@@ -168,17 +203,19 @@ export default function Participant({ | |
|
||
useEffect(() => { | ||
setLoading(true) | ||
LAMP.Activity.allByParticipant(participant.id, null).then((activities) => { | ||
setActivities(activities) | ||
props.activeTab(tab, participant.id) | ||
let language = !!localStorage.getItem("LAMP_user_" + participant.id) | ||
? JSON.parse(localStorage.getItem("LAMP_user_" + participant.id)).language | ||
: getSelectedLanguage() | ||
? getSelectedLanguage() | ||
: "en-US" | ||
i18n.changeLanguage(language) | ||
// getShowWelcome(participant).then(setOpen) | ||
}) | ||
LAMP.Activity.allByParticipant(participant.id, null, !(LAMP.Auth._auth.serverAddress === "demo.lamp.digital")).then( | ||
(activities) => { | ||
setActivities(activities) | ||
props.activeTab(tab, participant.id) | ||
let language = !!localStorage.getItem("LAMP_user_" + participant.id) | ||
? JSON.parse(localStorage.getItem("LAMP_user_" + participant.id)).language | ||
: getSelectedLanguage() | ||
? getSelectedLanguage() | ||
: "en-US" | ||
i18n.changeLanguage(language) | ||
// getShowWelcome(participant).then(setOpen) | ||
} | ||
) | ||
getHiddenEvents(participant).then(setHiddenEvents) | ||
tempHideCareTeam(participant).then(setHideCareTeam) | ||
}, []) | ||
|
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 |
---|---|---|
|
@@ -62,6 +62,7 @@ const localeMap = { | |
"zh-HK": zhHKLocale, | ||
} | ||
import DateFnsUtils from "@date-io/date-fns" | ||
import { getSelfHelpAllActivityEvents } from "./Participant" | ||
|
||
export const dateInUTCformat = (val) => { | ||
let month = | ||
|
@@ -188,7 +189,10 @@ async function getActivityEvents( | |
from: number, | ||
to: number | ||
): Promise<{ [groupName: string]: ActivityEventObj[] }> { | ||
let original = (await LAMP.ActivityEvent.allByParticipant(participant.id, null, from, to, null, true)) | ||
let original = (LAMP.Auth._auth.id === "[email protected]" | ||
? await getSelfHelpAllActivityEvents(from, to) | ||
: await LAMP.ActivityEvent.allByParticipant(participant.id, null, from, to, null, true) | ||
) | ||
.map((x) => ({ | ||
...x, | ||
activity: _activities.find((y) => x.activity === y.id), | ||
|
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ import PreventDBT from "./PreventDBT" | |
import PreventData from "./PreventData" | ||
import PreventGoalData from "./PreventGoalData" | ||
import VoiceRecoding from "./VoiceRecoding" | ||
import { getSelfHelpAllActivityEvents } from "./Participant" | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
|
@@ -208,10 +209,17 @@ export default function PreventPage({ activityId, type, participantId, ...props | |
setLoading(true) | ||
LAMP.Activity.view(activityId).then((data) => { | ||
setActivity(data) | ||
LAMP.ActivityEvent.allByParticipant(participantId).then((events) => { | ||
setActivityEvents(events.filter((event) => event.activity === activityId)) | ||
setLoading(false) | ||
}) | ||
if (LAMP.Auth._auth.id === "[email protected]") { | ||
getSelfHelpAllActivityEvents().then((events) => { | ||
setActivityEvents(events.filter((event) => event.activity === activityId)) | ||
setLoading(false) | ||
}) | ||
} else { | ||
LAMP.ActivityEvent.allByParticipant(participantId).then((events) => { | ||
setActivityEvents(events.filter((event) => event.activity === activityId)) | ||
setLoading(false) | ||
}) | ||
} | ||
}) | ||
}, []) | ||
|
||
|
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import fr from "javascript-time-ago/locale/fr" | |
import TimeAgo from "javascript-time-ago" | ||
import { useTranslation } from "react-i18next" | ||
import { VegaLite } from "react-vega" | ||
import { getSelfHelpAllActivityEvents } from "./Participant" | ||
TimeAgo.addLocale(en) | ||
const timeAgo = new TimeAgo("en-US") | ||
|
||
|
@@ -186,8 +187,6 @@ const useStyles = makeStyles((theme: Theme) => | |
|
||
export const strategies = { | ||
"lamp.survey": (slices, activity, scopedItem) => | ||
// (slices || []).map((x) => x.duration).reduce((prev, cur) => prev + cur, 0) / slices.length / 1000, | ||
|
||
(slices ?? []) | ||
.filter((x, idx) => (scopedItem !== undefined ? idx === scopedItem : true)) | ||
.map((x, idx) => { | ||
|
@@ -216,15 +215,14 @@ export const strategies = { | |
} else return Number(x?.value.replace(/\"/g, "")) || 0 | ||
}) | ||
.reduce((prev, curr) => prev + curr, 0), | ||
|
||
"lamp.spin_wheel": (slices, activity, scopedItem) => slices[slices.length - 1]?.type ?? 0, | ||
"lamp.jewels_a": (slices, activity, scopedItem) => | ||
"lamp.trails_b": (slices, activity, scopedItem) => | ||
slices.score == "NaN" | ||
? 0 | ||
: (parseInt(slices.score ?? 0).toFixed(1) || 0) > 100 | ||
? 100 | ||
: parseInt(slices.score ?? 0).toFixed(1) || 0, | ||
"lamp.trails_b": (slices, activity, scopedItem) => | ||
"lamp.spin_wheel": (slices, activity, scopedItem) => slices[slices.length - 1]?.type ?? 0, | ||
"lamp.jewels_a": (slices, activity, scopedItem) => | ||
slices.score == "NaN" | ||
? 0 | ||
: (parseInt(slices.score ?? 0).toFixed(1) || 0) > 100 | ||
|
@@ -289,7 +287,10 @@ export const strategies = { | |
*/ | ||
const getPercentageSettings = async (participantId, activities: ActivityObj[]) => { | ||
let percentage = [] | ||
let activityEvents = await LAMP.ActivityEvent.allByParticipant(participantId) | ||
let activityEvents = | ||
LAMP.Auth._auth.id === "[email protected]" | ||
? await getSelfHelpAllActivityEvents() | ||
: await LAMP.ActivityEvent.allByParticipant(participantId) | ||
return await Promise.all( | ||
percentage.concat( | ||
activities.map(async (activity) => { | ||
|
Oops, something went wrong.