[XQZone General] finding unique nodes in several documents

Farshad Farzan farshad at intelmeas.com
Tue Jun 14 18:51:33 PDT 2005


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.






More information about the General mailing list