Date: Fri, 29 Mar 2024 03:58:00 -0400 (EDT) Message-ID: <1121745972.877.1711699080771@ip-10-208-26-37.ec2.internal> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_876_1518274778.1711699080757" ------=_Part_876_1518274778.1711699080757 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
/* * Copyright: (c) 2004-2009 Mayo Foundation for Medical Education and=20 * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the * triple-shield Mayo logo are trademarks and service marks of MFMER. * * Except as contained in the copyright notice above, or as used to identif= y=20 * MFMER as the author of this software, the trade names, trademarks, servi= ce * marks, or product names of the copyright holder shall not be used in * advertising, promotion or otherwise in connection with this software wit= hout * prior written authorization of the copyright holder. *=20 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at=20 *=20 * =09=09http://www.eclipse.org/legal/epl-v10.html *=20 */ package org.LexGrid.LexBIG.example; import org.LexGrid.LexBIG.DataModel.Collections.AssociatedConceptList; import org.LexGrid.LexBIG.DataModel.Collections.AssociationList; import org.LexGrid.LexBIG.DataModel.Core.AssociatedConcept; import org.LexGrid.LexBIG.DataModel.Core.Association; import org.LexGrid.LexBIG.DataModel.Core.CodingSchemeSummary; import org.LexGrid.LexBIG.DataModel.Core.CodingSchemeVersionOrTag; import org.LexGrid.LexBIG.Exceptions.LBException; import org.LexGrid.LexBIG.Extensions.Generic.LexBIGServiceConvenienceMethod= s; import org.LexGrid.LexBIG.Impl.LexBIGServiceImpl; import org.LexGrid.LexBIG.LexBIGService.LexBIGService; /** * Example showing how to determine and display the hierarchical relationsh= ips * for a specific code, ancestors or descendants, within a fixed distance. *=20 * This program accepts two parameters, indicating the code and distance. T= he * first parameter is the code (required). The second parameter is the dist= ance * (optional). If 1, immediate children are displayed. If 2, grandchildren = are * displayed, etc. If absent or < 0, all downstream branches are display= ed. *=20 * BACKGROUND: From a database perspective, LexBIG stores relationships * internally in a forward direction, source to target. Due to differences = in * source formats, however, a wide variety of associations may be used ('PA= R', * 'CHD', 'isa', 'hasSubtype', etc). In addition, the direction of navigati= on * may vary ('isa' expands in a reverse direction whereas 'hasSubtype' expa= nds * in a forward direction. *=20 * The intent of the getHierarchy* methods on the * LexBIGServiceConvenienceMethods interface is to simplify the process of * hierarchy discovery and navigation. These methods significantly reduce t= he * need to understand conventions for root nodes, associations, and directi= on of * navigation for a specific source format. *=20 */ public class ListHierarchyByCode { final static int DEFAULT_DISTANCE =3D -1; public ListHierarchyByCode() { super(); } /** * Entry point for processing. *=20 * @param args */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Example: ListHierarchyByCode \"C0000\" 2"); return; } ; try { String code =3D args[0]; int distance =3D args.length =3D=3D 1 ? DEFAULT_DISTANCE : Inte= ger.parseInt(args[1]); new ListHierarchyByCode().run(code, distance); } catch (NumberFormatException nfe) { System.out.println("Parameter 2 must indicate a number represen= ting maximum distance to display.\n" + "Example: ListHierarchyByCode \"C0000\" 2"); return; } catch (Exception e) { Util.displayAndLogError("REQUEST FAILED !!!", e); } } public void run(String code, int maxDistance) throws LBException { CodingSchemeSummary css =3D Util.promptForCodeSystem(); long ms =3D System.currentTimeMillis(); try { if (css !=3D null) { LexBIGService lbSvc =3D LexBIGServiceImpl.defaultInstance()= ; LexBIGServiceConvenienceMethods lbscm =3D (LexBIGServiceCon= venienceMethods) lbSvc .getGenericExtension("LexBIGServiceConvenienceMetho= ds"); String scheme =3D css.getCodingSchemeURI(); CodingSchemeVersionOrTag csvt =3D new CodingSchemeVersionOr= Tag(); csvt.setVersion(css.getRepresentsVersion()); String desc =3D null; try { desc =3D lbscm.createCodeNodeSet(new String[] { code },= scheme, csvt).resolveToList(null, null, null, 1).getResolvedConceptReference(0).getEntityDesc= ription().getContent(); } catch (Exception e) { desc =3D "<not found>"; } Util.displayMessage("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); Util.displayMessage("Focus code: " + code + ":" + desc); Util.displayMessage("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); // Iterate through all hierarchies and levels ... String[] hierarchyIDs =3D lbscm.getHierarchyIDs(scheme, csv= t); for (int i =3D 0; i < hierarchyIDs.length; i++) { String hierarchyID =3D hierarchyIDs[i]; String reportedDistance =3D maxDistance >=3D 0 ? Int= eger.toString(maxDistance) : "ALL"; Util.displayMessage("----------------------------------= --------------------------"); Util.displayMessage("Hierarchy ID: " + hierarchyID); Util.displayMessage("----------------------------------= --------------------------"); Util.displayMessage("Paths to ancestors (distance <= =3D " + reportedDistance + ") ..."); printLevelPrev(lbscm, scheme, csvt, hierarchyID, code, = maxDistance, 0); Util.displayMessage(""); Util.displayMessage("Paths to descendants (distance <= ;=3D " + reportedDistance + ") ..."); printLevelNext(lbscm, scheme, csvt, hierarchyID, code, = maxDistance, 0); Util.displayMessage(""); } } } finally { System.out.println("Run time (ms): " + (System.currentTimeMilli= s() - ms)); } } /** * Displays ancestors for a code within the specified hierarchy up to t= he * given distance or until paths to root nodes are exhausted, recursing= as * necessary. *=20 * @param lbcsm * @param scheme * @param csvt * @param hierarchyID * @param code * @param maxDistance * @param currentDistance * @throws LBException */ protected void printLevelPrev(LexBIGServiceConvenienceMethods lbscm, St= ring scheme, CodingSchemeVersionOrTag csvt, String hierarchyID, String code, int maxDistance, int currentDi= stance) throws LBException { if (maxDistance < 0 || currentDistance < maxDistance) { StringBuffer indent =3D new StringBuffer(); for (int i =3D 0; i <=3D currentDistance; i++) indent.append(" "); AssociationList associations =3D lbscm.getHierarchyLevelPrev(sc= heme, csvt, hierarchyID, code, false, null); for (int i =3D 0; i < associations.getAssociationCount(); i+= +) { Association assoc =3D associations.getAssociation(i); AssociatedConceptList concepts =3D assoc.getAssociatedConce= pts(); for (int j =3D 0; j < concepts.getAssociatedConceptCount= (); j++) { AssociatedConcept concept =3D concepts.getAssociatedCon= cept(j); String prevCode =3D concept.getConceptCode(); String prevDesc =3D concept.getEntityDescription() =3D= =3D null ? "NO DESCRIPTION" : concept .getEntityDescription().getContent(); Util.displayMessage(indent + assoc.getDirectionalName()= + "<-" + prevCode + ":" + prevDesc); printLevelPrev(lbscm, scheme, csvt, hierarchyID, prevCo= de, maxDistance, currentDistance + 1); } } } } /** * Displays descendants for a code within the specified hierarchy up to= the * given distance or until all paths to leaf nodes is exhausted, recurs= ing * as necessary. *=20 * @param lbscm * @param scheme * @param csvt * @param hierarchyID * @param code * @param maxDistance * @param currentDistance * @throws LBException */ protected void printLevelNext(LexBIGServiceConvenienceMethods lbscm, St= ring scheme, CodingSchemeVersionOrTag csvt, String hierarchyID, String code, int maxDistance, int currentDi= stance) throws LBException { if (maxDistance < 0 || currentDistance < maxDistance) { StringBuffer indent =3D new StringBuffer(); for (int i =3D 0; i <=3D currentDistance; i++) indent.append(" "); AssociationList associations =3D lbscm.getHierarchyLevelNext(sc= heme, csvt, hierarchyID, code, false, null); for (int i =3D 0; i < associations.getAssociationCount(); i+= +) { Association assoc =3D associations.getAssociation(i); AssociatedConceptList concepts =3D assoc.getAssociatedConce= pts(); for (int j =3D 0; j < concepts.getAssociatedConceptCount= (); j++) { AssociatedConcept concept =3D concepts.getAssociatedCon= cept(j); String nextCode =3D concept.getConceptCode(); String nextDesc =3D concept.getEntityDescription().getC= ontent(); Util.displayMessage(indent + assoc.getDirectionalName()= + "->" + nextCode + ":" + nextDesc); printLevelNext(lbscm, scheme, csvt, hierarchyID, nextCo= de, maxDistance, currentDistance + 1); } } } } }