Unusual Behavior in modify facts

20 views
Skip to first unread message

zaman rafique

unread,
Aug 27, 2025, 9:33:38 PM (10 days ago) Aug 27
to CLIPSESG
Hi,

We have observed an unexpected behavior in the modify function. For the facts mentioned below, when the rule is executed, it behaves as expected for the era-line-item with order 1. However, when the same rule runs for order 2, the line item is being retracted. It is important to note that the same value is being passed to Current-responsible-id in both cases.  

Facts:

(assert

(era-line-item
(id 17201)
(order 1)
(procedure-id 4640)
(is-active False)
(code "J3420")
(code-qualifier "N4")
(cpt1 "J3420")
(cpt1-qualifier "HC")
(charge-amount 2.37)
(paid-amount 0.95)
(paid-units 1.00)
(allowed-amount 0.95)
(service-end-date "2025-08-05")
(service-start-date "2025-08-05")
(remark-codes "N16")
(remark-code-description "Family/member Out-of-Pocket maximum has been met. Payment based on a higher percentage.")
)
(era-line-item-adjustment
(id 17201)
(order 1)
(code "J3420")
(group-code "CO")
(original-group-code "CO")
(reason-code "45")
(original-reason-code "45")
(amount 1.42)
)
(era-line-item
(id 17202)
(order 2)
(procedure-id 19156)
(is-active False)
(code "96372")
(code-qualifier "HC")
(charge-amount 36.53)
(paid-amount 11.17)
(paid-units 1.00)
(allowed-amount 11.40)
(service-end-date "2025-08-05")
(service-start-date "2025-08-05")
(remark-codes "N16")
(remark-code-description "Family/member Out-of-Pocket maximum has been met. Payment based on a higher percentage.")
)
(era-line-item-adjustment
(id 17202)
(order 2)
(code "96372")
(group-code "CO")
(original-group-code "CO")
(reason-code "253")
(original-reason-code "253")
(amount 0.23)
)
(era-line-item-adjustment
(id 17202)
(order 2)
(code "96372")
(group-code "CO")
(original-group-code "CO")
(reason-code "45")
(original-reason-code "45")
(amount 25.13)
)

(current-responsible
(insurance-id 5289)
(plan-id 31)
(payer-display-name "HUMANA")
(payer-id "61101")
(priority "P")
)
(subscriber
(subscriber-id 5289)
(insurance-code "MB")
(insurance-type-code "-1")
(manual-insurance-status 0)
(eligiblity-inquiry-count 0)
(eligibility-inquiry-pos "11")
(eligibility-inquiry-dos "2025-08-04")
(eligibility-inquiry-service-types "30")
(payer-responsibility "P")
(address1 "1274 NW 79TH ST APPT 103")


)

(payer
(plan-id 31)
(rendering-provider-required "SITUATIONAL")
(display-name "HUMANA")
(last-name "HUMANA INC")
(payer-id "61101")
(real-time-payer-id "HUMANA")
(is-electronic TRUE)
(is-accept-cob-claims TRUE)
(is-rcm-plan TRUE)
(is-valid FALSE)

)


(patient-insurance-info
(insurance-id 5289)
(is-active TRUE)
(is-default TRUE)
(edi-submission-hsitory-exist TRUE)
(priority "P")
(insurance-code "MB")
(insurance-type-code "-1")
(payer-id "61101")
(real-time-payer-id "HUMANA")
(plan-id 31)
)
(patient-insurance-info
(insurance-id 5290)
(priority "P")
(insurance-code "MB")
(insurance-type-code "-1")
(sign-on-file-date "2022-04-01")
(effective-date "2022-04-01")
(termination-date "2024-01-31")
(first-name "FRANCINA")
(last-name "LLOYD")
(dob "1944-06-22")
(gender "FEMALE")
(policy-number "1AF2G44AP24")
(relationship-code "18")
(address1 "1274 NW 79TH ST APPT 103")
(city "MIAMI")
(state "FL")
(is-valid-state TRUE)
(zip-code "33147")
(is-valid-zip-code TRUE)
(payer-name "MEDICARE-FL")
(payer-display-name "MEDICARE OF FLORIDA")
(payer-filing-indicator "MB")
(payer-id "09102")
(real-time-payer-id "CMS")
(plan-id 34)
(is-rcm-plan TRUE)
(payer-address1 "PO BOX 44117")
(payer-city "JACKSONVILLE")
(payer-state "FL")
(payer-zipcode "32231")
)

)

Rule IS: 
(defrule NEXT-RESPONSIBLE::update-current-responsible-on-line-item
?eli <- (era-line-item
(id ?id)
(order ?order)
(current-responsible-id 0)
)
(current-responsible (insurance-id ?insurance-id-current))
(not (exists (current-responsible-set ?id)))
=>
(modify ?eli (current-responsible-id ?insurance-id-current))
(assert (current-responsible-set ?order))
)

Below is the result:
CLIPS> (run 1)
<== f-15067 (era-line-item ... (current-responsible-id 0) ...)
==> f-16317 (current-responsible-set 2)
CLIPS> (run 1)
<== f-15065 (era-line-item ... (current-responsible-id 0) ...)
==> f-15065 (era-line-item ... (current-responsible-id 5289) ...)
==> f-16318 (current-responsible-set 1)

Can anyone help on that as we are unable to identify the problem using IDE.

Thanks in advance,

CLIPS Support

unread,
Aug 27, 2025, 9:56:17 PM (10 days ago) Aug 27
to CLIPSESG
I couldn't reproduce the issue.

         CLIPS (6.4.2 1/14/25)
CLIPS> (unwatch all)
CLIPS>
(deftemplate era-line-item
   (slot id)
   (slot order)
   (slot current-responsible-id (default 0))
   (slot procedure-id)
   (slot is-active)
   (slot code)
   (slot code-qualifier)
   (slot cpt1)
   (slot cpt1-qualifier)
   (slot charge-amount)
   (slot paid-amount)
   (slot paid-units)
   (slot allowed-amount)
   (slot service-end-date)
   (slot service-start-date)
   (slot remark-codes)
   (slot remark-code-description))
CLIPS>
(deftemplate current-responsible
   (slot insurance-id))
CLIPS>    
(deffacts start

   (era-line-item
      (id 17201)
      (order 1)
      (procedure-id 4640)
      (is-active False)
      (code "J3420")
      (code-qualifier "N4")
      (cpt1 "J3420")
      (cpt1-qualifier "HC")
      (charge-amount 2.37)
      (paid-amount 0.95)
      (paid-units 1.00)
      (allowed-amount 0.95)
      (service-end-date "2025-08-05")
      (service-start-date "2025-08-05")
      (remark-codes "N16")
      (remark-code-description "Family/member Out-of-Pocket maximum has been met. Payment based on a higher percentage."))
   (era-line-item
      (id 17202)
      (order 2)
      (procedure-id 19156)
      (is-active False)
      (code "96372")
      (code-qualifier "HC")
      (charge-amount 36.53)
      (paid-amount 11.17)
      (paid-units 1.00)
      (allowed-amount 11.40)
      (service-end-date "2025-08-05")
      (service-start-date "2025-08-05")
      (remark-codes "N16")
      (remark-code-description "Family/member Out-of-Pocket maximum has been met. Payment based on a higher percentage."))
   (current-responsible
      (insurance-id 5289)))
CLIPS>
(defrule update-current-responsible-on-line-item

?eli <- (era-line-item
(id ?id)
(order ?order)
(current-responsible-id 0))
(current-responsible (insurance-id ?insurance-id-current))
(not (exists (current-responsible-set ?id)))
    =>
(modify ?eli (current-responsible-id ?insurance-id-current))
(assert (current-responsible-set ?order)))
CLIPS> (reset)
CLIPS> (watch facts)
CLIPS> (run 1)
<== f-1     (era-line-item ... (current-responsible-id 0) ...)
==> f-1     (era-line-item ... (current-responsible-id 5289) ...)
==> f-4     (current-responsible-set 1)
CLIPS> (run 1)
<== f-2     (era-line-item ... (current-responsible-id 0) ...)
==> f-2     (era-line-item ... (current-responsible-id 5289) ...)
==> f-5     (current-responsible-set 2)
CLIPS>


zaman rafique

unread,
Aug 28, 2025, 6:49:31 AM (10 days ago) Aug 28
to CLIPSESG
Hi,

I have updated the rule as mentioned below, and the current-responsible-id is now being asserted correctly. Could you please confirm if the earlier issue was due to the older version, as I am currently using 6.4?

Rule:


(defrule NEXT-RESPONSIBLE::update-current-responsible-on-line-item
?eli <- (era-line-item
(id ?id)
(order ?order)
(current-responsible-id 0)
)
(current-responsible (insurance-id ?insurance-id-current))
(not (exists (update-current-responsible-on-line-item ?id)))

=>
(modify ?eli (current-responsible-id ?insurance-id-current))
(assert (update-current-responsible-on-line-item ?id))
)

Output:

CLIPS> (run 3)
==> f-16140 (current-responsible (insurance-id 5289) (plan-id 31) (payer-display-name "HUMANA") (payer-id "61101") (priority "P"))
==> f-16141 (next-responsible (insurance-id 5286) (plan-id 16) (payer-id "00590") (priority "S") (is-forcefull FALSE))

<== f-15067 (era-line-item ... (current-responsible-id 0) ...)
==> f-15067 (era-line-item ... (current-responsible-id 5289) ...)
==> f-16142 (update-current-responsible-on-line-item 17202)

CLIPS> (run 1)
<== f-15065 (era-line-item ... (current-responsible-id 0) ...)
==> f-15065 (era-line-item ... (current-responsible-id 5289) ...)
==> f-16143 (update-current-responsible-on-line-item 17201)

CLIPS Support

unread,
Aug 29, 2025, 1:58:14 PM (9 days ago) Aug 29
to CLIPSESG
I can't reproduce the issue in either 6.3 or 6.4 with the code fragments you've provided. There were some changes between 6.3 and 6.4 in the way the modify command works, but without being able to reproduce the issue, I can't tell if it's related to the problem you're having.

6.4 Change:
The modify command now preserves the fact-index and fact-address of the fact being modified. Modifying a fact without changing any slots no longer retracts and reasserts the original fact. If all slot changes specified in the modify command match the current values of the fact to be modified, no action is taken.
Reply all
Reply to author
Forward
0 new messages