0

Using the Angular Demo from here, I added a collection of HospitalVisit objects and I wanted to answer the question, "has patient visited an out of state hospital".

Ask you can see I can only compare the HospitalVisit.State field to a string, another field on the same current object (or a dynamic data source), but it can not reference the parent object. How would I do this?

Something like

var p = new Patient();
        var homeSate = p.State;
        var hasBeenOutOfState = p.HospitalVisits.Any(h=> h.State != homeSate);

enter image description here

kevcoder
  • 883
  • 1
  • 15
  • 29
  • What do you need the State to be compared to? A collection of States? An output of a method? Or something else? – Alex Jan 20 '22 at 20:44
  • I want to compare the HospitalVisit.State to the Patient.State. I added more detail to the queston. – kevcoder Jan 20 '22 at 21:06

1 Answers1

0

You cannot get a reference to your main source from sub-sources. Instead, you should declare an in-rule method and get the desired value that way. For instance, you could declare the following method in your Patient type:

[ Method( DisplayName = "Out of State" ) ]
public bool HasOutOfStateVisits(List<HospitalVisit> visits)
{
   return visits != null && visits.Any(v => v.State != this.State);
}

And then use it in your rules like this:

Check if State has any value and Out of State(HospitalVisits) equals to True
Alex
  • 566
  • 1
  • 6
  • 14