Hi everyone, just getting to grips with Perchance, love the functionality and simplicity. Not a coder, so coming at this as a newbie.

I’m trying to build a dental patient generator for students to practice diagnosis on. I’ve got a simple version working: https://perchance.org/91ba5azokj But I need some condition-based logic so that the relevant variables only apply to the front or back tooth.

Front tooth If UL1 or LR2, it can link with:

• Mesial, Distal, Buccal or Lingual/Palatal • Composite or Glass Ionomer Cement • Any medical history • Any presenting complaint • Any ‘other’ item

Back tooth If UR6, UR4, LL6 or LR7, it can link with:

• MO, DO, MOD • Amalgam or Composite • Any medical history • Any presenting complaint • Any ‘other’ item

I can’t see how to build this with the plug-ins I’ve explored and having read the tutorials (a few times!). Any tips? I’ve got the information for the medical history, presenting complaints and other items to add later.

  • VioneTM
    link
    English
    4
    edit-2
    7 months ago

    Here is a modified generator.

    So first, we store the selection from the tooth list in a variable called x. We use .evaluateItem on the tooth so we can have the ‘string’ / evaluated form of the item i.e. a text without the perchance syntax.

    What we have on the surface list is what we call Dynamic Odds. Basically, it modifies the odds of the items in the list depending on the ‘condition’ that is on the odds. Essentially a ‘If/Else’ statement to control the odds/probability of an item to be chosen.

    In this case, we use the value on the variable x and check if it ‘includes’ a certain string, which would be your conditions ‘UL1’ and ‘LR2’.

    On the first three items:

    surface
      Mesio-occlusal (MO) ^[!x.includes('UL1') && !x.includes('LR2')]
      Disto-occlusal (DO)^[!x.includes('UL1') && !x.includes('LR2')]
      Mesio-occlusal-distal (MOD)^[!x.includes('UL1') && !x.includes('LR2')]
      ...
    

    We use the native JavaScript method .includes() to check if the value on x includes a certain string, in this case it is checking for ‘UL1’ and ‘LR2’. However, we are using the ! or ‘NOT’ notation to invert it, so we are checking if the string doesn’t contain the following strings. We then use the && or ‘AND’ notation to only return a ‘true’ statement if and only if BOTH conditions are true.

    In this case, it would be true if x doesn’t include UL1 AND LR2. Which means other than UL1 and LR2, the engine wouldn’t be able to ‘pick’ those first three items unless x doesn’t includes UL1 and LR2

    On the last items:

    surface
      ...
      Buccal (B)^[x.includes('UL1') || x.includes('LR2')]
      Labial (L)^[x.includes('UL1') || x.includes('LR2')]
      Palatal (P)^[x.includes('UL1') || x.includes('LR2')]
      Distal (D)^[x.includes('UL1') || x.includes('LR2')]
      Mesial (M)^[x.includes('UL1') || x.includes('LR2')]
      ...
    

    We do the opposite, we only allow the engine to select those items ONLY if x has UL1 OR LR2. The || is the OR operator in which it would return ‘true’ if only one of the items are ‘true’.

    I also added on the generator my ‘debugging’ utilities in which you can see the how the ‘odds’ are on the items depending on the value on x.

    Here are some resources to read: