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