9 Replies Latest reply on Nov 14, 2013 4:53 AM by Fiona Guy-Oracle

# How do I create a temporal attribute which is true for all days in all intervals over x days?

For example, given this source data:

Input temporal attribute to the function:

1 Jan : True

2 Jan: True

3 Jan: True

4 Jan: False

5 Jan: True

6 Jan: True

given x = 2,

then my result temporal attribute should have:

1 Jan: True

2 Jan: True

3 Jan: True

4 Jan: False

5 Jan: False

6 Jan: False

Another example might be: 'tell me all the times a person was resident when they were resident for x days consecutively'.

We have tried numerous combinations of the temporal functions to no avail.

How can I do it with OPA rules?

UPDATE:  added a test project with a test case: https://www.dropbox.com/s/05x84ycyc5v7tcu/test.zip?m

In this test case, the qualifying period is 182 days.

• ###### 1. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Hi,

I put together a quick solution for this and it is possible in OPA rules. I can't seem to attach pictures of the temporal visualisation which would help explain how the rules work, but take a look at the following (note, this is a quick solution so these might not be the best names for attributes, etc.).

inputs

the day is a residence day (temporal) -- You will probably want to build this from entity instances.

the number of required consecutive residence days -- 2 / 3 / 4 etc.

the range start date = 2013-01-01 -- you will want to use rules to prove these rather than hardcoding (i.e the earliest residence period start date)

the range end date = 2014-01-01

goals

the number of continuous periods that meet the consecutive residence days criteria = IntervalDailySum(the range start date, AddDays(the range end date, 1), the day is the start of a continuous period that meets the consecutive residence days criteria – number value (temporal))

Intermediates

 the   day is the start of a continuous period that meets the consecutive residence days criteria – number value (temporal) 1 the day is the start of a continuous period that meets the consecutive residence days   criteria (temporal) 0 otherwise

the day is the start of a continuous period that meets the consecutive residence days criteria (temporal) if

... the day before the day is not a residence day (temporal) and

...the day is a residence day (temporal) and

... IntervalAlways(the day’s date (temporal), the date which is the number of required consecutive
residence days after the day’s date (temporal), the day is a residence day (temporal))

System /config rules

the day’s date (temporal) = AddDays(the range start date, TemporalDaysSince(the range start date, the range end date))

the day before the day’s date (temporal) = AddDays(the day’s date (temporal), -1)

the date which is the number of required consecutive residence days after the day’s date (temporal) = AddDays(the day’s date (temporal), (the number of required consecutive residence days))

the day before the day is a residence day (temporal) if

...ValueAt(the day before the day’s date (temporal), the day is a residence day (temporal))

With an input of:

the number of required consecutive residence days = 3

The day is a residence day (temporal) is ...FALSE, 2013-10-09 TRUE, 2013-10-12 FALSE, 2013-10-14 TRUE, 2013-10-24 I get the answer of 2.

The person was resident on 09, 10, and 11 (3 consecutive days) and from the 14 to 23rd so they have two periods in the range.

I hope that goes some way to solving your problem. It shouldn't be too hard to create a "smoothed out" temporal attribute. I have assumed this is all global to create a quick solution but you will need to build up "the day is a residence day (temporal)" from instances if you wanted a better solution.

It might be best to contact me directly as it is difficult to explain over the forums without pictures etc.

Thanks,

Ben

• ###### 2. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

For that problem above specifically, I wrote the following:

the person is eligible for reimbursement if

the person is resident

and

TemporalAlwaysDays(2, the person is resident)

Between the 2 conditions they are checking that the person is resident on the day, and also the day before. by adding numbers to the temporal function you can increase the number of residence days required.

• ###### 3. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Here's my solution:

The person has been eligible for the required number of days if

IntervalAlways(The date the required number of days days before the temporal date, the temporal date, the person is eligible)

the temporal date = AddDays(2012-01-01,TemporalDaysSince(2012-01-01, the current date))

Note that "the date ... before ...." is the plain language form of the AddDays function (so I'm using the AddDays function to subtract days from the temporal date) and "the current date" is a recognized built-in function that returns the current date.

• ###### 4. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Thanks Fiona.  Do you think this will work when there are more than one intervals over x days in the input temporal attribute?

• ###### 5. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Just as a FYI, the reason the solution I proposed is more complex is because I tried to solve your original request,

"'tell me all the times a person was resident when they were resident for x days consecutively'"

These rules will do that - they will allow you to count in a range how many times the person had 3 (or whatever) consecutive days - i.e, perhaps the person is leaving the country and coming back often.

Ben

• ###### 6. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Hi Ben,

I should have been clearer in my request.  When I said 'tell me all the times', I didn't mean 'tell me how many times'.   I mean tell me every day the person was resident - the sort of info a temporal attribute provides.

• ###### 7. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

Hi Michael,

I experimented with this, but it appears that the resulting temporal attribute does not include the time BEFORE the person qualified.

If there were some way of creating a creating a temporal attribute based on your rules that started x days earlier, that would work.

Can you think of any way to do that?

• ###### 8. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

I'm not completely understand what you are trying to do, but when I set mine up I used an initial value of true for residence.

It looks like Ben and Fiona's solutions are a better fit!

• ###### 9. Re: How do I create a temporal attribute which is true for all days in all intervals over x days?

35fdbc45-7128-46dc-8eb0-3cb5e4d9eddf wrote:

Thanks Fiona.  Do you think this will work when there are more than one intervals over x days in the input temporal attribute?

Not sure I understand your question but if you are trying to use this with different values of x, I would create separate variables for your conclusion.  Eg if Santa requires you to be good for 10 days to get a present at Christmas and your mum requires you to be good for 14 days to get a present at Christmas (ie x could be 10 or 14), I would create 2 separate rules:

The person has been good for the parents' required number of days if

IntervalAlways(The date the parents' required number of days days before the temporal date, the temporal date, the person is good)

The person has been good for Santa's required number of days if

IntervalAlways(The date Santa's required number of days days before the temporal date, the temporal date, the person is good)

Sorry for the childish example :-)