How's this?

(defrule more-then-one-item-for-a-given-patient-per-order-1
   ;; matches any order item
   ?i1 <- (order_item (order_id ?order_id) (patient_id ?patient_id)
               (order_item_id ?item_id_1))

   ;; matches only order_items with the same order_id and patient_id
   ;; but a different order_item_id.

   ;; We use > rather than equals in the second pattern so
   ;; that for any given pair, they'll match in only one of the two
   ;; possible permutations. You could change this to use any other
   ;; slot you expect would always be different for the two line items.
        
   ?i2 <- (order_item (order_id ?order_id) (patient_id ?patient_id)
               (order_item_id ?item_id_2&:(> ?item_id_2 ?item_id_1)))

   =>
   (do-something-with ?i1 i2))

If you can't predict which slot will differ, you could do something
like this, which will be less efficient:

(defrule more-then-one-item-for-a-given-patient-per-order-2

   ;; match any order
   ?i1 <- (order_item (order_id ?order_id) (patient_id ?patient_id))

   ;; match any order with the same patient and order; could be the
   ;; same one a second time
   ?i2 <- (order_item (order_id ?order_id) (patient_id ?patient_id))

   ;; weed out the repeats and permutations
   (test (> (get ?i1 factId) (get ?i2 factId)))

   =>
   (do-something-with ?i1 i2))

I think Withers, Ryan(STL) wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello, 
> 
>   Below there is an excerpt of what I am passing to the Rete engine, there
> is a deftemplate for an order_item and two facts asserted as order items.  I
> need to write a rule which will detect if there is more than one line item
> with the same patient id asserted.  I have looked at the unique and exists
> functions and they don't do exactly what I want.  If I find two of the same
> patients on the same order I want the rule to fire.  There could be any
> number of line items on the order. Thanks in advance for any help. 
> 
> Sincerely,
> 
> Ryan Withers 
> 
> 
> (deftemplate order_item (slot order_item_id)(slot order_id)(slot
> item_number)(sl
> ot script_id)(slot required_field1)(slot required_field2)(slot
> required_field3)(
> slot required_field4)(slot patient_id)(slot physician_id)(slot
> product_id)(slot
> quantity)(slot price)(slot discount)(slot dur_status)(slot
> dur_auth_override_cod
> e)(slot value)(slot progress)(slot success)(slot reason)(slot
> timestamp)(slot cr
> eated_by)(slot last_mod_by)(slot create_date)(slot last_mod_date)(slot
> term_date
> )(slot id)(slot order_item_id)(slot dur_response_code)(slot
> dur_response_severit
> y)(slot dur_response_message)(slot created_by)(slot last_mod_by)(slot
> create_dat
> e)(slot last_mod_date)(slot term_date)(slot id)(slot order_item_id)(slot
> stock_i
> d)(slot quantity)(slot created_by)(slot last_mod_by)(slot create_date)(slot
> last
> _mod_date)(slot term_date))
> 
> (assert(order_item (order_item_id 723)(order_id 10244)(patient_id
> 488)(physician
> _id 494)(product_id 21)(quantity 1)(price 0)(discount 100)(value
> ORDER-EDIT)(pro
> gress IN-PROCESS)(timestamp  "2001/07/14 10:19:23")(created_by
> JClark)(last_mod_
> by JClark)(create_date  "2001/07/14 10:19:23")(last_mod_date  "2001/07/14
> 10:19:
> 23")(id 144)(order_item_id 723)(stock_id 345)(quantity 1)(created_by
> InventoryRe
> servation)(last_mod_by InventoryReservation)(create_date  "2001/07/14
> 10:42:29")
> (last_mod_date  "2001/07/14 10:42:29")))
> 
> (assert(order_item (order_item_id 724)(order_id 10244)(patient_id
> 488)(physician
> _id 494)(product_id 22)(quantity 1)(price 0)(discount 100)(value
> ORDER-EDIT)(pro
> gress IN-PROCESS)(timestamp  "2001/07/14 10:23:04")(created_by
> JClark)(last_mod_
> by JClark)(create_date  "2001/07/14 10:20:30")(last_mod_date  "2001/07/14
> 10:23:
> 04")(id 145)(order_item_id 724)(stock_id 348)(quantity 1)(created_by
> InventoryRe
> servation)(last_mod_by InventoryReservation)(create_date  "2001/07/14
> 10:42:29")
> (last_mod_date  "2001/07/14 10:42:29")))
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list (use your own address!) List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to