question

Chandler avatar image
0 Likes"
Chandler asked Chandler commented

Releasing resources only if a label exists - as user command? (healthcare)

I have been working on this and it is nearly working, but I need help to understand why I can't get the right function with a user command.

I am running patients through a release resource, though it is ambiguous which resources they have. I want all patients to release resources, but avoid throwing exceptions if the label does not exist.

This works, when put into the Resource field:

1695236399537.png

  1. /**Custom Code*/
  2. Object current = param(1);
  3. Object patient = current;
  4. treenode activity = param(2);
  5. Token token = param(3);
  6. treenode processFlow = ownerobject(activity);
  7.  
  8. Array ret = [];
  9.  
  10. if (patient.Locations?){
  11. for (int i = 1; i <= patient.Locations.length; i++){
  12. ret.push(i);
  13. }
  14. }
  15. else{
  16. ret.push(0x0);
  17. }
  18.  
  19. return ret;

But similar code does not work when I run it as a user command (it also doesn't work when I run it as code directly in the Resource field).

1695236448426.png

1695236485118.png

  1. /**Custom Code*/
  2. Object current = param(1);
  3. Object patient = current;
  4. string lbl = param(2);
  5.  
  6. Array ret = [];
  7.  
  8. if (patient.labels[lbl]){
  9. for (int i = 1; i <= patient.labels[lbl].subnodes.length; i++){
  10. ret.push(i);
  11. }
  12. }
  13. else{
  14. ret.push(0x0);
  15. }
  16.  
  17. return ret;


What am I missing here?

release_ambiguous_3.fsm

FlexSim 23.1.2
labelshealthcarescriptuser command
· 2
5 |100000

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

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

Looking at this again, I think you're overcomplicating things. You shouldn't have to write a complicated user command to handle this case. For example, you could set up the Release activity like this:

ReleaseAll.fsm1695419041949.png

Choose the Release All option from the dropdown of the Location Resource field and then set the Label field to

  1. person.labels.assert("Locations")

which will add the label if it doesn't exist. Or if you don't want to add the label in that case

  1. person.labels["Locations"] ? person.labels["Locations"] : 0

1695419041949.png (17.1 KiB)
releaseall.fsm (50.3 KiB)
· 1
5 |100000

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

Chandler avatar image
0 Likes"
Chandler answered Chandler commented

I figured it out, or at least a way to get the right answer:

Where I used:

  1. patient.labels[lbl].subnodes.length

...while I would expect that to work, I substituted:

  1. patient.labels[lbl].evaluate().length

...which gives me the array or value of the label explicitly, so I am getting the length property of the array instead of the treenode.

Seems the same to me, no worse anyway, so that'll do!

· 4
5 |100000

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