001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2026 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.test.hl7v2;
011
012import ca.cdr.api.hl7v2.CdrModelClassFactory;
013import ca.cdr.api.model.enm.CodeSystemEnum;
014import ca.cdr.api.util.PublicApiConstants;
015import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.EncounterData;
016import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.HospitalData;
017import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.ObservationData;
018import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.PatientData;
019import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.PractitionerData;
020import ca.uhn.fhir.context.FhirContext;
021import ca.uhn.hl7v2.DefaultHapiContext;
022import ca.uhn.hl7v2.HL7Exception;
023import ca.uhn.hl7v2.model.AbstractMessage;
024import ca.uhn.hl7v2.model.AbstractSegment;
025import ca.uhn.hl7v2.model.AbstractType;
026import ca.uhn.hl7v2.model.DataTypeException;
027import ca.uhn.hl7v2.model.Message;
028import ca.uhn.hl7v2.model.Varies;
029import ca.uhn.hl7v2.model.v25.datatype.CE;
030import ca.uhn.hl7v2.model.v25.datatype.CX;
031import ca.uhn.hl7v2.model.v25.datatype.DT;
032import ca.uhn.hl7v2.model.v25.datatype.EI;
033import ca.uhn.hl7v2.model.v25.datatype.NM;
034import ca.uhn.hl7v2.model.v25.datatype.PL;
035import ca.uhn.hl7v2.model.v25.datatype.ST;
036import ca.uhn.hl7v2.model.v25.datatype.TQ;
037import ca.uhn.hl7v2.model.v25.datatype.XAD;
038import ca.uhn.hl7v2.model.v25.datatype.XCN;
039import ca.uhn.hl7v2.model.v25.datatype.XON;
040import ca.uhn.hl7v2.model.v25.datatype.XPN;
041import ca.uhn.hl7v2.model.v25.datatype.XTN;
042import ca.uhn.hl7v2.model.v25.group.ORU_R01_PATIENT_RESULT;
043import ca.uhn.hl7v2.model.v25.group.RAS_O17_ADMINISTRATION;
044import ca.uhn.hl7v2.model.v25.group.RAS_O17_ORDER;
045import ca.uhn.hl7v2.model.v25.group.RDE_O11_ORDER;
046import ca.uhn.hl7v2.model.v25.message.ADT_A01;
047import ca.uhn.hl7v2.model.v25.message.ADT_A03;
048import ca.uhn.hl7v2.model.v25.message.ADT_A06;
049import ca.uhn.hl7v2.model.v25.message.ADT_A09;
050import ca.uhn.hl7v2.model.v25.message.ADT_A21;
051import ca.uhn.hl7v2.model.v25.message.ADT_A39;
052import ca.uhn.hl7v2.model.v25.message.ADT_A45;
053import ca.uhn.hl7v2.model.v25.message.ADT_A54;
054import ca.uhn.hl7v2.model.v25.message.ADT_A60;
055import ca.uhn.hl7v2.model.v25.message.DFT_P03;
056import ca.uhn.hl7v2.model.v25.message.ORM_O01;
057import ca.uhn.hl7v2.model.v25.message.ORU_R01;
058import ca.uhn.hl7v2.model.v25.message.QBP_Q21;
059import ca.uhn.hl7v2.model.v25.message.RAS_O17;
060import ca.uhn.hl7v2.model.v25.message.RDE_O11;
061import ca.uhn.hl7v2.model.v25.message.SIU_S12;
062import ca.uhn.hl7v2.model.v25.message.VXU_V04;
063import ca.uhn.hl7v2.model.v25.segment.AIL;
064import ca.uhn.hl7v2.model.v25.segment.AIP;
065import ca.uhn.hl7v2.model.v25.segment.AL1;
066import ca.uhn.hl7v2.model.v25.segment.DG1;
067import ca.uhn.hl7v2.model.v25.segment.FT1;
068import ca.uhn.hl7v2.model.v25.segment.GT1;
069import ca.uhn.hl7v2.model.v25.segment.IAM;
070import ca.uhn.hl7v2.model.v25.segment.IN1;
071import ca.uhn.hl7v2.model.v25.segment.IN2;
072import ca.uhn.hl7v2.model.v25.segment.MRG;
073import ca.uhn.hl7v2.model.v25.segment.MSH;
074import ca.uhn.hl7v2.model.v25.segment.NK1;
075import ca.uhn.hl7v2.model.v25.segment.OBR;
076import ca.uhn.hl7v2.model.v25.segment.OBX;
077import ca.uhn.hl7v2.model.v25.segment.ORC;
078import ca.uhn.hl7v2.model.v25.segment.PD1;
079import ca.uhn.hl7v2.model.v25.segment.PID;
080import ca.uhn.hl7v2.model.v25.segment.PR1;
081import ca.uhn.hl7v2.model.v25.segment.PV1;
082import ca.uhn.hl7v2.model.v25.segment.PV2;
083import ca.uhn.hl7v2.model.v25.segment.QPD;
084import ca.uhn.hl7v2.model.v25.segment.ROL;
085import ca.uhn.hl7v2.model.v25.segment.RXA;
086import ca.uhn.hl7v2.model.v25.segment.RXC;
087import ca.uhn.hl7v2.model.v25.segment.RXE;
088import ca.uhn.hl7v2.model.v25.segment.RXR;
089import ca.uhn.hl7v2.model.v25.segment.SCH;
090import ca.uhn.hl7v2.validation.impl.NoValidation;
091
092
093/**
094 * Creates HL7 V2 test data
095 */
096public class Hl7V2TestDataHelper {
097
098        public static final String FACILITY_SYSTEM = "http://acme.org/facility";
099        private static DefaultHapiContext ourV2Ctx;
100        private static FhirContext ourContext;
101
102        public Hl7V2TestDataHelper(FhirContext theFhirContext, DefaultHapiContext v2Ctx) {
103                ourContext = theFhirContext;
104                ourV2Ctx = v2Ctx;
105        }
106
107        public static Hl7V2TestDataHelper buildDefault(FhirContext theFhirContext) {
108                ourV2Ctx = new DefaultHapiContext();
109                ourV2Ctx.setValidationContext(new NoValidation());
110                ourV2Ctx.setModelClassFactory(new CdrModelClassFactory());
111                return new Hl7V2TestDataHelper(theFhirContext, ourV2Ctx);
112        }
113
114        public void addExtraComponent(AbstractType theTarget, int theComponentIndex, String theValue)
115                throws DataTypeException {
116                ST system = new ST(theTarget.getMessage());
117                system.setValue(theValue);
118                theTarget.getExtraComponents().getComponent(theComponentIndex).setData(system);
119        }
120
121        public ADT_A01 createAdtA01() throws HL7Exception {
122                return createAdtA01(true);
123        }
124
125        public ADT_A01 createAdtA01(boolean theValid) throws HL7Exception {
126                ADT_A01 a01 = new ADT_A01();
127
128                // Patient, family doctor, next of kin, and employer
129                populateMsh(a01.getMSH(), "ADT^A01^ADT_A01");
130                populatePid(a01.getPID(), theValid);
131                populateNk1NextOfKin(a01.insertNK1(0));
132                populateNk1Employer(a01.insertNK1(1));
133                populateRolA(a01.insertROL(0));
134
135                // Visit, attending, admitting, diagnosis, etc
136                populatePv1(a01.getPV1());
137                populatePv2(a01.getPV2());
138                populateRolB(a01.insertROL2(0));
139                populateRolC(a01.insertROL2(1));
140                populateDg1(a01.getDG1());
141                populatePr1First(a01.insertPROCEDURE(0).getPR1());
142                populateGt1(a01.getGT1());
143                populateIn1(a01.insertINSURANCE(0).getIN1());
144                populateIn2(a01.getINSURANCE(0).getIN2());
145
146                // Assessments
147                populateObxAssessmentWeight(a01, a01.insertOBX(0));
148                populateObxAssessmentHeight(a01, a01.insertOBX(0));
149
150                return a01;
151        }
152
153        public ADT_A03 createAdtA03() throws HL7Exception {
154                ADT_A03 a03 = new ADT_A03();
155
156                // Patient and family doctor
157                populateMsh(a03.getMSH(), "ADT^A03^ADT_A03");
158                populatePid(a03.getPID());
159                populateRolA(a03.insertROL(0));
160
161                // Visit, attending, admitting, diagnosis, etc
162                populatePv1(a03.getPV1());
163                populateRolB(a03.insertROL2(0));
164                populateRolC(a03.insertROL2(1));
165                populateDg1(a03.getDG1(), true);
166                populatePr1First(a03.getPROCEDURE(0).getPR1());
167                populatePr1Second(a03.getPROCEDURE(1).getPR1());
168                populateGt1(a03.getGT1());
169                populateIn1(a03.insertINSURANCE(0).getIN1());
170                populateIn2(a03.getINSURANCE(0).getIN2());
171
172                // Assessments (come after DG1 for A03)
173                populateObxAssessmentWeight(a03, a03.insertOBX(0));
174                populateObxAssessmentHeight(a03, a03.insertOBX(0));
175
176                return a03;
177        }
178
179        public ADT_A06 createAdtA06() throws HL7Exception {
180                ADT_A06 a06 = new ADT_A06();
181
182                populateMsh(a06.getMSH(), "ADT^A06^ADT_A06");
183                populatePid(a06.getPID());
184                // pd1
185                populateRolA(a06.insertROL(0));
186                // mrg
187                populateNk1NextOfKin(a06.getNK1());
188                populatePv1(a06.getPV1());
189                populatePv2(a06.getPV2());
190                populateRolB(a06.insertROL2(0));
191                populateObxAssessmentWeight(a06, a06.insertOBX(0));
192                populateAl1(a06.getAL1());
193                populateDg1(a06.getDG1(), true);
194                populatePr1First(a06.getPROCEDURE(0).getPR1());
195                populateGt1(a06.getGT1());
196                populateIn1(a06.insertINSURANCE(0).getIN1());
197                populateIn2(a06.getINSURANCE(0).getIN2());
198
199                return a06;
200        }
201
202        /**
203         * The ADT^A07 trigger uses the same structure as ADT^A06 (i.e. ADT_A06)
204         */
205        public ADT_A06 createAdtA07() throws HL7Exception {
206                ADT_A06 adtA07 = createAdtA06();
207                populateMsh(adtA07.getMSH(), "ADT^A07^ADT_A06");
208                return adtA07;
209        }
210
211        public ADT_A09 createAdtA10() throws HL7Exception {
212                ADT_A09 a09 = new ADT_A09();
213
214                // Patient
215                populateMsh(a09.getMSH(), "ADT^A10^ADT_A09");
216
217                // Visit
218                populatePv1(a09.getPV1());
219
220                return a09;
221        }
222
223        public ADT_A09 createAdtA11() throws HL7Exception {
224                ADT_A09 a09 = new ADT_A09();
225
226                // Patient
227                populateMsh(a09.getMSH(), "ADT^A11^ADT_A09");
228                populatePid(a09.getPID());
229
230                // Visit
231                populatePv1(a09.getPV1());
232                populatePv2(a09.getPV2());
233
234                return a09;
235        }
236
237        public void populateMinimalPatient(PID thePid, PD1 thePd1, PatientData thePatientData) throws HL7Exception {
238                CX pid3 = thePid.insertPid3_PatientIdentifierList(0);
239                pid3.getCx1_IDNumber().setValue(thePatientData.identifier.value);
240                pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue(thePatientData.identifier.system);
241                pid3.getCx5_IdentifierTypeCode().setValue("MR");
242
243                thePd1.getPd119_MilitaryBranch().setValue(thePatientData.militaryBranch);
244        }
245
246        public void populateMinimalEncounter(
247                PV1 thePv1,
248                PV2 thePv2,
249                EncounterData theEncounter,
250                HospitalData theHospital,
251                PractitionerData thePractitioner)
252                throws HL7Exception {
253                thePv1.getPv12_PatientClass().setValue("E"); // Table 0004 - Emergency
254
255                PL assignedLocation = thePv1.getPv13_AssignedPatientLocation();
256                assignedLocation.getPl1_PointOfCare().setValue(theHospital.name);
257                assignedLocation
258                        .getPl10_ComprehensiveLocationIdentifier()
259                        .getEi1_EntityIdentifier()
260                        .setValue(theHospital.identifier.value);
261                assignedLocation
262                        .getPl10_ComprehensiveLocationIdentifier()
263                        .getEi2_NamespaceID()
264                        .setValue(theHospital.identifier.system);
265                assignedLocation.getExtraComponents().getComponent(0).getData().parse(FACILITY_SYSTEM);
266
267                XCN practitioner = thePv1.getPv17_AttendingDoctor(0);
268                practitioner.getXcn1_IDNumber().setValue(thePractitioner.identifier.value);
269                practitioner.getXcn9_AssigningAuthority().getHd1_NamespaceID().setValue(thePractitioner.identifier.system);
270
271                CX visitNumber = thePv1.getPv119_VisitNumber();
272                visitNumber.getCx1_IDNumber().setValue(theEncounter.identifier.value);
273                visitNumber.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue(theEncounter.identifier.system);
274                visitNumber.getCx5_IdentifierTypeCode().setValue("VN"); // Table 0203 - Visit Number
275
276                thePv2.getPv28_ExpectedAdmitDateTime().getTs1_Time().setValue(theEncounter.expectedAdmitTime.v2Date);
277        }
278
279        public void populateMinimalObservation(Message theMessage, OBX theObx, ObservationData theObservationData)
280                throws DataTypeException {
281                theObx.getObx2_ValueType().setValue("ST");
282                ST obxText = new ST(theMessage);
283                obxText.setValue(theObservationData.text);
284                theObx.getObx5_ObservationValue(0).setData(obxText);
285
286                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(theObservationData.code);
287                theObx.getObx3_ObservationIdentifier().getCe3_NameOfCodingSystem().setValue(theObservationData.system);
288
289                theObx.getObx11_ObservationResultStatus().setValue(theObservationData.status);
290                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue(theObservationData.dateTime.v2Date);
291        }
292
293        public ADT_A21 createAdtA29() throws HL7Exception {
294                ADT_A21 a29 = new ADT_A21();
295
296                populateMsh(a29.getMSH(), "ADT^A29^ADT_A21");
297                populatePid(a29.getPID());
298
299                return a29;
300        }
301
302        /**
303         * The ADT^A42 trigger uses the same structure as ADT^A39 (i.e. ADT_A39)
304         */
305        public ADT_A39 createAdtA42() throws HL7Exception {
306                ADT_A39 adtA42 = new ADT_A39();
307                populateMsh(adtA42.getMSH(), "ADT^A42^ADT_A39");
308                populatePid(adtA42.getPATIENT().getPID());
309
310                populateMrg(adtA42.getPATIENT().getMRG());
311                populatePv1(adtA42.getPATIENT().getPV1());
312                return adtA42;
313        }
314
315        public ADT_A45 createAdtA45() throws HL7Exception {
316                ADT_A45 adtA45 = new ADT_A45();
317                populateMsh(adtA45.getMSH(), "ADT^A45^ADT_A45");
318                populatePid(adtA45.getPID());
319
320                populateMrg(adtA45.getMERGE_INFO().getMRG());
321                populatePv1(adtA45.getMERGE_INFO().getPV1());
322
323                return adtA45;
324        }
325
326        public ADT_A54 createAdtA54() throws HL7Exception {
327                ADT_A54 adtA54 = new ADT_A54();
328
329                // Patient and family doctor
330                populateMsh(adtA54.getMSH(), "ADT^A54^ADT_A54");
331                populatePid(adtA54.getPID());
332                populateRolA(adtA54.insertROL(0));
333
334                // Visit, attending, admitting, diagnosis, etc
335                populatePv1(adtA54.getPV1());
336                populateRolB(adtA54.insertROL2(0));
337                populateRolC(adtA54.insertROL2(1));
338
339                return adtA54;
340        }
341
342        public ADT_A60 createAdtA60() throws HL7Exception {
343                return createAdtA60(false);
344        }
345
346        public ADT_A60 createAdtA60(boolean thePopulateEncounterFields) throws HL7Exception {
347                ADT_A60 a60 = new ADT_A60();
348
349                populateMsh(a60.getMSH(), "ADT^A60^ADT_A01");
350                populatePid(a60.getPID());
351                populateIam(a60.getIAM(0));
352
353                if (thePopulateEncounterFields) {
354                        populatePv1(a60.getPV1());
355                        populatePv2(a60.getPV2());
356                }
357
358                return a60;
359        }
360
361        public DFT_P03 createDftP03() throws HL7Exception {
362                DFT_P03 p03 = new DFT_P03();
363
364                populateMsh(p03.getMSH(), "DFT^P03^DFT_P03");
365                populatePid(p03.getPID());
366
367                FT1 ft1 = p03.getFINANCIAL().getFT1();
368                ft1.getFt11_SetIDFT1().setValue("1");
369                ft1.getFt12_TransactionID().setValue("1133");
370                addExtraComponent(ft1.getFt12_TransactionID(), 0, "http://transaction-ids");
371                ft1.getFt13_TransactionBatchID().setValue("9999");
372                ft1.getFt14_TransactionDate().getDr1_RangeStartDateTime().parse("20150325000000-0000");
373                ft1.getFt14_TransactionDate().getDr2_RangeEndDateTime().parse("20150326000000-0000");
374                ft1.getFt16_TransactionType().setValue("CG");
375                ft1.getFt18_TransactionDescription().setValue("Consultation-Level 4");
376                ft1.getFt110_TransactionQuantity().setValue("4");
377                ft1.getFt116_AssignedPatientLocation().getPl1_PointOfCare().setValue("Acme Hospital");
378                ft1.getFt116_AssignedPatientLocation().getPl2_Room().setValue("3rd Floor Room 124");
379                ft1.getFt116_AssignedPatientLocation().getPl3_Bed().setValue("6");
380                ft1.getFt116_AssignedPatientLocation()
381                        .getPl4_Facility()
382                        .getHd1_NamespaceID()
383                        .setValue("Acme Facility");
384                ft1.getFt116_AssignedPatientLocation().getPl9_LocationDescription().setValue("The Acme Hospital");
385                ft1.getFt116_AssignedPatientLocation()
386                        .getPl10_ComprehensiveLocationIdentifier()
387                        .getEi1_EntityIdentifier()
388                        .setValue("Acme H");
389                ft1.getFt116_AssignedPatientLocation()
390                        .getPl10_ComprehensiveLocationIdentifier()
391                        .getEi2_NamespaceID()
392                        .setValue("http://acme.org/wards");
393
394                ft1.getFt120_PerformedByCode(0).getXcn1_IDNumber().setValue("666");
395                ft1.getFt120_PerformedByCode(0).getXcn2_FamilyName().getFn1_Surname().setValue("Dinosaur");
396                ft1.getFt120_PerformedByCode(0).getXcn3_GivenName().setValue("Frances");
397                ft1.getFt120_PerformedByCode(0)
398                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
399                        .setValue("Frannie");
400                ft1.getFt120_PerformedByCode(0)
401                        .getXcn9_AssigningAuthority()
402                        .getHd1_NamespaceID()
403                        .setValue("http://acme.org/clinicians");
404
405                ft1.getFt120_PerformedByCode(1).getXcn1_IDNumber().setValue("666");
406                ft1.getFt120_PerformedByCode(1).getXcn2_FamilyName().getFn1_Surname().setValue("Dinosaur");
407                ft1.getFt120_PerformedByCode(1).getXcn3_GivenName().setValue("Frances");
408                ft1.getFt120_PerformedByCode(1)
409                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
410                        .setValue("Frannie");
411                ft1.getFt120_PerformedByCode(1)
412                        .getXcn9_AssigningAuthority()
413                        .getHd1_NamespaceID()
414                        .setValue("http://acme.org/clinicians");
415
416                ft1.getFt121_OrderedByCode(0).getXcn1_IDNumber().setValue("555");
417                ft1.getFt121_OrderedByCode(0).getXcn2_FamilyName().getFn1_Surname().setValue("Giraffe");
418                ft1.getFt121_OrderedByCode(0).getXcn3_GivenName().setValue("Longneck");
419                ft1.getFt121_OrderedByCode(0)
420                        .getXcn9_AssigningAuthority()
421                        .getHd1_NamespaceID()
422                        .setValue("http://acme.org/clinicians");
423
424                populatePr1First(p03.getFINANCIAL().getFINANCIAL_PROCEDURE().getPR1());
425                populateDg1(p03.getDG1());
426
427                populateIn1(p03.getINSURANCE().getIN1());
428                populateIn2(p03.getINSURANCE().getIN2());
429
430                return p03;
431        }
432
433        public ORM_O01 createOrmO01() throws HL7Exception {
434                ORM_O01 orm = new ORM_O01();
435
436                populateMsh(orm.getMSH(), "ORM^O01^ORM_O01");
437
438                // PATIENT
439                populatePid(orm.getPATIENT().getPID(), true);
440                populatePv1(orm.getPATIENT().getPATIENT_VISIT().getPV1());
441                populateIn1(orm.getPATIENT().getINSURANCE().getIN1()); // Mapped to Organizaion
442                populateIn2(orm.getPATIENT().getINSURANCE().getIN2()); // Mapped to extension on the Patient
443                populateGt1(orm.getPATIENT().getGT1()); // Mapped to RelatedPerson
444                populateDg1(orm.getORDER(0).getORDER_DETAIL().getDG1());
445                orm.getORDER(0)
446                        .getORDER_DETAIL()
447                        .getDG1()
448                        .getDg13_DiagnosisCodeDG1()
449                        .getCe1_Identifier()
450                        .setValue("193462001");
451                orm.getORDER(0)
452                        .getORDER_DETAIL()
453                        .getDG1()
454                        .getDg13_DiagnosisCodeDG1()
455                        .getCe2_Text()
456                        .setValue("Insomnia");
457                orm.getORDER(0).getORDER_DETAIL().getDG1().getDg16_DiagnosisType().setValue("Tentative");
458
459                XCN dg116 = orm.getORDER(0).getORDER_DETAIL().getDG1().insertDg116_DiagnosingClinician(0);
460                populateXcn(dg116);
461
462                orm.getORDER(0)
463                        .getORDER_DETAIL()
464                        .getDG1()
465                        .getDg120_DiagnosisIdentifier()
466                        .getEi1_EntityIdentifier()
467                        .setValue("0000000042");
468                orm.getORDER(0)
469                        .getORDER_DETAIL()
470                        .getDG1()
471                        .getDg120_DiagnosisIdentifier()
472                        .getEi2_NamespaceID()
473                        .setValue("http://acme.org/diagnosis-identifiers");
474
475                // ORDER
476                ORC orc = orm.getORDER().getORC(); // Mapped to DiagnosticOrder
477                orc.getOrc1_OrderControl().setValue("NW");
478
479                EI orc2 = orc.getOrc2_PlacerOrderNumber();
480                orc2.getEi1_EntityIdentifier().setValue("12345");
481                orc2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticOrderIds");
482
483                orc.getOrc4_PlacerGroupNumber().getEi1_EntityIdentifier().setValue("123");
484                orc.getOrc4_PlacerGroupNumber().getEi2_NamespaceID().setValue("http://foo");
485
486                orc.getOrc7_QuantityTiming(0).getTq4_StartDateTime().getTs1_Time().setValue("20160210111213-0400");
487
488                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
489                populateXcn(orc12);
490
491                OBR obr = orm.getORDER().getORDER_DETAIL().getOBR(); // Mapped to DiagnosticReport
492
493                EI obr2 = obr.getObr2_PlacerOrderNumber();
494                obr2.getEi1_EntityIdentifier().setValue("54321");
495                obr2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticIds");
496
497                CE obr4 = obr.getObr4_UniversalServiceIdentifier();
498                obr4.getCe1_Identifier().setValue("5500-1");
499                obr4.getCe2_Text().setValue("Blood Panel");
500                obr4.getCe3_NameOfCodingSystem().setValue("http://acme.org/diagnosticCodes");
501
502                obr.getObr7_ObservationDateTime().getTs1_Time().setValue("201602131000-0400");
503                obr.getObr8_ObservationEndDateTime().getTs1_Time().setValue("201602131100-0400");
504                obr.getObr22_ResultsRptStatusChngDateTime().getTs1_Time().setValue("2017081312-0500");
505                obr.getObr25_ResultStatus().setValue("F");
506                obr.getObr27_QuantityTiming(0).getTq6_Priority().setValue("stat");
507
508                populateDg1(orm.getORDER(0).getORDER_DETAIL().getDG1()); // Mapped to Condition
509
510                // Observation stuff
511                ca.uhn.hl7v2.model.v25.group.ORM_O01_OBSERVATION order;
512                order = orm.getORDER(0).getORDER_DETAIL().getOBSERVATION();
513                order.getOBX().getObx2_ValueType().setValue("NM");
514                order.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("9477-3");
515                order.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Sodium (Plasma)");
516                order.getOBX()
517                        .getObx3_ObservationIdentifier()
518                        .getCe3_NameOfCodingSystem()
519                        .setValue("http://acme.org/observationCodes");
520                NM nm = new NM(orm);
521                nm.setValue("150");
522                order.getOBX().insertObx5_ObservationValue(0).setData(nm);
523                order.getOBX().getObx6_Units().getCe1_Identifier().setValue("mmol/L");
524                order.getOBX().getObx6_Units().getCe2_Text().setValue("mmol/Liter");
525                order.getOBX().getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
526                order.getOBX().getObx7_ReferencesRange().setValue("0.2-333");
527                order.getOBX().getObx11_ObservationResultStatus().setValue("F");
528
529                CE obx15 = order.getOBX().getObx15_ProducerSID();
530                obx15.getCe1_Identifier().setValue("3141592");
531                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
532
533                XCN obx16 = order.getOBX().getObx16_ResponsibleObserver(0);
534                populateXcn(obx16);
535
536                order.getOBX().getObx19_DateTimeOfTheAnalysis().getTs1_Time().setValue("20110202112233+0100");
537
538                Varies obx23 = (Varies) order.getOBX().getField(23, 0);
539                obx23.parse("Acme Facility");
540
541                Varies obx24 = (Varies) order.getOBX().getField(24, 0);
542                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
543
544                return orm;
545        }
546
547        public ORU_R01 createOruR01() throws HL7Exception {
548                ORU_R01 r01 = new ORU_R01();
549                r01.setParser(ourV2Ctx.getPipeParser());
550
551                r01.getMSH().getMsh1_FieldSeparator().setValue("|");
552                r01.getMSH().getMsh2_EncodingCharacters().setValue("^~\\&");
553                r01.getMSH().getMsh3_SendingApplication().getHd1_NamespaceID().setValue("http://acme.org/application");
554                r01.getMSH().getMsh3_SendingApplication().getHd2_UniversalID().setValue("ACME Application");
555                r01.getMSH().getMsh4_SendingFacility().getHd1_NamespaceID().setValue("http://acme.org/facility");
556                r01.getMSH().getMsh4_SendingFacility().getHd2_UniversalID().setValue("Acme Facility");
557                r01.getMSH().getMsh9_MessageType().parse("ORU^R01^ORU_R01");
558                r01.getMSH().getMsh10_MessageControlID().setValue("A001");
559                r01.getMSH().getMsh11_ProcessingID().parse("T");
560                r01.getMSH().getMsh12_VersionID().parse("2.5");
561
562                ORU_R01_PATIENT_RESULT patientResult = r01.insertPATIENT_RESULT(0);
563                populatePid(patientResult.getPATIENT().getPID());
564                populatePv1(patientResult.getPATIENT().getVISIT().getPV1());
565
566                ORC orc = patientResult.getORDER_OBSERVATION().getORC();
567                orc.getOrc1_OrderControl().setValue("NW");
568
569                EI orc2 = orc.getOrc2_PlacerOrderNumber();
570                orc2.getEi1_EntityIdentifier().setValue("12345");
571                orc2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticOrderIds");
572
573                orc.getOrc4_PlacerGroupNumber().getEi1_EntityIdentifier().setValue("123");
574                orc.getOrc4_PlacerGroupNumber().getEi2_NamespaceID().setValue("http://foo");
575
576                orc.getOrc7_QuantityTiming(0).getTq4_StartDateTime().getTs1_Time().setValue("20160210111213-0400");
577
578                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
579                populateXcn(orc12);
580
581                OBR obr = patientResult.getORDER_OBSERVATION().getOBR();
582
583                EI obr2 = obr.getObr2_PlacerOrderNumber();
584                obr2.getEi1_EntityIdentifier().setValue("54321");
585                obr2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticIds");
586
587                CE obr4 = obr.getObr4_UniversalServiceIdentifier();
588                obr4.getCe1_Identifier().setValue("5500-1");
589                obr4.getCe2_Text().setValue("Blood Panel");
590                obr4.getCe3_NameOfCodingSystem().setValue("http://acme.org/diagnosticCodes");
591
592                obr.getObr7_ObservationDateTime().getTs1_Time().setValue("201602131000-0400");
593                obr.getObr8_ObservationEndDateTime().getTs1_Time().setValue("201602131100-0400");
594                obr.getObr22_ResultsRptStatusChngDateTime().getTs1_Time().setValue("2017081312-0500");
595                obr.getObr25_ResultStatus().setValue("F");
596                obr.getObr27_QuantityTiming(0).getTq6_Priority().setValue("stat");
597
598                patientResult.getORDER_OBSERVATION().getNTE(0).insertNte3_Comment(0).setValue("Comment Line 1");
599                patientResult.getORDER_OBSERVATION().getNTE(0).insertNte3_Comment(1).setValue("Comment Line 2");
600                patientResult.getORDER_OBSERVATION().getNTE(1).insertNte3_Comment(0).setValue("Comment Line 3");
601                patientResult.getORDER_OBSERVATION().getNTE(2).insertNte3_Comment(0).parse("Comment Line 4a & Comment Line 4b");
602
603                ca.uhn.hl7v2.model.v25.group.ORU_R01_OBSERVATION observation;
604                observation = patientResult
605                        .getORDER_OBSERVATION()
606                        .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
607                observation.getOBX().getObx2_ValueType().setValue("NM");
608                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("9477-3");
609                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Sodium (Plasma)");
610                observation
611                        .getOBX()
612                        .getObx3_ObservationIdentifier()
613                        .getCe3_NameOfCodingSystem()
614                        .setValue("http://acme.org/observationCodes");
615                NM nm = new NM(r01);
616                nm.setValue("150");
617                observation.getOBX().insertObx5_ObservationValue(0).setData(nm);
618                observation.getOBX().getObx6_Units().getCe1_Identifier().setValue("mmol/L");
619                observation.getOBX().getObx6_Units().getCe2_Text().setValue("mmol/Liter");
620                observation.getOBX().getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
621                observation.getOBX().getObx7_ReferencesRange().setValue("0.2-333");
622                observation.getOBX().getObx11_ObservationResultStatus().setValue("F");
623
624                CE obx15 = observation.getOBX().getObx15_ProducerSID();
625                obx15.getCe1_Identifier().setValue("3141592");
626                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
627
628                XCN obx16 = observation.getOBX().getObx16_ResponsibleObserver(0);
629                populateXcn(obx16);
630
631                observation.getOBX().getObx19_DateTimeOfTheAnalysis().getTs1_Time().setValue("20110202112233+0100");
632
633                Varies obx23 = (Varies) observation.getOBX().getField(23, 0);
634                obx23.parse("Acme Facility");
635
636                Varies obx24 = (Varies) observation.getOBX().getField(24, 0);
637                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
638
639                observation = patientResult
640                        .getORDER_OBSERVATION()
641                        .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
642                observation.getOBX().getObx2_ValueType().setValue("DT");
643                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("3472-2");
644                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Fasting Date");
645                observation
646                        .getOBX()
647                        .getObx3_ObservationIdentifier()
648                        .getCe3_NameOfCodingSystem()
649                        .setValue("http://acme.org/observationCodes");
650                DT dt = new DT(r01);
651                dt.setValue("20160213");
652                observation.getOBX().insertObx5_ObservationValue(0).setData(dt);
653                observation.getOBX().getObx11_ObservationResultStatus().setValue("F");
654                observation.getOBX().getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("20160101121314.1234-0400");
655                observation.getNTE(0).insertNte3_Comment(0).setValue("Comment Line 1");
656                observation.getNTE(0).insertNte3_Comment(1).setValue("Comment Line 2");
657                observation.getNTE(1).insertNte3_Comment(0).setValue("Comment Line 3");
658                observation.getNTE(2).insertNte3_Comment(0).parse("Comment Line 4a & Comment Line 4b");
659
660                obx15 = observation.getOBX().getObx15_ProducerSID();
661                obx15.getCe1_Identifier().setValue("3141592");
662                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
663
664                obx23 = (Varies) observation.getOBX().getField(23, 0);
665                obx23.parse("Acme Facility");
666
667                obx24 = (Varies) observation.getOBX().getField(24, 0);
668                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
669
670                // Some OBX String lines
671
672                observation = patientResult
673                        .getORDER_OBSERVATION()
674                        .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
675                observation.getOBX().getObx2_ValueType().setValue("ST");
676                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("17464-1");
677                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Text Comment");
678                observation
679                        .getOBX()
680                        .getObx3_ObservationIdentifier()
681                        .getCe3_NameOfCodingSystem()
682                        .setValue("http://acme.org/observationCodes");
683                ST st = new ST(r01);
684                st.setValue("line 1");
685                observation.getOBX().insertObx5_ObservationValue(0).setData(st);
686                st = new ST(r01);
687                st.setValue("line 2");
688                observation.getOBX().insertObx5_ObservationValue(1).setData(st);
689
690                obx15 = observation.getOBX().getObx15_ProducerSID();
691                obx15.getCe1_Identifier().setValue("3141592");
692                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
693
694                obx23 = (Varies) observation.getOBX().getField(23, 0);
695                obx23.parse("Acme Facility");
696
697                obx24 = (Varies) observation.getOBX().getField(24, 0);
698                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
699
700                observation = patientResult
701                        .getORDER_OBSERVATION()
702                        .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
703                observation.getOBX().getObx2_ValueType().setValue("ST");
704                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("17464-1");
705                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Text Comment");
706                observation
707                        .getOBX()
708                        .getObx3_ObservationIdentifier()
709                        .getCe3_NameOfCodingSystem()
710                        .setValue("http://acme.org/observationCodes");
711                st = new ST(r01);
712                st.setValue("line 3");
713                observation.getOBX().insertObx5_ObservationValue(0).setData(st);
714                st = new ST(r01);
715                st.setValue("line 4");
716                observation.getOBX().insertObx5_ObservationValue(1).setData(st);
717
718                obx15 = observation.getOBX().getObx15_ProducerSID();
719                obx15.getCe1_Identifier().setValue("3141592");
720                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
721
722                obx23 = (Varies) observation.getOBX().getField(23, 0);
723                obx23.parse("Acme Facility");
724
725                obx24 = (Varies) observation.getOBX().getField(24, 0);
726                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
727
728                return r01;
729        }
730
731        public RDE_O11 createRdeO11() throws HL7Exception {
732                return createRdeO11(false);
733        }
734
735        public RDE_O11 createRdeO11(boolean hasMultipleComponents) throws HL7Exception {
736                return createRdeO11(hasMultipleComponents, true);
737        }
738
739        public RDE_O11 createRdeO11(boolean hasMultipleComponents, boolean bothComponentsAreCoded) throws HL7Exception {
740                RDE_O11 rde = new RDE_O11();
741                populateMsh(rde.getMSH(), "RDE^O11^RDE_O11");
742                populatePid(rde.getPATIENT().getPID(), true);
743                populatePv1(rde.getPATIENT().getPATIENT_VISIT().getPV1());
744
745                RDE_O11_ORDER order = rde.insertORDER(0);
746                ORC orc = order.getORC();
747                populateOrcForMedication(orc, "NW", true, false);
748
749                RXE rxe = order.getRXE();
750                populateRxe(rxe);
751
752                RXR rxr = order.getRXR();
753                populateRxr(rxr);
754
755                RXC rxc = order.insertRXC(0);
756                rxc.getRxc1_RXComponentType().setValue("A");
757                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("MEW");
758                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Kittens");
759                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/cats");
760                rxc.getRxc3_ComponentAmount().setValue("0.5");
761                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
762
763                if (hasMultipleComponents) {
764                        if (bothComponentsAreCoded) {
765                                rxc = order.insertRXC(1);
766                                rxc.getRxc1_RXComponentType().setValue("B");
767                                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("WAF");
768                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Puppies");
769                                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/dogs");
770                                rxc.getRxc3_ComponentAmount().setValue("0.3");
771                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
772                        } else {
773                                rxc = order.insertRXC(1);
774                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Duckies");
775                                rxc.getRxc3_ComponentAmount().setValue("0.2");
776                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
777                        }
778                }
779
780                return rde;
781        }
782
783        public SIU_S12 createSiuS12() throws HL7Exception {
784
785                /* Sample from NEMS
786                MSH|^~\&|NextGen Rosetta|NextGen Clinic^0001|Billing System|Billing System|20201215094458188||SIU^S14|365776434|P|2.5
787                SCH|5617679^5617679|5617679^5617679||||79c7e354-8743-47ed-b8ca-66c4308c55ff^Follow Up 15 Min|^Smile API Testing Details|79c7e354-8743-47ed-b8ca-66c4308c55ff^Follow Up 15 Min|15|minutes|^^^202012150945^202012151000|||||1562^CDR^Smile||||1562^CDR^Smile|||||KEPT
788                PID|1|000001084399|312759||Test^Xiuming||20000401|M||11111111-1234-5678-3333-111122223333^Declined to specify|123 Smile Ave^^San Francisco^CA^94112^4c370504-8471-4303-a04b-200a31015e17^^^121cbd16-ba04-4d58-ac09-9ada6474505b||4152223333||^eng^|||||||78860700-68ed-4c0f-bf10-b6a522831ae4^Other||||||||N
789                PV1|1|O|ab8af01a-fbcc-4ead-9b24-8bac014f413b||||bd1a5a82-6dee-4a8a-8059-37e8db475b1e^Smile PROV^Demo|||||||||||||||||||||||||||||||||||||202012150944||||||c9fb567a-e4e5-4e2e-a042-23db78859880
790                AIL|1|A|ab8af01a-fbcc-4ead-9b24-8bac014f413b^San Bruno Adult NEMS^San Bruno 1 Medical|^Place||202012150945||||||KEPT
791                AIP|1|A|bd1a5a82-6dee-4a8a-8059-37e8db475b1e^Smile PROV^Demo|P^Attending||202012150945||||||KEPT
792                AIP|2|A|e1e79ce3-070b-48eb-b898-dc498f6efcaa^Abstracted^Med|S^Resource||202012150945||||||KEPT
793                NTE||{"formSet":[{"formLabel":"nems-instructions"},{"formLabel":"nems-phq9"},{"formLabel":"nems-bhs"},{"formLabel":"nems-gad7"}]}|20^8^14||+Smile API Testing
794                 */
795
796                SIU_S12 siu = new SIU_S12();
797
798                populateMsh(siu.getMSH(), "SIU^S12^SIU_S12");
799
800                populateSch(siu.getSCH());
801                populateAil(siu.getRESOURCES().getLOCATION_RESOURCE().getAIL());
802                populateAip(siu.getRESOURCES().getPERSONNEL_RESOURCE().getAIP());
803
804                populatePv1(siu.getPATIENT().getPV1());
805                populatePid(siu.getPATIENT().getPID(), true);
806
807                return siu;
808        }
809
810        public VXU_V04 createVxuV04() throws HL7Exception {
811                VXU_V04 vxu = new VXU_V04();
812
813                // Patient, family doctor, next of kin, and employer
814                populateMsh(vxu.getMSH(), "VXU^V04^VXU_V04");
815                populatePid(vxu.getPID(), true);
816
817                ORC orc = vxu.getORDER().getORC();
818                orc.getOrc1_OrderControl().setValue("RE");
819                orc.getOrc2_PlacerOrderNumber().getEi1_EntityIdentifier().setValue("0001");
820                orc.getOrc2_PlacerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/vaxorders");
821
822                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
823                populateXcn(orc12);
824
825                /*
826                Sample from MUSC
827
828                MSH|^~\&|EPIC|SC378274|SIMON|SIMON|20210202071234-0500|NOF200|VXU^V04^VXU_V04|878162|P|2.5.1|||ER|AL|||||Z22^CDCPHINVS||
829                PID|1||009999901^^^MRN^MR||TESTER^NICK^^^^^L||19810724|M|||55 FAKE STREET^^CHARLESTON^SC^29401^US^P^^| |^PRN^PH^^1^865^5551212~^NET^Internet^npappageorgio@gmail.com|||||9950381520||||||N||||||N||
830                ORC|RE|228878084^MUSC_EPIC|16306934^MUSC||||||20210202071216-0500|NOF200^FLEISCHMANN^NOELLE^^^^^^MUSCNetID||1871601732^SCHEURER^DANIELLE^B.^^^^^MUSC_EPIC^^^^PNPI|^^^MUSC RUTLEDGE TOWER&SC378274&IMM^^^^^|^^^^1^843^7922300^^||||58D99F5F5D8CD6502783D9901B5E1ECDA83173F1^ROVER IOS 144|||||||||||I|
831                RXA|0|1|20210202|20210202|208^COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML^CVX|30|mcg^micrograms^UCUM||00^New immunization record^NIP001~^VIS date: 12/01/2020~~~|NOF200^FLEISCHMANN^NOELLE^^^^^^MUSCNetID|^^^MUSC RUTLEDGE TOWER&SC378274&IMM^^^^^||||EN9581|20210502|PFR^Pfizer, Inc^MVX|||CP|A|20210202071234-0500||||||
832                RXR|IM^Intramuscular^HL70162|LD^Left deltoid^HL70163
833                OBX|1|CE|30956-7^Vaccine Type^LN|1|208^COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML^CVX||||||F|||20210202||||||||||||||||||
834                OBX|2|DT|29768-9^VIS Publication Date^LN|1|20201201||||||F|||20210202||||||||||||||||||
835                OBX|3|DT|29769-7^VIS Presentation Date^LN|1|20210202||||||F|||20210202||||||||||||||||||
836                */
837
838                RXA rxa = vxu.getORDER().getRXA();
839                rxa.getRxa2_AdministrationSubIDCounter().setValue("1");
840                rxa.getRxa2_AdministrationSubIDCounter()
841                        .getExtraComponents()
842                        .getComponent(0)
843                        .getData()
844                        .parse("http://acme.org/medadmins");
845                rxa.getRxa3_DateTimeStartOfAdministration().getTs1_Time().setValue("20171209071055-0500");
846                rxa.getRxa4_DateTimeEndOfAdministration().getTs1_Time().setValue("20171209071100-0500");
847                rxa.getRxa5_AdministeredCode().getCe1_Identifier().setValue("208");
848                rxa.getRxa5_AdministeredCode().getCe2_Text().setValue("COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML");
849                rxa.getRxa5_AdministeredCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/meds");
850                rxa.getRxa6_AdministeredAmount().setValue("4");
851                rxa.getRxa7_AdministeredUnits().parse("mg^milligrams^http://unitsofmeasure.org");
852                rxa.getRxa9_AdministrationNotes(0).getCe2_Text().setValue("This is a note");
853
854                rxa.getRxa10_AdministeringProvider(0).getXcn1_IDNumber().setValue("825");
855                rxa.getRxa10_AdministeringProvider(0)
856                        .getXcn2_FamilyName()
857                        .getFn1_Surname()
858                        .setValue("Bouvier");
859                rxa.getRxa10_AdministeringProvider(0).getXcn3_GivenName().setValue("Marge");
860                rxa.getRxa10_AdministeringProvider(0)
861                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
862                        .setValue("Q");
863                rxa.getRxa10_AdministeringProvider(0)
864                        .getXcn9_AssigningAuthority()
865                        .getHd1_NamespaceID()
866                        .setValue("http://acme.org/clinicians");
867
868                rxa.getRxa12_AdministeredPerTimeUnit().setValue("Day");
869                rxa.getRxa20_CompletionStatus().setValue("CP");
870
871                populateRxr(vxu.getORDER().getRXR());
872
873                return vxu;
874        }
875
876        public void populateAil(AIL theAil) throws HL7Exception {
877
878                theAil.getAil1_SetIDAIL().setValue("4321");
879                theAil.getAil2_SegmentActionCode().setValue("U"); // [A]dd, [D]elete, [U]pdate, [X] no change
880                theAil.getAil3_LocationResourceID(0)
881                        .getPl1_PointOfCare()
882                        .setValue("locations^http://acme.org/location/321^DNS");
883                theAil.getAil3_LocationResourceID(0).getPl2_Room().setValue("room^http://acme.org/location/room/321^DNS");
884                theAil.getAil3_LocationResourceID(0).getPl3_Bed().setValue("bed^http://acme.org/location/room/321/bed/a^DNS");
885                // AIL-3.PL-10.EI-1,EI-2 are responsible for a location's first identifier
886                theAil.getAil3_LocationResourceID(0)
887                        .getPl10_ComprehensiveLocationIdentifier()
888                        .getEi1_EntityIdentifier()
889                        .setValue("6789");
890                theAil.getAil3_LocationResourceID(0)
891                        .getPl10_ComprehensiveLocationIdentifier()
892                        .getEi2_NamespaceID()
893                        .setValue("http://acme.org/locaton");
894                theAil.getAil3_LocationResourceID(0)
895                        .getPl11_AssigningAuthorityForLocation()
896                        .getHd1_NamespaceID()
897                        .setValue("http://acme.org");
898
899                theAil.getAil4_LocationTypeAIL().getCe1_Identifier().setValue("C");
900
901                theAil.getAil6_StartDateTime().getTs1_Time().setValue("202104121335-0500");
902
903                theAil.getAil9_Duration().setValue("30");
904                theAil.getAil10_DurationUnits().getCe1_Identifier().setValue("minutes");
905                theAil.getAil10_DurationUnits().getCe2_Text().setValue("Minutes");
906        }
907
908        public void populateAip(AIP theAip) throws HL7Exception {
909
910                theAip.getAip1_SetIDAIP().setValue("6543");
911                theAip.getAip2_SegmentActionCode().setValue("U"); // [A]dd, [D]elete, [U]pdate, [X] no change
912                theAip.getAip3_PersonnelResourceID(0).getXcn1_IDNumber().setValue("5432");
913                theAip.getAip3_PersonnelResourceID(0)
914                        .getXcn2_FamilyName()
915                        .getFn1_Surname()
916                        .setValue("Smith");
917                theAip.getAip3_PersonnelResourceID(0).getXcn3_GivenName().setValue("Jane");
918                theAip.getAip3_PersonnelResourceID(0)
919                        .getXcn9_AssigningAuthority()
920                        .getHd1_NamespaceID()
921                        .setValue("http://acme.org");
922
923                theAip.getAip4_ResourceType().getCe1_Identifier().setValue("PPRF");
924
925                theAip.getAip6_StartDateTime().getTs1_Time().setValue("202104121335-0500");
926
927                theAip.getAip9_Duration().setValue("30");
928                theAip.getAip10_DurationUnits().getCe1_Identifier().setValue("minutes");
929                theAip.getAip10_DurationUnits().getCe2_Text().setValue("Minutes");
930
931                theAip.getAip12_FillerStatusCode().getCe1_Identifier().setValue("Booked");
932        }
933
934        public void populateDg1(DG1 theDg1) throws DataTypeException {
935                theDg1.getDg13_DiagnosisCodeDG1().getCe1_Identifier().setValue("193462001");
936                theDg1.getDg13_DiagnosisCodeDG1().getCe2_Text().setValue("Insomnia");
937                theDg1.getDg13_DiagnosisCodeDG1().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
938        }
939
940        public DG1 populateDg1(DG1 theDg1, boolean includeDiagnosisTypeAndPriority) throws HL7Exception {
941                theDg1.getDg13_DiagnosisCodeDG1().getCe1_Identifier().setValue("193462001");
942                theDg1.getDg13_DiagnosisCodeDG1().getCe2_Text().setValue("Insomnia");
943                theDg1.getDg13_DiagnosisCodeDG1().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
944
945                theDg1.getDg15_DiagnosisDateTime().getTs1_Time().setValue("20010101070000-0400");
946
947                if (includeDiagnosisTypeAndPriority) {
948                        theDg1.getDg16_DiagnosisType().setValue("F");
949                        theDg1.getDg115_DiagnosisPriority().setValue("1");
950                }
951
952                XCN dg116 = theDg1.insertDg116_DiagnosingClinician(0);
953                populateXcn(dg116);
954
955                theDg1.getDg120_DiagnosisIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
956                theDg1.getDg120_DiagnosisIdentifier().getEi2_NamespaceID().setValue("http://acme.org/diagnosis-identifiers");
957
958                return theDg1;
959        }
960
961        public void populateGt1(GT1 theGt1) throws HL7Exception {
962                theGt1.getGt12_GuarantorNumber(0).getCx1_IDNumber().setValue("23323");
963                theGt1.getGt12_GuarantorNumber(0)
964                        .getCx4_AssigningAuthority()
965                        .getHd1_NamespaceID()
966                        .setValue("http://acme.org/guarantors");
967                theGt1.getGt12_GuarantorNumber(1).getCx1_IDNumber().setValue("32332");
968                theGt1.getGt12_GuarantorNumber(1)
969                        .getCx4_AssigningAuthority()
970                        .getHd1_NamespaceID()
971                        .setValue("http://acme.org/guarantors");
972                XPN gt13 = theGt1.insertGt13_GuarantorName(0);
973                gt13.getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
974                gt13.getXpn2_GivenName().setValue("Fannie");
975                gt13.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Foo");
976                gt13.getXpn4_SuffixEgJRorIII().setValue("Jr");
977                gt13.getXpn7_NameTypeCode().setValue("L");
978                XAD gt15 = theGt1.insertGt15_GuarantorAddress(0);
979                gt15.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("313 Fleet Street");
980                gt15.getXad3_City().setValue("Cheektowaga");
981                gt15.getXad4_StateOrProvince().setValue("NY");
982                gt15.getXad5_ZipOrPostalCode().setValue("28366");
983                gt15.getXad6_Country().setValue("USA");
984                gt15.getXad7_AddressType().setValue("W");
985                XTN gt16 = theGt1.insertGt16_GuarantorPhNumHome(0);
986                gt16.getXtn1_TelephoneNumber().setValue("1(333)555-1234");
987                gt16.getXtn2_TelecommunicationUseCode().setValue("PRN");
988                gt16.getXtn3_TelecommunicationEquipmentType().setValue("PH");
989                theGt1.getGt18_GuarantorDateTimeOfBirth().getTs1_Time().setValue("19000102");
990                theGt1.getGt19_GuarantorAdministrativeSex().setValue("M");
991                theGt1.getGt111_GuarantorRelationship().getCe1_Identifier().setValue("MTH");
992                theGt1.getGt111_GuarantorRelationship().getCe2_Text().setValue("mother");
993                theGt1.getGt111_GuarantorRelationship()
994                        .getCe3_NameOfCodingSystem()
995                        .setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
996        }
997
998        public void populateIam(IAM theIam) throws HL7Exception {
999                theIam.getIam2_AllergenTypeCode().getCe1_Identifier().setValue("DA");
1000                theIam.getIam2_AllergenTypeCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0127);
1001                theIam.getIam3_AllergenCodeMnemonicDescription().getCe1_Identifier().setValue("256259004");
1002                theIam.getIam3_AllergenCodeMnemonicDescription().getCe2_Text().setValue("Pollen (Substance)");
1003                theIam.getIam3_AllergenCodeMnemonicDescription()
1004                        .getCe3_NameOfCodingSystem()
1005                        .setValue(PublicApiConstants.CODE_SYSTEM_SNOMED);
1006                theIam.getIam4_AllergySeverityCode().getCe1_Identifier().setValue("SV");
1007                theIam.getIam4_AllergySeverityCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0128);
1008                theIam.getIam5_AllergyReactionCode(0).setValue("Wheezing");
1009                theIam.getIam5_AllergyReactionCode(1).setValue("Puking Guts Out");
1010                theIam.getIam7_AllergyUniqueIdentifier().getEi1_EntityIdentifier().setValue("88344");
1011                theIam.getIam7_AllergyUniqueIdentifier().getEi2_NamespaceID().setValue("http://acme.org/allergies");
1012                theIam.getIam11_OnsetDate().parse("20170203");
1013                theIam.getIam13_ReportedDateTime().parse("20170204");
1014                theIam.getIam17_AllergyClinicalStatusCode().getCe1_Identifier().setValue("C");
1015                theIam.getIam17_AllergyClinicalStatusCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0438);
1016        }
1017
1018        public void populateAl1(AL1 theIam) throws HL7Exception {
1019                theIam.getAl12_AllergenTypeCode().getCe1_Identifier().setValue("DA");
1020                theIam.getAl12_AllergenTypeCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0127);
1021                theIam.getAl13_AllergenCodeMnemonicDescription().getCe1_Identifier().setValue("256259004");
1022                theIam.getAl13_AllergenCodeMnemonicDescription().getCe2_Text().setValue("Pollen (Substance)");
1023                theIam.getAl13_AllergenCodeMnemonicDescription()
1024                        .getCe3_NameOfCodingSystem()
1025                        .setValue(PublicApiConstants.CODE_SYSTEM_SNOMED);
1026                theIam.getAl14_AllergySeverityCode().getCe1_Identifier().setValue("SV");
1027                theIam.getAl14_AllergySeverityCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0128);
1028                theIam.getAl15_AllergyReactionCode(0).setValue("Wheezing");
1029                theIam.getAl15_AllergyReactionCode(1).setValue("Puking Guts Out");
1030                theIam.getAl16_IdentificationDate().setValue("20001231");
1031        }
1032
1033        public void populateIn1(IN1 theIn1) throws DataTypeException {
1034                theIn1.getIn12_InsurancePlanID().getCe3_NameOfCodingSystem().setValue("http://acme.org/insurancePlanIds");
1035                theIn1.getIn12_InsurancePlanID().getCe1_Identifier().setValue("449988");
1036                theIn1.getIn13_InsuranceCompanyID(0).getCx1_IDNumber().setValue("443322");
1037                theIn1.getIn13_InsuranceCompanyID(0)
1038                        .getCx4_AssigningAuthority()
1039                        .getHd1_NamespaceID()
1040                        .setValue("http://acme.org/insurerIds");
1041                theIn1.getIn14_InsuranceCompanyName(0).getXon1_OrganizationName().setValue("InsurerCo");
1042                theIn1.getIn15_InsuranceCompanyAddress(0)
1043                        .getXad1_StreetAddress()
1044                        .getSad1_StreetOrMailingAddress()
1045                        .setValue("342 Evergreen Terrace");
1046                theIn1.getIn15_InsuranceCompanyAddress(0).getXad2_OtherDesignation().setValue("2nd Floor");
1047                theIn1.getIn15_InsuranceCompanyAddress(0).getXad3_City().setValue("Springfield");
1048                theIn1.getIn15_InsuranceCompanyAddress(0).getXad4_StateOrProvince().setValue("NI");
1049                theIn1.getIn15_InsuranceCompanyAddress(0).getXad5_ZipOrPostalCode().setValue("12345");
1050                theIn1.getIn15_InsuranceCompanyAddress(0).getXad6_Country().setValue("USA");
1051                theIn1.getIn15_InsuranceCompanyAddress(0).getXad7_AddressType().setValue("W");
1052                theIn1.getIn116_NameOfInsured(0).getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1053                theIn1.getIn116_NameOfInsured(0).getXpn2_GivenName().setValue("John");
1054                theIn1.getIn116_NameOfInsured(0)
1055                        .getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof()
1056                        .setValue("Q");
1057                theIn1.getIn116_NameOfInsured(0).getXpn4_SuffixEgJRorIII().setValue("Jr");
1058                theIn1.getIn116_NameOfInsured(0).getXpn7_NameTypeCode().setValue("L");
1059        }
1060
1061        public void populateIn1Difference(IN1 theIn1, String identifier) throws DataTypeException {
1062                theIn1.getIn12_InsurancePlanID().getCe3_NameOfCodingSystem().setValue("http://acme.org/insurancePlanIds");
1063                theIn1.getIn12_InsurancePlanID().getCe1_Identifier().setValue("449988" + identifier);
1064                theIn1.getIn13_InsuranceCompanyID(0).getCx1_IDNumber().setValue("443322" + identifier);
1065                theIn1.getIn13_InsuranceCompanyID(0)
1066                        .getCx4_AssigningAuthority()
1067                        .getHd1_NamespaceID()
1068                        .setValue("http://acme.org/insurerIds");
1069                theIn1.getIn14_InsuranceCompanyName(0).getXon1_OrganizationName().setValue("InsurerCo" + identifier);
1070                theIn1.getIn15_InsuranceCompanyAddress(0)
1071                        .getXad1_StreetAddress()
1072                        .getSad1_StreetOrMailingAddress()
1073                        .setValue("342 Evergreen Terrace");
1074                theIn1.getIn15_InsuranceCompanyAddress(0).getXad2_OtherDesignation().setValue("2nd Floor");
1075                theIn1.getIn15_InsuranceCompanyAddress(0).getXad3_City().setValue("Springfield");
1076                theIn1.getIn15_InsuranceCompanyAddress(0).getXad4_StateOrProvince().setValue("NI");
1077                theIn1.getIn15_InsuranceCompanyAddress(0).getXad5_ZipOrPostalCode().setValue("12345");
1078                theIn1.getIn15_InsuranceCompanyAddress(0).getXad6_Country().setValue("USA");
1079                theIn1.getIn15_InsuranceCompanyAddress(0).getXad7_AddressType().setValue("W");
1080                theIn1.getIn116_NameOfInsured(0).getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1081                theIn1.getIn116_NameOfInsured(0).getXpn2_GivenName().setValue("John");
1082                theIn1.getIn116_NameOfInsured(0)
1083                        .getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof()
1084                        .setValue("Q");
1085                theIn1.getIn116_NameOfInsured(0).getXpn4_SuffixEgJRorIII().setValue("Jr");
1086                theIn1.getIn116_NameOfInsured(0).getXpn7_NameTypeCode().setValue("L");
1087        }
1088
1089        public void populateIn2(IN2 theIn2) throws HL7Exception {
1090                theIn2.getIn214_MilitaryService().setValue("A");
1091                theIn2.getIn214_MilitaryService()
1092                        .getExtraComponents()
1093                        .getComponent(0)
1094                        .getData()
1095                        .parse("U.S. ARMY");
1096                theIn2.getIn214_MilitaryService()
1097                        .getExtraComponents()
1098                        .getComponent(1)
1099                        .getData()
1100                        .parse("urn:test:source:militarybranch");
1101                theIn2.getIn214_MilitaryService()
1102                        .getExtraComponents()
1103                        .getComponent(2)
1104                        .getData()
1105                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1106                theIn2.getIn214_MilitaryService()
1107                        .getExtraComponents()
1108                        .getComponent(3)
1109                        .getData()
1110                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-branch");
1111
1112                theIn2.getIn215_MilitaryRankGrade().setValue("MG");
1113                theIn2.getIn215_MilitaryRankGrade()
1114                        .getExtraComponents()
1115                        .getComponent(0)
1116                        .getData()
1117                        .parse("O8 MAJ GENERAL");
1118                theIn2.getIn215_MilitaryRankGrade()
1119                        .getExtraComponents()
1120                        .getComponent(1)
1121                        .getData()
1122                        .parse("urn:test:source:militaryrank");
1123                theIn2.getIn215_MilitaryRankGrade()
1124                        .getExtraComponents()
1125                        .getComponent(2)
1126                        .getData()
1127                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1128                theIn2.getIn215_MilitaryRankGrade()
1129                        .getExtraComponents()
1130                        .getComponent(3)
1131                        .getData()
1132                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-rank");
1133
1134                theIn2.getIn216_MilitaryStatus().setValue("R");
1135                theIn2.getIn216_MilitaryStatus()
1136                        .getExtraComponents()
1137                        .getComponent(0)
1138                        .getData()
1139                        .parse("RETIRED");
1140                theIn2.getIn216_MilitaryStatus()
1141                        .getExtraComponents()
1142                        .getComponent(1)
1143                        .getData()
1144                        .parse("urn:test:source:militarystatus");
1145                theIn2.getIn216_MilitaryStatus()
1146                        .getExtraComponents()
1147                        .getComponent(2)
1148                        .getData()
1149                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1150                theIn2.getIn216_MilitaryStatus()
1151                        .getExtraComponents()
1152                        .getComponent(3)
1153                        .getData()
1154                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-status");
1155        }
1156
1157        public void populateMsh(MSH theMsh, String messageType) throws HL7Exception {
1158                theMsh.getMsh1_FieldSeparator().setValue("|");
1159                theMsh.getMsh2_EncodingCharacters().setValue("^~\\&");
1160                theMsh.getMsh3_SendingApplication().getHd1_NamespaceID().setValue("http://acme.org/application");
1161                theMsh.getMsh3_SendingApplication().getHd2_UniversalID().setValue("ACME Application");
1162                theMsh.getMsh4_SendingFacility().getHd1_NamespaceID().setValue("http://acme.org/facility");
1163                theMsh.getMsh4_SendingFacility().getHd2_UniversalID().setValue("Acme Facility");
1164                theMsh.getMsh9_MessageType().parse(messageType);
1165                theMsh.getMsh10_MessageControlID().setValue("A001");
1166                theMsh.getMsh11_ProcessingID().parse("T");
1167                theMsh.getMsh12_VersionID().parse("2.5");
1168        }
1169
1170        public void populateNk1Employer(NK1 theNk1) throws HL7Exception {
1171                theNk1.getNk11_SetIDNK1().setValue("2");
1172
1173                XPN nk12 = theNk1.insertNk12_NKName(0);
1174                nk12.getXpn1_FamilyName().getFn1_Surname().setValue("Burns");
1175                nk12.getXpn2_GivenName().setValue("Charles");
1176                nk12.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Montgomery");
1177
1178                CE nk13 = theNk1.getNk13_Relationship();
1179                nk13.getCe1_Identifier().setValue("ECON");
1180                nk13.getCe2_Text().setValue("Employer");
1181                nk13.getCe3_NameOfCodingSystem().setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
1182
1183                XAD nk14 = theNk1.insertNk14_Address(0);
1184                nk14.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("999 Mammon Avenue");
1185                nk14.getXad3_City().setValue("Springfield");
1186                nk14.getXad4_StateOrProvince().setValue("MO");
1187                nk14.getXad5_ZipOrPostalCode().setValue("91656");
1188                nk14.getXad6_Country().setValue("USA");
1189                nk14.getXad7_AddressType().setValue("W");
1190
1191                XTN nk15 = theNk1.insertNk16_BusinessPhoneNumber(0);
1192                nk15.getXtn1_TelephoneNumber().setValue("(636)555-5678");
1193                nk15.getXtn2_TelecommunicationUseCode().setValue("WPN");
1194                nk15.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1195                nk15.getXtn6_AreaCityCode().setValue("636");
1196                nk15.getXtn7_LocalNumber().setValue("5555678");
1197
1198                CE nk17 = theNk1.getNk17_ContactRole();
1199                nk17.getCe1_Identifier().setValue("E");
1200                nk17.getCe2_Text().setValue("Employer");
1201                nk17.getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0131_R4);
1202
1203                theNk1.getNk115_AdministrativeSex().setValue("M");
1204
1205                XON nk113 = theNk1.insertOrganizationNameNK1(0);
1206                nk113.getXon1_OrganizationName().setValue("Springfield Nuclear Power Plant");
1207
1208                theNk1.getNk18_StartDate().setValue("201506");
1209
1210                CX nk133 = theNk1.insertNk133_NextOfKinAssociatedPartySIdentifiers(0);
1211                nk133.getCx1_IDNumber().setValue("0123456789");
1212                nk133.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/organization");
1213        }
1214
1215        public void populateNk1NextOfKin(NK1 theNk1) throws HL7Exception {
1216                theNk1.getNk11_SetIDNK1().setValue("1");
1217
1218                XPN nk12 = theNk1.insertNk12_NKName(0);
1219                nk12.getXpn1_FamilyName().getFn1_Surname().setValue("Simpson");
1220                nk12.getXpn2_GivenName().setValue("Marjorie");
1221                nk12.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Marge");
1222
1223                CE nk13 = theNk1.getNk13_Relationship();
1224                nk13.getCe1_Identifier().setValue("MTH");
1225                nk13.getCe2_Text().setValue("Mother");
1226                nk13.getCe3_NameOfCodingSystem().setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
1227
1228                XAD nk14 = theNk1.insertNk14_Address(0);
1229                nk14.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("742 Evergreen Terrace");
1230                nk14.getXad3_City().setValue("Springfield");
1231                nk14.getXad4_StateOrProvince().setValue("MO");
1232                nk14.getXad5_ZipOrPostalCode().setValue("65619");
1233                nk14.getXad6_Country().setValue("USA");
1234                nk14.getXad7_AddressType().setValue("H");
1235
1236                XTN nk15 = theNk1.insertNk15_PhoneNumber(0);
1237                nk15.getXtn1_TelephoneNumber().setValue("(636)555-1234");
1238                nk15.getXtn2_TelecommunicationUseCode().setValue("PRN");
1239                nk15.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1240                nk15.getXtn6_AreaCityCode().setValue("636");
1241                nk15.getXtn7_LocalNumber().setValue("5551234");
1242
1243                CE nk17 = theNk1.getNk17_ContactRole();
1244                nk17.getCe1_Identifier().setValue("N");
1245                nk17.getCe2_Text().setValue("Next-of-Kin");
1246                nk17.getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0131_R4);
1247
1248                theNk1.getNk18_StartDate().setValue("2011");
1249                theNk1.getNk19_EndDate().setValue("20120102");
1250
1251                theNk1.getNk110_NextOfKinAssociatedPartiesJobTitle().setValue("Clown");
1252                theNk1.getNk114_MaritalStatus().getCe1_Identifier().setValue("I");
1253
1254                theNk1.getNk115_AdministrativeSex().setValue("F");
1255                theNk1.getNk116_DateTimeOfBirth().parse("20210101121212-0000");
1256                theNk1.getNk129_ContactReason(0).parse("EMER^Emergency^http://contact-reasons");
1257                theNk1.getNk130_ContactPersonSName(0)
1258                        .getXpn1_FamilyName()
1259                        .getFn1_Surname()
1260                        .setValue("Alt Family Name");
1261
1262                theNk1.getNk113_OrganizationNameNK1(0).getXon1_OrganizationName().setValue("Org Name");
1263                theNk1.getNk133_NextOfKinAssociatedPartySIdentifiers(0)
1264                        .getCx1_IDNumber()
1265                        .setValue("12345");
1266                theNk1.getNk133_NextOfKinAssociatedPartySIdentifiers(0)
1267                        .getCx4_AssigningAuthority()
1268                        .getHd1_NamespaceID()
1269                        .setValue("http://ids");
1270        }
1271
1272        public void populateObxAssessmentHeight(Message theMessage, OBX theObx) throws DataTypeException {
1273                theObx.getObx2_ValueType().setValue("NM");
1274                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(PublicApiConstants.CODE_LOINC_BODY_HEIGHT);
1275                theObx.getObx3_ObservationIdentifier().getCe2_Text().setValue(PublicApiConstants.CODE_LOINC_BODY_HEIGHT_TEXT);
1276                theObx.getObx3_ObservationIdentifier().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_LOINC);
1277                NM obxHtNm = new NM(theMessage);
1278                obxHtNm.setValue("51");
1279                theObx.getObx5_ObservationValue(0).setData(obxHtNm);
1280                theObx.getObx6_Units().getCe1_Identifier().setValue("cm");
1281                theObx.getObx6_Units().getCe2_Text().setValue("cm");
1282                theObx.getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
1283                theObx.getObx11_ObservationResultStatus().setValue("F");
1284                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("201109031113-0400");
1285        }
1286
1287        public void populateObxAssessmentWeight(Message a01, OBX theObx) throws DataTypeException {
1288                theObx.getObx2_ValueType().setValue("NM");
1289                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(PublicApiConstants.CODE_LOINC_BODY_WEIGHT);
1290                theObx.getObx3_ObservationIdentifier().getCe2_Text().setValue(PublicApiConstants.CODE_LOINC_BODY_WEIGHT_TEXT);
1291                theObx.getObx3_ObservationIdentifier().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_LOINC);
1292                NM obxWtNm = new NM(a01);
1293                obxWtNm.setValue("123.4");
1294                theObx.getObx5_ObservationValue(0).setData(obxWtNm);
1295                theObx.getObx6_Units().getCe1_Identifier().setValue("kg");
1296                theObx.getObx6_Units().getCe2_Text().setValue("kg");
1297                theObx.getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
1298                theObx.getObx11_ObservationResultStatus().setValue("F");
1299                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("201109031113-0400");
1300        }
1301
1302        public void populateOrcForMedication(
1303                ORC theOrc, String theOrderControl, boolean thePopulateOrc2, boolean thePopulateOrc3) throws HL7Exception {
1304                theOrc.getOrc1_OrderControl().setValue(theOrderControl);
1305                if (thePopulateOrc2) {
1306                        theOrc.getOrc2_PlacerOrderNumber().getEi1_EntityIdentifier().setValue("0001");
1307                        theOrc.getOrc2_PlacerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/medorders");
1308                }
1309                if (thePopulateOrc3) {
1310                        theOrc.getOrc3_FillerOrderNumber().getEi1_EntityIdentifier().setValue("0002");
1311                        theOrc.getOrc3_FillerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/medorders");
1312                }
1313
1314                TQ orc7 = theOrc.insertOrc7_QuantityTiming(0);
1315                orc7.getTq4_StartDateTime().getTs1_Time().setValue("201701021110-0500");
1316
1317                theOrc.getOrc9_DateTimeOfTransaction().getTs1_Time().setValue("201701021110-0500");
1318
1319                XCN orc12 = theOrc.insertOrc12_OrderingProvider(0);
1320                populateXcn(orc12);
1321        }
1322
1323        public void populatePid(PID thePid) throws HL7Exception {
1324                populatePid(thePid, true);
1325        }
1326
1327        public void populatePid(PID thePid, boolean theValid) throws HL7Exception {
1328                CX pid3 = thePid.insertPid3_PatientIdentifierList(0);
1329                pid3.getCx1_IDNumber().setValue("7000135");
1330
1331                // If we're creating an invalid message, we'll skip all the mandatory bits of PID-3, since this is a
1332                // pretty common screwup
1333                if (theValid) {
1334                        pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/mrns");
1335                        pid3.getCx5_IdentifierTypeCode().setValue("MR");
1336                        pid3 = thePid.insertPid3_PatientIdentifierList(1);
1337                        pid3.getCx1_IDNumber().setValue("01238638267");
1338                        pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/secondaryIds");
1339                        pid3.getCx5_IdentifierTypeCode().setValue("SB");
1340                }
1341                XPN pid5 = thePid.insertPid5_PatientName(0);
1342                pid5.getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1343                pid5.getXpn2_GivenName().setValue("John");
1344                pid5.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Q");
1345                pid5.getXpn4_SuffixEgJRorIII().setValue("Jr");
1346                pid5.getXpn7_NameTypeCode().setValue("L");
1347
1348                XPN pid6 = thePid.insertPid6_MotherSMaidenName(0);
1349                pid6.getXpn1_FamilyName().getFn1_Surname().setValue("Smythe");
1350                pid6.getXpn2_GivenName().setValue("Jane");
1351                pid6.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("K");
1352                pid6.getXpn4_SuffixEgJRorIII().setValue("Sr");
1353                pid6.getXpn7_NameTypeCode().setValue("D");
1354
1355                thePid.getPid7_DateTimeOfBirth().getTs1_Time().setValue("19650322");
1356
1357                thePid.getPid8_AdministrativeSex().setValue("M");
1358
1359                CE pid10 = thePid.getPid10_Race(0);
1360                pid10.getCe1_Identifier().setValue("2028-9");
1361                pid10.getCe2_Text().setValue("Asian");
1362                pid10.getCe3_NameOfCodingSystem().setValue("urn:oid:2.16.840.1.113883.6.238");
1363                pid10.getExtraComponents()
1364                        .getComponent(0)
1365                        .getData()
1366                        .parse("http://hl7.org/fhir/us/core/StructureDefinition/us-core-race");
1367                pid10.getExtraComponents().getComponent(1).getData().parse("ombCategory");
1368
1369                XAD pid11 = thePid.insertPid11_PatientAddress(0);
1370                pid11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("342 Evergreen Terrace");
1371                pid11.getXad2_OtherDesignation().setValue("2nd Floor");
1372                pid11.getXad3_City().setValue("Springfield");
1373                pid11.getXad4_StateOrProvince().setValue("NI");
1374                pid11.getXad5_ZipOrPostalCode().setValue("12345");
1375                pid11.getXad6_Country().setValue("USA");
1376                pid11.getXad7_AddressType().setValue("H");
1377
1378                XTN pid13 = thePid.insertPid13_PhoneNumberHome(0);
1379                pid13.getXtn1_TelephoneNumber().setValue("1(333)555-1234");
1380                pid13.getXtn2_TelecommunicationUseCode().setValue("PRN");
1381                pid13.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1382
1383                thePid.getPid15_PrimaryLanguage().parse("EN^English^http://languages");
1384
1385                CE pid16 = thePid.getPid16_MaritalStatus();
1386                pid16.getCe1_Identifier().setValue("I");
1387
1388                CE pid17 = thePid.getPid17_Religion();
1389                pid17.getCe1_Identifier().setValue("AGNOSTIC");
1390                pid17.getCe2_Text().setValue("Agnostic");
1391                pid17.getCe3_NameOfCodingSystem().setValue("urn:test:source:religion");
1392                pid17.getExtraComponents()
1393                        .getComponent(0)
1394                        .getData()
1395                        .parse("http://hl7.org/fhir/StructureDefinition/patient-religion");
1396
1397                CX pid18 = thePid.getPid18_PatientAccountNumber();
1398                pid18.getCx1_IDNumber().setValue("123456789");
1399                pid18.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/patientAccountNumbers");
1400                pid18.getCx5_IdentifierTypeCode().setValue("AN");
1401
1402                CE pid22 = thePid.getPid22_EthnicGroup(0);
1403                pid22.getCe1_Identifier().setValue("2135-2");
1404                pid22.getCe2_Text().setValue("Hispanic or Latino");
1405                pid22.getCe3_NameOfCodingSystem().setValue("urn:oid:2.16.840.1.113883.6.238");
1406                pid22.getExtraComponents()
1407                        .getComponent(0)
1408                        .getData()
1409                        .parse("http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity");
1410                pid22.getExtraComponents().getComponent(1).getData().parse("ombCategory");
1411
1412                // Adding multiple PID-26
1413                CE pid26_1 = thePid.getPid26_Citizenship(0);
1414                pid26_1.getCe1_Identifier().setValue("1");
1415                pid26_1.getCe2_Text().setValue("CA");
1416                pid26_1.getCe3_NameOfCodingSystem().setValue("urn:test:source:citizenship");
1417                CE pid26_2 = thePid.getPid26_Citizenship(1);
1418                pid26_2.getCe1_Identifier().setValue("2");
1419                pid26_2.getCe2_Text().setValue("US");
1420                pid26_2.getCe3_NameOfCodingSystem().setValue("urn:test:source:citizenship");
1421
1422                CE pid27 = thePid.getPid27_VeteransMilitaryStatus();
1423                pid27.getCe1_Identifier().setValue("N");
1424                pid27.getCe2_Text().setValue("Not a Veteran");
1425                pid27.getCe3_NameOfCodingSystem().setValue("urn:test:source:vetstatus");
1426                pid27.getExtraComponents()
1427                        .getComponent(0)
1428                        .getData()
1429                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1430                pid27.getExtraComponents()
1431                        .getComponent(1)
1432                        .getData()
1433                        .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/vet-status");
1434
1435                CE pid28 = thePid.getPid28_Nationality();
1436                pid28.getCe1_Identifier().setValue("1");
1437                pid28.getCe2_Text().setValue("Canadian");
1438                pid28.getCe3_NameOfCodingSystem().setValue("urn:test:source:nationality");
1439
1440                thePid.getPid30_PatientDeathIndicator().setValue("N");
1441        }
1442
1443        private void populateMrg(MRG theMrg) throws HL7Exception {
1444                CX mrg1 = theMrg.insertPriorPatientIdentifierList(0);
1445                mrg1.getCx1_IDNumber().setValue("7000135");
1446                mrg1.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/mrns");
1447                mrg1.getCx5_IdentifierTypeCode().setValue("MR");
1448        }
1449
1450        public void populatePr1First(PR1 thePr1) throws DataTypeException {
1451                thePr1.getPr11_SetIDPR1().setValue("1");
1452                thePr1.getPr13_ProcedureCode().getCe1_Identifier().setValue("2W53XYZ");
1453                thePr1.getPr13_ProcedureCode().getCe2_Text().setValue("Removal of Other Device on Abdominal Wall");
1454                thePr1.getPr13_ProcedureCode()
1455                        .getCe3_NameOfCodingSystem()
1456                        .setValue(CodeSystemEnum.PCS.getCodeSystemUri(ourContext));
1457                thePr1.getPr14_ProcedureDescription().setValue("Face Transplant");
1458                thePr1.getPr15_ProcedureDateTime().getTs1_Time().setValue("20010101070000-0400");
1459                thePr1.getPr16_ProcedureFunctionalType().setValue("D");
1460                thePr1.getPr119_ProcedureIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
1461                thePr1.getPr119_ProcedureIdentifier().getEi2_NamespaceID().setValue("http://acme.org/procedure-identifiers");
1462        }
1463
1464        public void populatePr1Second(PR1 thePr1) throws DataTypeException {
1465                thePr1.getPr11_SetIDPR1().setValue("2");
1466                thePr1.getPr13_ProcedureCode().getCe1_Identifier().setValue("02HV33Z");
1467                thePr1.getPr13_ProcedureCode()
1468                        .getCe2_Text()
1469                        .setValue("Insertion of Infusion Device into Superior Vena Cava, Percutaneous Approach");
1470                thePr1.getPr13_ProcedureCode()
1471                        .getCe3_NameOfCodingSystem()
1472                        .setValue(CodeSystemEnum.PCS.getCodeSystemUri(ourContext));
1473                thePr1.getPr15_ProcedureDateTime().getTs1_Time().setValue("20010101070000-0400");
1474                thePr1.getPr119_ProcedureIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
1475                thePr1.getPr119_ProcedureIdentifier().getEi2_NamespaceID().setValue("http://acme.org/procedure-identifiers");
1476        }
1477
1478        public void populatePv1(PV1 thePv1) throws HL7Exception {
1479                thePv1.getPv12_PatientClass().setValue("I");
1480                thePv1.getPv13_AssignedPatientLocation().getPl1_PointOfCare().setValue("Acme Hospital");
1481                thePv1.getPv13_AssignedPatientLocation().getPl2_Room().setValue("3rd Floor Room 124");
1482                thePv1.getPv13_AssignedPatientLocation().getPl3_Bed().setValue("6");
1483                thePv1.getPv13_AssignedPatientLocation()
1484                        .getPl4_Facility()
1485                        .getHd1_NamespaceID()
1486                        .setValue("Acme Facility");
1487                thePv1.getPv13_AssignedPatientLocation().getPl9_LocationDescription().setValue("The Acme Hospital");
1488                thePv1.getPv13_AssignedPatientLocation()
1489                        .getPl10_ComprehensiveLocationIdentifier()
1490                        .getEi1_EntityIdentifier()
1491                        .setValue("Acme H");
1492                thePv1.getPv13_AssignedPatientLocation()
1493                        .getPl10_ComprehensiveLocationIdentifier()
1494                        .getEi2_NamespaceID()
1495                        .setValue("http://acme.org/wards");
1496                thePv1.getPv13_AssignedPatientLocation()
1497                        .getExtraComponents()
1498                        .getComponent(0)
1499                        .getData()
1500                        .parse("http://acme.org/facility");
1501                thePv1.getPv13_AssignedPatientLocation()
1502                        .getExtraComponents()
1503                        .getComponent(1)
1504                        .getData()
1505                        .parse("Room 124, 3rd Floor");
1506                thePv1.getPv13_AssignedPatientLocation()
1507                        .getExtraComponents()
1508                        .getComponent(2)
1509                        .getData()
1510                        .parse("124-3");
1511                thePv1.getPv13_AssignedPatientLocation()
1512                        .getExtraComponents()
1513                        .getComponent(3)
1514                        .getData()
1515                        .parse("http://acme.org/rooms");
1516                thePv1.getPv13_AssignedPatientLocation()
1517                        .getExtraComponents()
1518                        .getComponent(4)
1519                        .getData()
1520                        .parse("Bed 6");
1521                thePv1.getPv13_AssignedPatientLocation()
1522                        .getExtraComponents()
1523                        .getComponent(5)
1524                        .getData()
1525                        .parse("B 6");
1526                thePv1.getPv13_AssignedPatientLocation()
1527                        .getExtraComponents()
1528                        .getComponent(6)
1529                        .getData()
1530                        .parse("http://acme.org/beds");
1531                thePv1.getPv14_AdmissionType().setValue("E");
1532                thePv1.getPv115_AmbulatoryStatus(0).setValue("A1");
1533
1534                populateXcn(thePv1.getPv17_AttendingDoctor(0));
1535                thePv1.getPv110_HospitalService().setValue("1");
1536                addExtraComponent(thePv1.getPv110_HospitalService(), 0, "Adoption/Permanent Care Info/Support");
1537                addExtraComponent(
1538                        thePv1.getPv110_HospitalService(), 1, CodeSystemEnum.SERVICE_TYPE.getCodeSystemUri(ourContext));
1539
1540                thePv1.getPv114_AdmitSource().setValue("emd");
1541                thePv1.getPv114_AdmitSource()
1542                        .getExtraComponents()
1543                        .getComponent(0)
1544                        .getData()
1545                        .parse("From accident/emergency department");
1546                thePv1.getPv114_AdmitSource()
1547                        .getExtraComponents()
1548                        .getComponent(1)
1549                        .getData()
1550                        .parse(CodeSystemEnum.ADMIT_SOURCE.getCodeSystemUri(ourContext));
1551                thePv1.getPv110_HospitalService().setValue("1");
1552                thePv1.getPv118_PatientType().setValue("QQ");
1553                thePv1.getPv119_VisitNumber().getCx1_IDNumber().setValue("4736455");
1554                thePv1.getPv119_VisitNumber()
1555                        .getCx4_AssigningAuthority()
1556                        .getHd1_NamespaceID()
1557                        .setValue("http://acme.org/visitNumbers");
1558                thePv1.getPv119_VisitNumber().getCx5_IdentifierTypeCode().setValue("VN");
1559                thePv1.getPv120_FinancialClass(0).getFc1_FinancialClassCode().setValue("FC1");
1560                thePv1.getPv120_FinancialClass(0).getFc2_EffectiveDate().getTs1_Time().setValue("20210202121212-0000");
1561                thePv1.getPv124_ContractCode(0).setValue("CC1");
1562                thePv1.getPv136_DischargeDisposition().setValue("home");
1563                thePv1.getPv136_DischargeDisposition()
1564                        .getExtraComponents()
1565                        .getComponent(0)
1566                        .getData()
1567                        .parse("Home");
1568                thePv1.getPv136_DischargeDisposition()
1569                        .getExtraComponents()
1570                        .getComponent(1)
1571                        .getData()
1572                        .parse(CodeSystemEnum.DISCHARGE_DISPOSITION.getCodeSystemUri(ourContext));
1573                thePv1.getPv139_ServicingFacility().setValue("Acme Facility");
1574                thePv1.getPv139_ServicingFacility()
1575                        .getExtraComponents()
1576                        .getComponent(0)
1577                        .getData()
1578                        .parse("http://acme.org/facility");
1579                thePv1.getPv141_AccountStatus().setValue("active");
1580                thePv1.getPv144_AdmitDateTime().getTime().setValue("20160122094430-0400");
1581                thePv1.insertPv145_DischargeDateTime(0).getTime().setValue("20160122094431-0400");
1582        }
1583
1584        public void populatePv2(PV2 thePv2) throws HL7Exception {
1585                thePv2.getPv22_AccommodationCode().getCe1_Identifier().setValue("wheel");
1586                thePv2.getPv22_AccommodationCode().getCe2_Text().setValue("Wheelchair");
1587                thePv2.getPv22_AccommodationCode()
1588                        .getCe3_NameOfCodingSystem()
1589                        .setValue("http://terminology.hl7.org/CodeSystem/encounter-special-arrangements");
1590
1591                thePv2.getPv23_AdmitReason().getCe1_Identifier().setValue("109006");
1592                thePv2.getPv23_AdmitReason().getCe2_Text().setValue("Anxiety disorder of childhood OR adolescence");
1593                thePv2.getPv23_AdmitReason().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
1594
1595                thePv2.getPv24_TransferReason().getCe1_Identifier().setValue("TR");
1596                thePv2.getPv24_TransferReason().getCe2_Text().setValue("Transfer Reasons");
1597                thePv2.getPv24_TransferReason().getCe3_NameOfCodingSystem().setValue("http://transfer-reasons");
1598
1599                thePv2.getPv28_ExpectedAdmitDateTime().getTs1_Time().setValue("20210203040506-0200");
1600                thePv2.getPv29_ExpectedDischargeDateTime().getTs1_Time().setValue("20210605040302-0200");
1601
1602                thePv2.getPv226_PreviousTreatmentDate().setValue("20190203");
1603                thePv2.getPv227_ExpectedDischargeDisposition().parse("DD^Discharge Disposition^http://discharge-dispositions");
1604        }
1605
1606        public void populateRolA(ROL theRol) throws HL7Exception {
1607                populateXcn(theRol.getRol4_RolePerson(0));
1608
1609                XAD rol11 = theRol.insertRol11_OfficeHomeAddressBirthplace(0);
1610                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("123 Brewer Street");
1611                rol11.getXad3_City().setValue("Buffalo");
1612                rol11.getXad4_StateOrProvince().setValue("NY");
1613                rol11.getXad5_ZipOrPostalCode().setValue("98765");
1614                rol11.getXad6_Country().setValue("USA");
1615                rol11.getXad7_AddressType().setValue("W");
1616
1617                XTN rol12 = theRol.insertRol12_Phone(0);
1618                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-1978");
1619                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1620                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1621        }
1622
1623        public void populateRolB(ROL rol2) throws HL7Exception {
1624                rol2.getRol3_RoleROL().getCe1_Identifier().setValue("ADM");
1625                rol2.getRol3_RoleROL().getCe2_Text().setValue("admitter");
1626                rol2.getRol3_RoleROL().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.PARTICIPANTTYPE_URI);
1627                rol2.getRol4_RolePerson(0).getXcn1_IDNumber().setValue("3622");
1628                rol2.getRol4_RolePerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("Hawkins");
1629                rol2.getRol4_RolePerson(0).getXcn3_GivenName().setValue("Finnie");
1630                rol2.getRol4_RolePerson(0)
1631                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1632                        .setValue("Winnie Pooh");
1633                rol2.getRol4_RolePerson(0)
1634                        .getXcn9_AssigningAuthority()
1635                        .getHd1_NamespaceID()
1636                        .setValue("http://acme.org/clinicians");
1637                XAD rol11 = rol2.insertRol11_OfficeHomeAddressBirthplace(0);
1638                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("20 Canal St");
1639                rol11.getXad3_City().setValue("Buffalo");
1640                rol11.getXad4_StateOrProvince().setValue("NY");
1641                rol11.getXad5_ZipOrPostalCode().setValue("98222");
1642                rol11.getXad6_Country().setValue("USA");
1643                rol11.getXad7_AddressType().setValue("W");
1644
1645                XTN rol12 = rol2.insertRol12_Phone(0);
1646                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-2133");
1647                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1648                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1649        }
1650
1651        public void populateRolC(ROL rol3) throws HL7Exception {
1652                XAD rol11;
1653                XTN rol12;
1654                rol3.getRol3_RoleROL().getCe1_Identifier().setValue("ATND");
1655                rol3.getRol3_RoleROL().getCe2_Text().setValue("attender");
1656                rol3.getRol3_RoleROL().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.PARTICIPANTTYPE_URI);
1657                rol3.getRol4_RolePerson(0).getXcn1_IDNumber().setValue("7452");
1658                rol3.getRol4_RolePerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("May");
1659                rol3.getRol4_RolePerson(0).getXcn3_GivenName().setValue("Sadie");
1660                rol3.getRol4_RolePerson(0)
1661                        .getXcn9_AssigningAuthority()
1662                        .getHd1_NamespaceID()
1663                        .setValue("http://acme.org/clinicians");
1664
1665                rol11 = rol3.insertRol11_OfficeHomeAddressBirthplace(0);
1666                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("313 Fleet Street");
1667                rol11.getXad3_City().setValue("Cheektowaga");
1668                rol11.getXad4_StateOrProvince().setValue("NY");
1669                rol11.getXad5_ZipOrPostalCode().setValue("28366");
1670                rol11.getXad6_Country().setValue("USA");
1671                rol11.getXad7_AddressType().setValue("W");
1672
1673                rol12 = rol3.insertRol12_Phone(0);
1674                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-6624");
1675                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1676                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1677        }
1678
1679        public void populateRxe(RXE theRxe) throws HL7Exception {
1680                theRxe.getRxe1_QuantityTiming().parse("^2 times daily&0900,1800^^20160205101500-0400^20160714165258-0400^R^^");
1681                theRxe.getRxe2_GiveCode()
1682                        .parse("02713^morphine injection 2 mg^http://acme.org/drugs^^^^^^Mighty Morphine Powder Dangers");
1683                theRxe.getRxe3_GiveAmountMinimum().setValue("0.5");
1684                theRxe.getRxe4_GiveAmountMaximum().setValue("2");
1685                theRxe.getRxe5_GiveUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1686                theRxe.getRxe7_ProviderSAdministrationInstructions(0).parse("^Take with Food");
1687                theRxe.getRxe7_ProviderSAdministrationInstructions(1).parse("^Take at Night");
1688                theRxe.getRxe10_DispenseAmount().setValue("1.2");
1689                theRxe.getRxe11_DispenseUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1690                theRxe.getRxe23_GiveRateAmount().setValue("1.0");
1691                theRxe.getRxe24_GiveRateUnits().parse("mL/h^milliliter per hour^http://unitsofmeasure.org");
1692        }
1693
1694        public void populateRxr(RXR theRxr) throws HL7Exception {
1695                theRxr.getRxr1_Route().parse("6064005^Topical^http://snomed.info/sct");
1696                theRxr.getRxr2_AdministrationSite().parse("69536005^Head^http://snomed.info/sct");
1697        }
1698
1699        public void populateSch(SCH theSch) throws HL7Exception {
1700
1701                theSch.getSch1_PlacerAppointmentID().getEi1_EntityIdentifier().parse("1234");
1702                theSch.getSch1_PlacerAppointmentID().getEi2_NamespaceID().parse("http://acme.org/placer/321");
1703
1704                theSch.getSch2_FillerAppointmentID().getEi1_EntityIdentifier().parse("1235");
1705                theSch.getSch2_FillerAppointmentID().getEi2_NamespaceID().parse("http://acme.org/placer/322");
1706
1707                theSch.getSch3_OccurrenceNumber().setValue("1");
1708
1709                theSch.getSch6_EventReason().getCe1_Identifier().parse("22");
1710                theSch.getSch6_EventReason().getCe2_Text().parse("Hypnotherapy"); // Maps to "Hypnotherapy"
1711                // ^ User-defined table in v2 but specific serviceType in FHIR
1712
1713                theSch.getSch7_AppointmentReason().getCe1_Identifier().parse("ROUTINE");
1714                // ^ User-defined table in v2 but specific reasonCode in FHIR
1715
1716                theSch.getSch9_AppointmentDuration().setValue("30");
1717                theSch.getSch10_AppointmentDurationUnits().getCe1_Identifier().setValue("minutes");
1718                theSch.getSch11_AppointmentTimingQuantity(0)
1719                        .getTq4_StartDateTime()
1720                        .getTs1_Time()
1721                        .setValue("202104141300-0500");
1722                theSch.getSch11_AppointmentTimingQuantity(0)
1723                        .getTq5_EndDateTime()
1724                        .getTs1_Time()
1725                        .setValue("202104141330-0500");
1726
1727                // SCH-16
1728                theSch.getSch16_FillerContactPerson(0).getXcn1_IDNumber().setValue("2345");
1729                theSch.getSch16_FillerContactPerson(0)
1730                        .getXcn2_FamilyName()
1731                        .getFn1_Surname()
1732                        .setValue("Smith");
1733                theSch.getSch16_FillerContactPerson(0).getXcn3_GivenName().setValue("Jane");
1734                theSch.getSch16_FillerContactPerson(0)
1735                        .getXcn9_AssigningAuthority()
1736                        .getHd1_NamespaceID()
1737                        .setValue("http://acme.org");
1738
1739                theSch.getSch20_EnteredByPerson(0).getXcn1_IDNumber().setValue("3456");
1740                theSch.getSch20_EnteredByPerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("Coltrane");
1741                theSch.getSch20_EnteredByPerson(0).getXcn3_GivenName().setValue("John");
1742                theSch.getSch20_EnteredByPerson(0)
1743                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1744                        .setValue("William");
1745                theSch.getSch20_EnteredByPerson(0)
1746                        .getXcn9_AssigningAuthority()
1747                        .getHd1_NamespaceID()
1748                        .setValue("http://acme.org");
1749
1750                theSch.getSch25_FillerStatusCode().getCe1_Identifier().setValue("Booked");
1751                // ^ status (appointmentStatus) table in FHIR
1752        }
1753
1754        public void populateZxt(AbstractMessage theMsg) throws HL7Exception {
1755                /*
1756                 * Extensions on Patient
1757                 */
1758                // Patient.active with boolean
1759                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT"))).parse("ZXT||ST|true|Patient.active");
1760                // Patient.multipleBirthInteger with numeric
1761                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1762                        .parse("ZXT||NM|3|Patient.multipleBirthInteger");
1763                // Patient.extension with valueString
1764                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1765                        .parse("ZXT||ST|Golly!|Patient.extension('http://acme.org/extension1').valueString");
1766                // Patient.extension with nested extension with valueString
1767                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1768                        .parse(
1769                                "ZXT||ST|Gee!|Patient.extension('http://acme.org/extension2').extension('http://acme.org/nestedExtension1').valueString");
1770                // Patient.extension with multiple nested extensions with valueString
1771                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1772                        .parse(
1773                                "ZXT||ST|Whiz!|Patient.extension('http://acme.org/extension3').extension('http://acme.org/nestedExtension2').extension('http://acme.org/nestedExtension3').valueString");
1774
1775                /*
1776                 * Extensions on Encounter
1777                 */
1778                // Encounter.extension with valueString
1779                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1780                        .parse("ZXT||ST|Aces!|Encounter.extension('http://acme.org/extension4').valueString");
1781                // Encounter.class.extension with valueString
1782                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1783                        .parse(
1784                                "ZXT||ST|Well, isn't that super?|Encounter.class.extension('http://acme.org/extension5').valueString");
1785                // Encounter.extension with valueCoding
1786                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1787                        .parse(
1788                                "ZXT||CWE|CODE^This is a code.^http://acme.org/codes|Encounter.extension('http://acme.org/extension6').valueCoding");
1789                // Encounter.extension with valueCodeableConcept, 1st code
1790                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1791                        .parse(
1792                                "ZXT||CWE|CODE1^This is a code1.^http://acme.org/codes|Encounter.extension('http://acme.org/extension7').valueCodeableConcept");
1793                // Encounter.extension with valueCodeableConcept, 2nd code
1794                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1795                        .parse(
1796                                "ZXT||CWE|CODE2^This is a code2.^http://acme.org/codes|Encounter.extension('http://acme.org/extension7').valueCodeableConcept");
1797                // Encounter.extension with valueInteger
1798                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1799                        .parse("ZXT||NM|3|Encounter.extension('http://acme.org/extension8').valueInteger");
1800                // Encounter.extension with valueDecimal
1801                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1802                        .parse("ZXT||NM|3.3|Encounter.extension('http://acme.org/extension9').valueDecimal");
1803        }
1804
1805        public RAS_O17 createRasO17() throws HL7Exception {
1806                return createRasO17(false);
1807        }
1808
1809        public RAS_O17 createRasO17(boolean hasMultipleComponents) throws HL7Exception {
1810                return createRasO17(hasMultipleComponents, true, true, false);
1811        }
1812
1813        public RAS_O17 createRasO17(boolean hasMultipleComponents, boolean bothComponentsAreCoded) throws HL7Exception {
1814                return createRasO17(hasMultipleComponents, bothComponentsAreCoded, true, false);
1815        }
1816
1817        public RAS_O17 createRasO17(
1818                boolean hasMultipleComponents,
1819                boolean bothComponentsAreCoded,
1820                boolean thePopulateOrc2,
1821                boolean thePopulateOrc3)
1822                throws HL7Exception {
1823                RAS_O17 ras = new RAS_O17();
1824                populateMsh(ras.getMSH(), "RAS^O17^RAS_O17");
1825                populatePid(ras.getPATIENT().getPID(), true);
1826                populatePv1(ras.getPATIENT().getPATIENT_VISIT().getPV1());
1827
1828                RAS_O17_ORDER order = ras.insertORDER(0);
1829                ORC orc = order.getORC();
1830                populateOrcForMedication(orc, "NW", thePopulateOrc2, thePopulateOrc3);
1831
1832                populateRxe(ras.getORDER().getENCODING().getRXE());
1833                populateRxr(ras.getORDER().getENCODING().getRXR());
1834
1835                RXC rxc = ras.getORDER().getENCODING().insertRXC(0);
1836                rxc.getRxc1_RXComponentType().setValue("A");
1837                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("MEW");
1838                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Kittens");
1839                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/cats");
1840                rxc.getRxc3_ComponentAmount().setValue("0.5");
1841                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1842
1843                if (hasMultipleComponents) {
1844                        if (bothComponentsAreCoded) {
1845                                rxc = ras.getORDER().getENCODING().insertRXC(1);
1846                                rxc.getRxc1_RXComponentType().setValue("B");
1847                                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("WAF");
1848                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Puppies");
1849                                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/dogs");
1850                                rxc.getRxc3_ComponentAmount().setValue("0.3");
1851                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1852                        } else {
1853                                rxc = ras.getORDER().getENCODING().insertRXC(1);
1854                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Duckies");
1855                                rxc.getRxc3_ComponentAmount().setValue("0.2");
1856                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1857                        }
1858                }
1859
1860                RAS_O17_ADMINISTRATION admin = ras.getORDER().getADMINISTRATION();
1861
1862                RXA rxa = admin.insertRXA(0);
1863                rxa.getRxa2_AdministrationSubIDCounter().setValue("1");
1864                rxa.getRxa2_AdministrationSubIDCounter()
1865                        .getExtraComponents()
1866                        .getComponent(0)
1867                        .getData()
1868                        .parse("http://acme.org/medadmins");
1869                rxa.getRxa3_DateTimeStartOfAdministration().getTs1_Time().setValue("20171209071055-0500");
1870                rxa.getRxa4_DateTimeEndOfAdministration().getTs1_Time().setValue("20171209071100-0500");
1871                rxa.getRxa5_AdministeredCode().getCe1_Identifier().setValue("0001");
1872                rxa.getRxa5_AdministeredCode().getCe2_Text().setValue("Tylenol");
1873                rxa.getRxa5_AdministeredCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/meds");
1874                rxa.getRxa6_AdministeredAmount().setValue("4");
1875                rxa.getRxa7_AdministeredUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1876                rxa.getRxa9_AdministrationNotes(0).getCe2_Text().setValue("This is a note");
1877
1878                rxa.getRxa10_AdministeringProvider(0).getXcn1_IDNumber().setValue("825");
1879                rxa.getRxa10_AdministeringProvider(0)
1880                        .getXcn2_FamilyName()
1881                        .getFn1_Surname()
1882                        .setValue("Bouvier");
1883                rxa.getRxa10_AdministeringProvider(0).getXcn3_GivenName().setValue("Marge");
1884                rxa.getRxa10_AdministeringProvider(0)
1885                        .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1886                        .setValue("Q");
1887                rxa.getRxa10_AdministeringProvider(0)
1888                        .getXcn9_AssigningAuthority()
1889                        .getHd1_NamespaceID()
1890                        .setValue("http://acme.org/clinicians");
1891
1892                rxa.getRxa12_AdministeredPerTimeUnit().setValue("Day");
1893                rxa.getRxa20_CompletionStatus().setValue("CP");
1894
1895                populateRxr(admin.getRXR());
1896
1897                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1898                        .parse("ZXC|A|MEW^Kittens^http://acme.org/cats|0.5|mg^milligrams^http://unitsofmeasure.org");
1899
1900                if (hasMultipleComponents) {
1901                        if (bothComponentsAreCoded) {
1902                                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1903                                        .parse("ZXC|B|WAF^Puppies^http://acme.org/dogs|0.3|mg^milligrams^http://unitsofmeasure.org");
1904                        } else {
1905                                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1906                                        .parse("ZXC||^Duckies|0.2|mg^milligrams^http://unitsofmeasure.org");
1907                        }
1908                }
1909
1910                return ras;
1911        }
1912
1913        public QBP_Q21 createQbpQ21() throws HL7Exception {
1914                QBP_Q21 qbp = new QBP_Q21();
1915                populateMsh(qbp.getMSH(), "QBP^Q23^QBP");
1916                populateQpd(qbp.getQPD());
1917                qbp.getRCP().getRcp1_QueryPriority().setValue("I");
1918                return qbp;
1919        }
1920
1921        private void populateQpd(QPD theQpd) throws HL7Exception {
1922                // QPD-1: Message Query Name
1923                theQpd.getQpd1_MessageQueryName().getCe1_Identifier().setValue("IHE PIX Query");
1924
1925                // QPD-2: Query Tag
1926                theQpd.getQpd2_QueryTag().setValue("QRY1248968460880");
1927
1928                // QPD-3: Patient Identifier
1929                theQpd.getQpd3_UserParametersInsuccessivefields().parse("PD12345^^^PIF&1.2.840.114158.2012.11.01.1&ISO");
1930        }
1931
1932        public void populateXcn(XCN theXCN) throws DataTypeException {
1933                theXCN.getXcn1_IDNumber().setValue("777");
1934                theXCN.getXcn2_FamilyName().getFn1_Surname().setValue("Jones");
1935                theXCN.getXcn3_GivenName().setValue("Lisa");
1936                theXCN.getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Frances Little Piglet");
1937                theXCN.getXcn5_SuffixEgJRorIII().setValue("Jr");
1938                theXCN.getXcn6_PrefixEgDR().setValue("DR");
1939                theXCN.getXcn7_DegreeEgMD().setValue("MD");
1940                theXCN.getXcn9_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/clinicians");
1941        }
1942}