[XQZone General] finding unique nodes in several documents

atownsen at wiley.co.uk atownsen at wiley.co.uk
Wed Jun 15 05:55:46 PDT 2005




Hi Farshad,

There are a number of ways to try this which are hopefully a little simpler
than your solution :-)

Firstly - I think part of your current problem comes from a
misunderstanding of intersect as used below:

if (exists( $b[i:family = $last][i:given = $first]/.. intersect $x ) )

It is _not_ testing to see whether there is any patientPatient node in $x,
it is testing to see whether THAT PARTICULAR node is in $x, based on node
identity so thats partly why you get every node.


What I think you are trying to do is something more like this:

(: For each different family name :)
for $last in distinct-values(xdmp:directory('/CDA/','infinity')
                //i:patient//i:patientPatient/i:name/i:family)
(: For each different first name with the current family name :)
for $first in distinct-values(xdmp:directory('/CDA/','infinity')
                //i:patient//i:patientPatient/i:name[i:family
=$last]/i:given )
return
        (: Find matching patient nodes and return the _first_ only :)
        (xdmp:directory('/CDA/','infinity')
                //i:patient//i:patientPatient[i:name/i:family =$last and
i:name/i:given = $first])[1]


Note in the return clause this selects just the first node if there are
several records for the same patient.  Also note the way the predicate
applies to i:patientPatient nodes rather than i:name nodes - this means
that you can avoid using the parent axis (i.e. "/..") which is often rather
slower to use than the child axis.

Please note I did not actually load in your data so typos above are always
possible :-)

You don't need to build the list with insert-before() - the above will
return you one patientPatient node for each patient.

Also note that this solution as above is suseptible to case changes of the
patients names.

Hopes this helps!

Andy
|+------------------------------+-----------------------------------------|
||   "Farshad Farzan"           |                                         |
||   <farshad at intelmeas.com>    |                                         |
||   Sent by:                   |   To:        <general at xqzone.marklogic.c|
||   general-bounces at xqzone.mark|   om>                                   |
||   logic.com                  |           cc:                           |
||                              |           Subject:        [XQZone       |
||   15/06/2005 02:51           |   General] finding unique nodes in      |
||   Please respond to farshad; |   several documents                     |
||   Please respond to General  |                                         |
||   XQZone Discussion          |                                         |
|+------------------------------+-----------------------------------------|









I am new to xquery , struggling to find a nice way to return a sequence of
unique nodes that appear in several documents in the data base.

Here is background:
I have several documents that refer to several patients.
I need to find out all the unique patients. , but not just their names but
all their specifics that appear in their patient node.


Here is the code :
----------------------------------------------
declare namespace i='urn:hl7-org:v3'

let $x := ()
return

let $last := distinct-values(
xdmp:directory('/CDA/','infinity')//i:patient//i:patientPatient/i:name/i:fam
ily)
let $first :=
distinct-values(xdmp:directory('/CDA/','infinity')//i:patient//i:patientPati
ent/i:name[i:family =  $last]/i:given )


for $b in
xdmp:directory('/CDA/','infinity')//i:patient//i:patientPatient/i:name


let $x :=  if (exists( $b[i:family = $last][i:given = $first]/.. intersect
$x ) ) then <none/> else
insert-before($x, 0, $b[i:family = $last][i:given = $first]/..)

return <result> {                 $x
} </result>
------------------------------------------------
So, what I have done, is to find the unique first and unique last
sequences.

Then , go through the documents and whenever the document has the first and
last same as the list , store the node in the sequence $x.

But it does not work, I still get every document.


Sample document ( copy 4 times but change the family and given only 2 time
to have 2 document for each patient and save it in  directory CDA)

----------------------------------------------
<patient>
                                                  <id extension="12345"
root="2.16.840.1.113883.3.933"/>
                                                  <telecom value='tel:
(781) 555-1212' use='HP'/>
                                                  <addr>

<streetAddressLine>17 Daws
Rd.</streetAddressLine>

<city>Blue Bell</city>

<state>MA</state>

<postalCode>02368</postalCode>

<country>USA</country>
                                                  </addr>
                                                  <patientPatient>
                                                                   <name>

<prefix>Mrs.</prefix>
<given>Patricia</given>
<family>Smith</family>
                                                                   </name>

<administrativeGenderCode code="F"
codeSystem="2.16.840.1.113883.5.1"/>

<birthTime value="19600127"/>
                                                  </patientPatient>
                                                  <providerOrganization>
                                                                   <id
extension="M345"
root="2.16.840.1.113883.3.933"/>

<name>Good Health Clinic</name>
                                                                   <telecom
value='tel: (999) 555-1212'
use='P'/>
                                                                   <addr>
<streetAddressLine>21 North
Ave</streetAddressLine>
<city>Burlington</city>
<state>MA</state>
<postalCode>01803</postalCode>
<country>USA</country>
                                                                   </addr>
                                                  </providerOrganization>
                                 </patient>


-----------------------------------



What am I doing wrong ?
Any idea , or a better way ??
Thanks.



_______________________________________________
General mailing list
General at xqzone.marklogic.com
http://xqzone.com/mailman/listinfo/general


######################################################################
The information contained in this e-mail and any subsequent 
correspondence is private and confidential and intended solely 
for the named recipient(s).  If you are not a named recipient, 
you must not copy, distribute, or disseminate the information, 
open any attachment, or take any action in reliance on it.  If you 
have received the e-mail in error, please notify the sender and delete
the e-mail.  

Any views or opinions expressed in this e-mail are those of the 
individual sender, unless otherwise stated.  Although this e-mail has 
been scanned for viruses you should rely on your own virus check, as 
the sender accepts no liability for any damage arising out of any bug 
or virus infection.
######################################################################



More information about the General mailing list