Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
SELECT 
  p/uid/value, 
  pid/items[at0010]/value AS full_name, 
  d/items[at0001]/value AS bday, 
  d/items[at0031]/value AS gender
FROM 
  (PERSON p [openEHR-DEMOGRAPHIC-PERSON.person.v2] 
      CONTAINS PARTY_IDENTITY pid [openEHR-DEMOGRAPHIC-PARTY_IDENTITY.person_name.v2]
      AND CONTAINS ITEM_TREE d [openEHR-DEMOGRAPHIC-ITEM_TREE.person_details.v2])
  AND 
  (CONTAINS GROUP g [openEHR-DEMOGRAPHIC-GROUP.group.v2]
      CONTAINS PARTY_IDENTITY gid [openEHR-DEMOGRAPHIC-PARTY_IDENTITY.group_name.v2])
  AND
  (CONTAINS ROLE r [openEHR-DEMOGRAPHIC-ROLE.role.v2])
WHERE 
  gid/items[at0010]/value = "Care Group X"
  AND IS_RELATED(p, g, 'patientOf')
  AND p/roles[1]/id = r/uid AND r/name/value = 'Patient'

Relations are store as PARTY_RELATIONSHIP instances, referred by ACTORS above, but they are not used explicitly in the query. The IS_RELATED() function will have to solve the query constrain by using those referred PARTY_RELATIONSHIP. Another variant would be to also add PARTY_RELATIONHIP in the FROM section:

Code Block
languagesql
FROM 
  PERSON p [openEHR-DEMOGRAPHIC-PERSON.person.v2] 
  AND GROUP g [openEHR-DEMOGRAPHIC-GROUP.group.v2]
  AND PARTY_RELATIONSHIP pr
WHERE 
  p/party_relationship/id = pr/uid
  AND pr/source/id = p.uid
  AND pr/target/id = g.uid
  AND pr/name = 'patientOf'