source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/AggregatorLib/src/gov/hhs/fha/nhinc/gateway/aggregator/model/DocRetrieveMessageKey.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 7.9 KB
Line 
1package gov.hhs.fha.nhinc.gateway.aggregator.model;
2
3import gov.hhs.fha.nhinc.gateway.aggregator.AggregatorException;
4
5
6/**
7 * This represents the fields that make up the message key
8 * that identifies a single document retrieve record in the
9 * aggregator message results table.
10 *
11 * @author Les Westberg
12 */
13public class DocRetrieveMessageKey
14{
15
16 private static final String DOC_RETRIEVE_TAG = "DocRetrieve";
17 private static final String DOC_RETRIEVE_TAG_START = "<" + DOC_RETRIEVE_TAG + ">";
18 private static final String DOC_RETRIEVE_TAG_END = "</" + DOC_RETRIEVE_TAG + ">";
19 private static final String HOME_COMMUNITY_ID_TAG = "HomeCommunityId";
20 private static final String HOME_COMMUNITY_ID_TAG_START = "<" + HOME_COMMUNITY_ID_TAG + ">";
21 private static final String HOME_COMMUNITY_ID_TAG_END = "</" + HOME_COMMUNITY_ID_TAG + ">";
22 private static final String REPOSITORY_ID_TAG = "RepositoryId";
23 private static final String REPOSITORY_ID_TAG_START = "<" + REPOSITORY_ID_TAG + ">";
24 private static final String REPOSITORY_ID_TAG_END = "</" + REPOSITORY_ID_TAG + ">";
25 private static final String DOCUMENT_ID_TAG = "PatientId";
26 private static final String DOCUMENT_ID_TAG_START = "<" + DOCUMENT_ID_TAG + ">";
27 private static final String DOCUMENT_ID_TAG_END = "</" + DOCUMENT_ID_TAG + ">";
28
29 // Private member variables
30 //-------------------------
31 private String homeCommunityId;
32 private String repositoryId;
33 private String documentId;
34
35 /**
36 * Default constructor.
37 */
38 public DocRetrieveMessageKey()
39 {
40 clear();
41 }
42
43 /**
44 * This method takes the information in a formatted message key and
45 * creates an object with that information. This key should be one
46 * that was created by this class. (or at least exactly formatted
47 * that way).
48 *
49 * @param sMessageKey The message key as formatted by calling the
50 * creatingXMLMessageKey.
51 * @throws AggregatorException This is thrown if the format of the XML message
52 * is not correct.
53 */
54 public DocRetrieveMessageKey(String sMessageKey)
55 throws AggregatorException
56 {
57 // Since this is a simple XML that is in a controlled format -
58 // It is easiest to just pull out the fields by hand-parsing...
59 //-------------------------------------------------------------
60 parseXMLMessageKey(sMessageKey);
61 }
62
63 /**
64 * Clear the ocntents of this object
65 */
66 public void clear()
67 {
68 homeCommunityId = "";
69 repositoryId = "";
70 documentId = "";
71 }
72
73 /**
74 * Returns the document ID of the document.
75 *
76 * @return The document ID of the document.
77 */
78 public String getDocumentId()
79 {
80 return documentId;
81 }
82
83 /**
84 * Sets the document ID of the document.
85 *
86 * @param documentId The document ID of the document.
87 */
88 public void setDocumentId(String documentId)
89 {
90 this.documentId = documentId;
91 }
92
93 /**
94 * Returns the Home community Id where the document lis lcoated.
95 *
96 * @return the hoome community Id of the location of the document.
97 */
98 public String getHomeCommunityId()
99 {
100 return homeCommunityId;
101 }
102
103 /**
104 * Sets the Home community Id where the document lis lcoated.
105 *
106 * @param homeCommunityId the hoome community Id of the location of the document.
107 */
108 public void setHomeCommunityId(String homeCommunityId)
109 {
110 this.homeCommunityId = homeCommunityId;
111 }
112
113 /**
114 * Returns the repository ID for the repository that contains the document.
115 *
116 * @return The repository ID for the repository that contains the document.
117 */
118 public String getRepositoryId()
119 {
120 return repositoryId;
121 }
122
123 /**
124 * Sets the repository ID for the repository that contains the document.
125 *
126 * @param repositoryId The repository ID for the repository that contains the document.
127 */
128 public void setRepositoryId(String repositoryId)
129 {
130 this.repositoryId = repositoryId;
131 }
132
133 /**
134 * This method creates the XML Message Key that will be stored in the
135 * MessageKey field of the AGGREGATOR.AGG_MESSAGE_RESULTS table.
136 *
137 * @return The XML key that is created based on the fields in this object.
138 */
139 public String createXMLMessageKey()
140 {
141 String sHomeCommunityId = "";
142 String sRepositoryId = "";
143 String sDocumentId = "";
144
145 if (homeCommunityId != null)
146 {
147 sHomeCommunityId = homeCommunityId.trim();
148 }
149
150 if (repositoryId != null)
151 {
152 sRepositoryId = repositoryId.trim();
153 }
154
155 if (documentId != null)
156 {
157 sDocumentId = documentId.trim();
158 }
159
160 String sKey = DOC_RETRIEVE_TAG_START +
161 HOME_COMMUNITY_ID_TAG_START + sHomeCommunityId + HOME_COMMUNITY_ID_TAG_END +
162 REPOSITORY_ID_TAG_START + sRepositoryId + REPOSITORY_ID_TAG_END +
163 DOCUMENT_ID_TAG_START + sDocumentId + DOCUMENT_ID_TAG_END +
164 DOC_RETRIEVE_TAG_END;
165
166 return sKey;
167 }
168
169 /**
170 * Since this is a simple XML that is in a controlled format -
171 * It is easiest to just pull out the fields by hand-parsing...
172 *
173 * @param sMessageKey The XML string key containing the data.
174 * @throws AggregatorException This is thrown if the format of the XML message
175 * is not correct.
176 */
177 public void parseXMLMessageKey(String sMessageKey)
178 throws AggregatorException
179 {
180 int iStartIdx = 0;
181 int iEndIdx = 0;
182
183 // Get the Home community
184 //------------------------
185 iStartIdx = sMessageKey.indexOf(HOME_COMMUNITY_ID_TAG_START);
186 if (iStartIdx >= 0)
187 {
188 iStartIdx += HOME_COMMUNITY_ID_TAG_START.length();
189 }
190 else
191 {
192 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
193 }
194
195 iEndIdx = sMessageKey.indexOf(HOME_COMMUNITY_ID_TAG_END);
196 if (iEndIdx > 0)
197 {
198 homeCommunityId = sMessageKey.substring(iStartIdx, iEndIdx);
199 }
200 else
201 {
202 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
203 }
204
205 // Get the Repository ID
206 //----------------------
207 iStartIdx = sMessageKey.indexOf(REPOSITORY_ID_TAG_START);
208 if (iStartIdx >= 0)
209 {
210 iStartIdx += REPOSITORY_ID_TAG_START.length();
211 }
212 else
213 {
214 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
215 }
216
217 iEndIdx = sMessageKey.indexOf(REPOSITORY_ID_TAG_END);
218 if (iEndIdx > 0)
219 {
220 repositoryId = sMessageKey.substring(iStartIdx, iEndIdx);
221 }
222 else
223 {
224 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
225 }
226
227 // Get the Document Id
228 //-------------------
229 iStartIdx = sMessageKey.indexOf(DOCUMENT_ID_TAG_START);
230 if (iStartIdx >= 0)
231 {
232 iStartIdx += DOCUMENT_ID_TAG_START.length();
233 }
234 else
235 {
236 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
237 }
238
239 iEndIdx = sMessageKey.indexOf(DOCUMENT_ID_TAG_END);
240 if (iEndIdx > 0)
241 {
242 documentId = sMessageKey.substring(iStartIdx, iEndIdx);
243 }
244 else
245 {
246 throw new AggregatorException("Format of DocRetrieveMessageKey was invalid. MessageKey = '" + sMessageKey + "'");
247 }
248 }
249
250}
Note: See TracBrowser for help on using the repository browser.