<p dir="ltr">Try prefixing MedicationRecord with "exists". 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, "Ray Hooker" <<a href="mailto:ray.hooker@me.com">ray.hooker@me.com</a>> 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 "Find patient taking <span style="text-decoration:underline">Atorvastin</span> (<span style="text-decoration:underline">Lipitor</span>)"</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">        </span>dialect "<span style="text-decoration:underline">mvel</span>"</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("RxNorm").contains("617314")) 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("Found a patient taking <span style="text-decoration:underline">Lipitor</span>: "+$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("test",$p.medical_record_number,"Found Patient Taking <span style="text-decoration:underline">Lipitor</span>","now"));</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 <<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>> wrote:</div>
<br><blockquote type="cite">As you describe it, here's the way to refer to a particular medication:<br><br> Patient( $meds: medications )<br> Medication( drugCode == "55749-003-01" ) 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] "55749-003" ) 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 == "55749-003-01" ) from $meds<br> Medication( drugCode == "55799-565-01" ) from $meds<br><br>with<br>
<br> $p: Patient()<br> Medication( drugCode == "55749-003-01", patient == $p )<br> Medication( drugCode == "55799-565-01", patient == $p )<br><br>Much depends on the number of facts you'll need to process.<br>
<br>To answer your question, "Takes" was a class name I invented to refer<br>to the relation as an object, and "this" is Java's "this", referring<br>to the matching object.<br><br>-W<br><br>
<br>On 02/01/2014, Ray Hooker <<a href="mailto:ray.hooker@me.com" target="_blank">ray.hooker@me.com</a>> 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 <<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>> 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 <<a href="mailto:ray.hooker@me.com" target="_blank">ray.hooker@me.com</a>> 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 ---> 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 "if a<br>patient<br>is<br>taking medication=xxx...."<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>