Skip to content

Instantly share code, notes, and snippets.

@allencoded
Created June 26, 2020 07:34
Show Gist options
  • Save allencoded/a7757e6fba81b8b7186c5f528454df9b to your computer and use it in GitHub Desktop.
Save allencoded/a7757e6fba81b8b7186c5f528454df9b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const introScreen = {
id: "6cdfb4bc-b762-11ea-b3de-0242ac130004",
type: "RECOMMENDATION",
facts: [
{
id: "845cfa0e-b763-11ea-b3de-0242ac130004",
title: "Mild Severity"
}
]
};
const riskAssessmentScreen = {
id: "d2c67306-b762-11ea-b3de-0242ac130004",
type: "CALCULATOR",
facts: [
{
id: "c039220a-b763-11ea-b3de-0242ac130004",
title: "Oxygen Saturation",
answers: [
{
label: "Normal > 90",
value: "b1edb6dc-b76a-11ea-b3de-0242ac130004"
},
{
label: "Abnormal < 90",
value: "cf280fe0-b76a-11ea-b3de-0242ac130004"
}
]
}
]
};
const dischargeScreen = {
id: "20edb080-b763-11ea-b3de-0242ac130004",
type: "RECOMMENDATION",
facts: [
{
id: "2229f1ec-b764-11ea-b3de-0242ac130004",
title: "Discharge Home"
}
]
};
const admitScreen = {
id: "a7f375ee-b76b-11ea-b3de-0242ac130004",
type: "RECOMMENDATION",
facts: [
{
id: "bbc40dcc-b76b-11ea-b3de-0242ac130004",
title: "Admit"
}
]
};
const pathway = {
id: "cbc44692-b761-11ea-b3de-0242ac130004",
title: "Mild Severity Management",
screens: [
introScreen.id,
riskAssessmentScreen.id,
dischargeScreen.id,
admitScreen.id
],
transitionMap: {
[introScreen.id]: {
rules: [
{
goTo: riskAssessmentScreen.id
}
]
},
[riskAssessmentScreen.id]: {
rules: [
{
factKeys: ["b1edb6dc-b76a-11ea-b3de-0242ac130004"],
goTo: dischargeScreen.id
},
{
factKeys: ["cf280fe0-b76a-11ea-b3de-0242ac130004"],
goTo: admitScreen.id
}
]
},
[dischargeScreen.id]: {
final: true
},
[admitScreen.id]: {
final: true
}
}
};
function statesBuilder() {
const states = {};
Object.entries(pathway.transitionMap).forEach(([key, value]) => {
const pathwayId = key;
const screen = value;
states[pathwayId] = {};
if (screen.rules) {
// TODO: BUILD CONDITIONALS
states[pathwayId].on = screen.rules.reduce((acc, cur) => {
return { ...acc, ...{ [cur.goTo]: cur.goTo } };
}, {});
} else {
states[pathwayId].type = "final";
}
});
return states;
}
function buildMachine() {
return {
id: pathway.id,
initial: pathway.screens[0],
states: statesBuilder()
};
}
const fetchMachine = Machine(buildMachine());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment