Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created July 30, 2021 06:26
Show Gist options
  • Save tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.
Save tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.

Revisions

  1. tmbtech created this gist Jul 30, 2021.
    106 changes: 106 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,106 @@
    // TODO: this needs to be refactored to a better location
    const brandNames = {
    botox: 'BOTOX®',
    juvederm: 'JUVÉDERM®',
    cool_sculpting: 'CoolSculpting® and CoolSculpting® Elite',
    cool_tone: 'CoolTone®',
    diamond_glow: 'DiamondGlow®',
    kybella: 'KYBELLA®',
    latisse: 'LATISSE®',
    natrelle: 'Natrelle®',
    skin_medica: 'SkinMedica®',
    };

    const ImportantSafetyInformationMachine = Machine(
    {
    id: 'isi-builder',
    initial: 'start',
    context: {
    brands: [''],
    codeIds: [],
    },
    states: {
    start: {
    on: {
    '': [
    { target: 'containsBotox', cond: 'containsBotox' },
    {
    target: 'singleSafetyAndPrescribingInfo',
    cond: 'hasKybellaOrLatisse',
    actions: 'setSingleSafetyInformationOnly',
    },
    {
    target: 'importantSafetyInformationOnly',
    actions: 'setImportantSafetyInformationOnly',
    },
    ],
    },
    },
    containsBotox: {
    on: {
    '': [
    {
    target: 'botoxOnly',
    cond: 'hasOnlyOneCondition',
    actions: 'setBotoxOnly',
    },
    {
    target: 'botoxSafetyAndPrescribingInfo',
    cond: 'hasKybellaOrLatisse',
    actions: ['setBotoxOnly', 'setSafetyAndPrescribingInfo'],
    },
    {
    target: 'botoxOnlyImportantSafetyInformationOnly',
    actions: ['setBotoxOnly', 'setImportantSafetyInformationOnly'],
    },
    ],
    },
    },
    singleSafetyAndPrescribingInfo: {},
    importantSafetyInformationOnly: {},
    doesNotContainBotox: {},
    hasOnlyOneCondition: {},
    botoxOnly: {},
    botoxSafetyAndPrescribingInfo: {},
    botoxOnlyImportantSafetyInformationOnly: {},
    },
    },
    {
    actions: {
    setBotoxOnly: assign({
    codeIds: (context) => {
    return [...context.codeIds, 'BotoxOnly'];
    },
    }),
    setImportantSafetyInformationOnly: assign({
    codeIds: (context) => [
    ...context.codeIds,
    'ImportantSafetyInformationOnly',
    ],
    }),
    setSingleSafetyInformationOnly: assign({
    codeIds: (context) => [
    ...context.codeIds,
    'SingleSafetyAndPrescribingInfo',
    ],
    }),
    setSafetyAndPrescribingInfo: assign({
    codeIds: (context) => {
    return [...context.codeIds, 'SafetyAndPrescribingInfo'];
    },
    }),
    },
    guards: {
    doesNotContainBotox: (context) =>
    !context.brands.includes(brandNames.botox),
    containsBotox: (context) => context.brands.includes(brandNames.botox),
    hasOnlyOneCondition: (context) => context.brands.length === 1,
    hasKybellaOrLatisse: (context) => {
    return context.brands.some(
    (brand) =>
    brand === brandNames.kybella || brand === brandNames.latisse
    );
    },
    },
    }
    );