Reputation: 91
I know Java and I know C#.
I am a noobie with the JBoss Drools "Guvnor" and just their DRL rules language in general. I need a little help on how to use dates and times correctly in the LHS of rules.
For example, I have to assure data quality in a health care system. Obviously, each patient has a DOB in their record and it is of type java.util.Date.
Okay, so say I want to ensure that the DOB in the data passed as Facts is indeed before today's date. I know, for instance, in C#, you can get the current date/time by saying DateTime.Now.
I want to add a rule in Guvnor that says (and this is pseudo-code):
WHEN patient DOB is before NOW THEN mark patient as valid
My Patient fact is:
declare Patient patientID: integer firstName: text lastName: text dateOfBirth: java.util.Date end
I also have a Dose fact, with a patientID field to link it to what patient got what dose:
declare Dose doseID: integer patientID: integer administeredDate: java.util.Date amount: integer end
Also, say a medication is released on a certain year, 1995, and I want to also check that a dose for a given patient is not administered prior to that year.
How do I do these two? I've tried Googling and Googling but all I get is links to the (utterly-useless) Guvnor User Guide which is pretty badly-written in that it doesn't contain this basic information, i.e., how dates and times work and are written in DRL syntax.
Thank you.
Upvotes: 2
Views: 6514
Reputation: 983
As always there are more than one way to do this. Here is one.
function Date currentTime(){
// The content of this method is Java
return new Date();
}
RULE "my rule"
WHEN
patient : Patient( dateOfBirth < currentTime() )
THEN
// Everything in THEN part is Java
patient.setValid(true); // Notice I added a valid field into the fact type
update(patient);
END
The other rule you asked for
Also, say a medication is released on a certain year, 1995, and I want to also check that a dose for a given patient is not administered prior to that year.
RULE "Second Rule"
WHEN
patient : Patient()
not Dose( patientId == patient.patientId, administeredDate < 01-Jan-1995 ) // The date format can be changed if you want to.
WHEN
System.out.println( "Patient " + patient.getFirstName + " " +patient.getLastName() + " was not given a dose before." );
END
The Guvnor user guide does not cover the language basics. You can find them from here. Guvnor is meant to provide you guided editors for writing the DRL or storing the files containing DRL. You check what the guided rule would look like if it was written in DRL by pressing the "View Source" button that is in each asset editor that produces DRL.
Upvotes: 1