<p dir="ltr">Try prefixing MedicationRecord with &quot;exists&quot;. See the user guide for more information. </p>
<p dir="ltr">Sent on the move</p>
<div class="gmail_quote">On 9 Jan 2014 03:36, &quot;Ray Hooker&quot; &lt;<a href="mailto:ray.hooker@me.com">ray.hooker@me.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Wolfgang,  Thanks.  That works nicely.  I do have a followup question.  I wrote the following query:<div><br></div><div><div style="margin:0px;font-size:11px;font-family:Monaco">rule &quot;Find patient taking <span style="text-decoration:underline">Atorvastin</span> (<span style="text-decoration:underline">Lipitor</span>)&quot;</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">        </span>dialect &quot;<span style="text-decoration:underline">mvel</span>&quot;</div><div style="margin:0px;font-size:11px;font-family:Monaco">
<span style="white-space:pre-wrap">        </span>when</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                </span>$p: PatientRecord($<span style="text-decoration:underline">meds</span>: <span style="text-decoration:underline">medications</span>)</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                </span>MedicationRecord(getCode(&quot;RxNorm&quot;).contains(&quot;617314&quot;)) from $<span style="text-decoration:underline">meds</span></div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">        </span>then</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                </span>System.out.println(&quot;Found a patient taking <span style="text-decoration:underline">Lipitor</span>: &quot;+$p.medical_record_number);</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                </span>results.addResult(new Result(&quot;test&quot;,$p.medical_record_number,&quot;Found Patient Taking <span style="text-decoration:underline">Lipitor</span>&quot;,&quot;now&quot;));</div>
<div style="margin:0px;font-size:11px;font-family:Monaco">end</div><div style="margin:0px;font-size:11px;font-family:Monaco"><br></div><div style="margin:0px;font-size:11px;font-family:Monaco">The problem is that a patient record may have multiple times where this was prescribed.  How would I change the query so that it does not repeat the find so that it is logically:</div>
<div style="margin:0px;font-size:11px;font-family:Monaco">“If the patient ever took Lipitor… or if there is any record of the patient taking Lipitor then flag then…”  instead of flagging for each hit??  So it only flags a patient with at least one medication record indicating Lipitor…</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><br></div><div style="margin:0px;font-size:11px;font-family:Monaco">Thanks,</div><div><br></div><div><br></div><div>Ray<br><div><div>On Jan 2, 2014, at 12:36 PM, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt; wrote:</div>
<br><blockquote type="cite">As you describe it, here&#39;s the way to refer to a particular medication:<br><br>   Patient( $meds: medications )<br>   Medication( drugCode == &quot;55749-003-01&quot; ) from $meds<br><br>This rule determines whether the patient has this particular<br>
medication. There are other operators that might be useful:<br><br>  Medication( drugCode str[startsWith] &quot;55749-003&quot; ) from $meds<br><br>Inserting the Medication objects with a backlink to the Patient can<br>simplify rule evaluation, which may depend on the number and<br>
complexity of the rules. Compare:<br><br>   Patient( $meds: medications )<br>   Medication( drugCode == &quot;55749-003-01&quot; ) from $meds<br>   Medication( drugCode == &quot;55799-565-01&quot; ) from $meds<br><br>with<br>
<br>   $p: Patient()<br>   Medication( drugCode == &quot;55749-003-01&quot;, patient == $p )<br>   Medication( drugCode == &quot;55799-565-01&quot;, patient == $p )<br><br>Much depends on the number of facts you&#39;ll need to process.<br>
<br>To answer your question, &quot;Takes&quot; was a class name I invented to refer<br>to the relation as an object, and &quot;this&quot; is Java&#39;s &quot;this&quot;, referring<br>to the matching object.<br><br>-W<br><br>
<br>On 02/01/2014, Ray Hooker &lt;<a href="mailto:ray.hooker@me.com" target="_blank">ray.hooker@me.com</a>&gt; wrote:<br><blockquote type="cite">Wolfgang,   So in your case you were envisioning the possibility of a Takes<br>
object that matched between a particular medication and the patient.<br>Actually we are fairly close in the case of medications.<br><br>As you probably know MongoDB allows for documents.   In this case, the<br>patient’s document contains subdocuments.  In the case of medications, this<br>
semantically means “as of the date of this patient document, the patient is<br>taking the following medicine listed by the applicable code and text<br>description”.<br><br>When read from the DB, you actually have a Java object Patient (or “Record”)<br>
that has a method “medications” that returns a set of “Medication” objects.<br>The parent knows about the medication through the set “medications”.  I<br>certainly could assert each patient/ record and for each of those assert<br>
each subdocument, inserting a key back to the parent.<br><br>So the rule would need to identify, for example, any case where a particular<br>had a medication object where the drug code matched a particular code or set<br>
of codes.<br><br>Any suggestions are appreciated.  Also in the example below, is “Takes” a<br>function  and what does “this” refer to?<br><br>Thanks,<br><br>Ray<br>On Jan 2, 2014, at 2:01 AM, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt; wrote:<br>
<br><blockquote type="cite">Ideally, a relation is represented by separate objects. Then you might<br>have<br>a rule<br><br>  $p: Patient()<br>  $p: Takes( patient == $p, $m: medication )<br>  Medication( this == $m )<br>
<br>and this rule will fire for each medication of the patient.<br><br>Answering such questions without details about the actual data model<br>is impossible.<br><br>-W<br><br>On 02/01/2014, Ray Hooker &lt;<a href="mailto:ray.hooker@me.com" target="_blank">ray.hooker@me.com</a>&gt; wrote:<br>
<blockquote type="cite">I am trying to figure out how to work with an existing model. The data<br>is<br>in<br>MongoDB with embedded documents.  It is about patients would have<br>sub-documents.  For example.  An individual patient may have multiple<br>
allergies. Also a patient has multiple medications.  So it is as<br>follows:<br><br>- Patient.medications ---&gt; multiple Medication objects<br><br>So I see where you have a simple one to one.  Typically perhaps you<br>might<br>
have the medication record know that it is associated with the patient,<br>but<br>that is not how it is currently organized.  So the question is can I<br>write<br>rules when patients.medications returns a set/ collection of medications<br>
associated with the patient. I want to write a rule such as &quot;if a<br>patient<br>is<br>taking medication=xxx....&quot;<br><br>Thanks for your help.<br><br>Ray Hooker<br></blockquote>_______________________________________________<br>
rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote><br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br></div></div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div>