<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Wolfgang, &nbsp;Thanks. &nbsp;That works nicely. &nbsp;I do have a followup question. &nbsp;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 class="Apple-tab-span" style="white-space:pre">        </span>dialect "<span style="text-decoration: underline">mvel</span>"</div><div style="margin: 0px; font-size: 11px; font-family: Monaco;"><span class="Apple-tab-span" style="white-space:pre">        </span>when</div><div style="margin: 0px; font-size: 11px; font-family: Monaco;"><span class="Apple-tab-span" style="white-space:pre">                </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 class="Apple-tab-span" style="white-space:pre">                </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 class="Apple-tab-span" style="white-space:pre">        </span>then</div><div style="margin: 0px; font-size: 11px; font-family: Monaco;"><span class="Apple-tab-span" style="white-space:pre">                </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 class="Apple-tab-span" style="white-space:pre">                </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. &nbsp;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…” &nbsp;instead of flagging for each hit?? &nbsp;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">wolfgang.laun@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">As you describe it, here's the way to refer to a particular medication:<br><br> &nbsp;&nbsp;Patient( $meds: medications )<br> &nbsp;&nbsp;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> &nbsp;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> &nbsp;&nbsp;Patient( $meds: medications )<br> &nbsp;&nbsp;Medication( drugCode == "55749-003-01" ) from $meds<br> &nbsp;&nbsp;Medication( drugCode == "55799-565-01" ) from $meds<br><br>with<br><br> &nbsp;&nbsp;$p: Patient()<br> &nbsp;&nbsp;Medication( drugCode == "55749-003-01", patient == $p )<br> &nbsp;&nbsp;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 &lt;<a href="mailto:ray.hooker@me.com">ray.hooker@me.com</a>&gt; wrote:<br><blockquote type="cite">Wolfgang, &nbsp;&nbsp;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. &nbsp;&nbsp;In this case, the<br>patient’s document contains subdocuments. &nbsp;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”. &nbsp;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. &nbsp;Also in the example below, is “Takes” a<br>function &nbsp;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">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> &nbsp;$p: Patient()<br> &nbsp;$p: Takes( patient == $p, $m: medication )<br> &nbsp;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">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. &nbsp;It is about patients would have<br>sub-documents. &nbsp;For example. &nbsp;An individual patient may have multiple<br>allergies. Also a patient has multiple medications. &nbsp;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. &nbsp;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. &nbsp;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">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote><br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br><br></blockquote><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote></div><br></div></div></body></html>