RIM Service Examples
The code samples below help you do the following:
- Use CD Qualifiers (see Example 7-34)
- Query PQ Values (see Example 7-35)
- Query CE/CD Values (see Example 7-36)
- Query BL Values (see Example 7-37)
- Query INT values (see Example 7-38)
- Query TS values (see Example 7-39)
Use CD Qualifiers
Example 7-34 Use CD Qualifiers
// Creates an Observation Event showing the use of qualifiers // on coded data to provide additional information about the code // Uses the SNOMED-CT coding scheme, which must be loaded to pass validation // Use Act Code of DISDX/ActCode. // DISDX represents a "Discharge Diagnosis" // ActCode OID is 2.16.840.1.113883.5.4 CD actCode = dataTypeFactory.newCD("DISDX", "2.16.840.1.113883.5.4"); Observation obs = actFactory.newObservation(ActMood.EVN, actCode, dataTypeFactory.nullSET_II(NullFlavor.NA)); obs.setText(dataTypeFactory.newST("Acute sudden-onset severe appendicitis, first episode.")); // Construct a code for observation value with qualifiers // Code is Appendicitis/SNOMED-CT // Qualifiers represent the following name - value information - // Severity (246112005) - Severe (24484000) // Clinical Course (263502005) - Acute Onset (373933003) // Episodicity (246456000) - First Episode (255217005) // All qualifiers use the SNOMED-CT coding scheme // It is expected that qualifiers will normally be taken from the same // coding scheme as the code. However, HDR does not validate this. CR[] qualifiers = { dataTypeFactory.newCR( dataTypeFactory.newCV("246112005", "2.16.840.1.113883.6.96"), dataTypeFactory.newCD("24484000", "2.16.840.1.113883.6.96"), dataTypeFactory.newBN(false)), dataTypeFactory.newCR( dataTypeFactory.newCV("263502005", "2.16.840.1.113883.6.96"), dataTypeFactory.newCD("373933003", "2.16.840.1.113883.6.96"), dataTypeFactory.newBN(false)), dataTypeFactory.newCR( dataTypeFactory.newCV("246456000", "2.16.840.1.113883.6.96"), dataTypeFactory.newCD("255217005", "2.16.840.1.113883.6.96"), dataTypeFactory.newBN(false)) }; // use Appendicitis (74400008) from SNOMED-CT coding scheme CD code = dataTypeFactory.newCD( dataTypeFactory.newST("74400008"), dataTypeFactory.newUID("2.16.840.1.113883.6.96"), dataTypeFactory.nullST(NullFlavor.NA), dataTypeFactory.nullST(NullFlavor.NA), dataTypeFactory.nullED(NullFlavor.NA), dataTypeFactory.newLIST<CR>(qualifiers)); obs.setValue(code); // Add participations to a Medical Practitioner and to a Patient // Participation to the Patient is typically SBJ // Participation to the Provider is typically AUT // Omitting the Person (player) and Organization (scoper) // for the purposes of the example Patient pat = roleFactory.newPatient(dataTypeFactory.nullCE(NullFlavor.NA), null, null, dataTypeFactory.nullSET_II(NullFlavor.NA)); LicensedEntity prov = roleFactory.newHealthcareProvider( dataTypeFactory.nullCE(NullFlavor.NA), null, null, dataTypeFactory.nullSET_II(NullFlavor.NA)); obs.addParticipation(ParticipationType.SBJ,pat); obs.addParticipation(ParticipationType.AUT,prov); // Attach the Observation to a Control Act and submit ControlAct cact = actFactory.newControlActEvent( dataTypeFactory.nullCD(NullFlavor.NA), dataTypeFactory.nullSET_II(NullFlavor.NA)); cact.addOBActRelationship(ActRelationshipType.SUBJ,obs); rimService.submit(cact);
Query Based on Observation Value Attribute
The data type specification defines a hierarchy of various exceptional values or null values. You can use the isNull method to determine whether a data type is an exceptional value. The nullFlavor method returns a CS code that specifies the type of exceptional value.
Example 7-35 Query PQ Values
Query for all patients with a "Post-Prandial Blood Glucose Measurement" greater than 180 mg/dL (OBS.EVN.302788006//SNOMED-CT with Observation.value (PQ) = greater than 180 mg/dL).
// Show how to perform a query on Observation Value. // It is normal to specifiy the Class Code, Mood code, code and value // attributes for such queries // Build a Role Fetch to bring back the Patient RoleFetch rf = queryComponentFactory.newRoleFetch(); // Decide which attributes to retrieve on the Patient Role rf.retrieveId(true); // Build a Participation Fetch,with a ParticipationCriteria // specifying that the participation type is SBJ ParticipationAttributeCriteria pc = queryComponentFactory.newParticipationAttributeCriteria(); pc.setTypeCode(ParticipationCriteria.EQUALS,ParticipationType.SBJ); ParticipationFetch pf = queryComponentFactory.newParticipationFetch(pc,queryComponentFactory.VERSION_DEPENDENT); pf.addRoleFetch(rf); // Put together act critera, specifying class code, mood code, code // and value attributes ActAttributeCriteria ac = queryComponentFactory.newActAttributeCriteria(); ac.setClassCode(ActCriteria.EQUALS,ActClass.OBS); ac.setMoodCode(ActCriteria.EQUALS,ActMood.EVN); // Build code and value criteria objects CodedTypeAttributeCriteria ctac = queryComponentFactory.newCodedTypeAttributeCriteria(); ctac.setCode(dataTypeFactory.newST("302788006")); ctac.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); ac.setCode(ctac); PQAttributeCriteria pqac = queryComponentFactory.newPQAttributeCriteria(); pqac.setValue(PQAttributeCriteria.GREATER_THAN,dataTypeFactory.newREAL("180")); pqac.setUnit(PQAttributeCriteria.EQUALS,dataTypeFactory.newCS("mg/dL")); ac.setValue(pqac); ActFetch af = queryComponentFactory.newActFetch(ac, queryComponentFactory.VERSION_DEPENDENT); af.addParticipationFetch(pf); af.retrieveAll(); Iterator iter = rimService.queryActs(serviceLocator,af); while (iter.hasNext()) { Observation obs = (Observation)iter.next(); System.out.println("== Observation =="); System.out.println("== id ==>" + obs.getId()); System.out.println("== code ==>" + obs.getCode()); System.out.println("== value ==>" + ((PQ)obs.getValue()).literal()); Iterator partIter = obs.getParticipations(); while (partIter.hasNext()) { Role role = ((Participation)partIter.next()).getRole(); System.out.println("== Role id ===> " + role.getId()); } }
Example 7-36 Query CE/CD Values
Query for all patients with a diagnosis of "Asthma" or "Pneumonia" (OBS.EVN.DISDX//ActCode with Observation.value (CE) = 195967001// SNOMED-CT or 233604007// SNOMED-CT).
// use the same fetch and criteria objects as before. // change the code and value attributes for the different criteria ctac = queryComponentFactory.newCodedTypeAttributeCriteria(); ctac.setCode(dataTypeFactory.newST("DISDX")); ctac.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.5.4")); ac.setCode(ctac); CodedTypeAttributeCriteria asthmaCriteria = queryComponentFactory.newCodedTypeAttributeCriteria(); asthmaCriteria.setCode(dataTypeFactory.newST("195967001")); asthmaCriteria.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); CodedTypeAttributeCriteria pneumoniaCriteria = queryComponentFactory.newCodedTypeAttributeCriteria(); pneumoniaCriteria.setCode(dataTypeFactory.newST("233604007")); pneumoniaCriteria.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); ac.setValue((CodedTypeAttributeCriteria)queryComponentFactory.or(asthmaCriteria, pneumoniaCriteria)); af = queryComponentFactory.newActFetch(ac, queryComponentFactory.VERSION_DEPENDENT); af.addParticipationFetch(pf); af.retrieveAll(); iter = rimService.queryActs(serviceLocator,af); while (iter.hasNext()) { Observation obs = (Observation)iter.next(); System.out.println("== Observation =="); System.out.println("== id ==>" + obs.getId()); System.out.println("== code ==>" + obs.getCode()); System.out.println("== value ==>" + obs.getValue()); Iterator partIter = obs.getParticipations(); while (partIter.hasNext()) { Role role = ((Participation)partIter.next()).getRole(); System.out.println("== Role id ===> " + role.getId()); } }
Example 7-37 Query BL Values
Query for all patients with a positive "Mantoux Test" (OBS.EVN.268376005//SNOMED-CT with Observation.value (BL) = true).
ctac = queryComponentFactory.newCodedTypeAttributeCriteria(); ctac.setCode(dataTypeFactory.newST("268376005")); ctac.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); ac.setCode(ctac); ac.setValue(ActAttributeCriteria.EQUALS,dataTypeFactory.newBL(true)); af = queryComponentFactory.newActFetch(ac, queryComponentFactory.VERSION_DEPENDENT); af.addParticipationFetch(pf); af.retrieveAll(); iter = rimService.queryActs(serviceLocator,af); while (iter.hasNext()) { Observation obs = (Observation)iter.next(); System.out.println("== Observation =="); System.out.println("== id ==>" + obs.getId()); System.out.println("== code ==>" + obs.getCode()); System.out.println("== value ==>" + ((BL)obs.getValue()).literal()); Iterator partIter = obs.getParticipations(); while (partIter.hasNext()) { Role role = ((Participation)partIter.next()).getRole(); System.out.println("== Role id ===> " + role.getId()); } }
Example 7-38 Query INT values
Query for all patients with a zero "Missing Tooth Count" (OBS.EVN.251317003//SNOMED-CT with Observation.value (INT) = 0).
ctac = queryComponentFactory.newCodedTypeAttributeCriteria(); ctac.setCode(dataTypeFactory.newST("251317003")); ctac.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); ac.setCode(ctac); ac.setValue(ActAttributeCriteria.EQUALS,dataTypeFactory.newINT(0)); af = queryComponentFactory.newActFetch(ac, queryComponentFactory.VERSION_DEPENDENT); af.addParticipationFetch(pf); af.retrieveAll(); iter = rimService.queryActs(serviceLocator,af); while (iter.hasNext()) { Observation obs = (Observation)iter.next(); System.out.println("== Observation =="); System.out.println("== id ==>" + obs.getId()); System.out.println("== code ==>" + obs.getCode()); System.out.println("== value ==>" + ((INT)obs.getValue()).literal()); Iterator partIter = obs.getParticipations(); while (partIter.hasNext()) { Role role = ((Participation)partIter.next()).getRole(); System.out.println("== Role id ===> " + role.getId()); } }
Example 7-39 Query TS values
Query for all patients with a "Time of Onset" greater than or equal to 00:02:01 (OBS.EVN.263501003//SNOMED-CT with Observation.value (TS) = 00:02:01).
ctac = queryComponentFactory.newCodedTypeAttributeCriteria(); ctac.setCode(dataTypeFactory.newST("263501003")); ctac.setCodeSystem(dataTypeFactory.newUID("2.16.840.1.113883.6.96")); ac.setCode(ctac); try { ac.setValue(ActAttributeCriteria.EQUALS,dataTypeFactory.newTS(new SimpleDateFormat("yyMMddHHmmss").parse("080101000201"))); } catch (Exception e) { e.printStackTrace(); } af = queryComponentFactory.newActFetch(ac, queryComponentFactory.VERSION_DEPENDENT); af.addParticipationFetch(pf); af.retrieveAll(); iter = rimService.queryActs(serviceLocator,af); while (iter.hasNext()) { Observation obs = (Observation)iter.next(); System.out.println("== Observation =="); System.out.println("== id ==>" + obs.getId()); System.out.println("== code ==>" + obs.getCode()); System.out.println("== value ==>" + ((TS)obs.getValue()).literal()); Iterator partIter = obs.getParticipations(); while (partIter.hasNext()) { Role role = ((Participation)partIter.next()).getRole(); System.out.println("== Role id ===> " + role.getId()); } }