question

Chandler avatar image
1 Like"
Chandler asked Chandler commented

How to get a label using a variable?

I am trying to use a string variable in a reference to a patient label, to check the value of multiple labels inside a loop inside of an Assign Labels object.

When tokens enter this Assign Labels, they have several labels set to 0 or 1 depending on whether they need certain imaging tests.

The new label value should be a 0 if all of several labels are set to 0, or 1 if there are any labels set to 1.

I am currently assigning these labels to the patient (they are "xray", "ct", etc. 0/1 for each) and trying to evaluate them by referencing the list in a table, as pictured below:

  1. /**Custom Code*/
  2. Object current = param(1);
  3. Object patient = current;
  4. treenode activity = param(2);
  5. Token token = param(3);
  6. Variant assignTo = param(4);
  7. string labelName = param(5);
  8. treenode processFlow = ownerobject(activity);
  9.  
  10. print(patient);
  11.  
  12.  
  13. int imgCount = 0; // set count of imaging processes to 0
  14.  
  15. // check the table of imaging assignment values for imaging names
  16. Table headers = Model.find("Tools/GlobalTables/ptFlowPcts");
  17.  
  18. print(headers);
  19. print(headers.numCols);
  20.  
  21. for (int i = 1; i = headers.numCols; i++){ // loop through the number of columns
  22.     string img = headers.getColHeader(i); // get the column name (imaging type) for each loop
  23.     imgCount += patient.img; // try to get the 0 or 1 value of this label
  24. }
  25. if (imgCount = 0){
  26.     return 0; // return 0 (no) only if there are no imaging called for
  27. }
  28. else{
  29.     return 1; // return 1 if one or more imaging is called for
  30. }

The question at hand is: how can i reference a label on a patient using a variable, so that I can check an arbitrary number of labels in a code block? I have tried a few different things:

    1. label(patient, img)
    1. patient.img
    1. patient."img"
    1. patient.labels[img].value
    1. patient.labels[img].evaluate()
  • ... and every other combination I could come up with.

Some of them led to a crash, some just threw an exception saying the label didn't exist. I am at the point where I just have to say I don't know how this should work.

---

Ideally I would just have a label that contains an array with a list of imaging randomly assigned based on our client data. And now that I think about it, I should be able to do that with code. But I'd still like to know better how to do what I described above.

Thanks in advance, you are all always so helpful!

FlexSim 23.1.0
flexscriptlabelscustom codeassigning labels
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Chandler commented

The correct way to get a label node from a string variable is

  1. patient.labels[img]

Then to get the value off that node you can use .value or .evaluate() if you want it to execute a FlexScript node:

  1. patient.labels[img].value
  2. patient.labels[img].evaluate()

Here's an example model that demonstrates it working

LabelFromString.fsm


labelfromstring.fsm (25.9 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.