1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.transform.subdisc;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
8 | import java.util.List;
|
---|
9 | import javax.xml.bind.JAXBElement;
|
---|
10 | import org.hl7.v3.CE;
|
---|
11 | import org.hl7.v3.II;
|
---|
12 | import org.hl7.v3.IVLTSExplicit;
|
---|
13 | import org.hl7.v3.PNExplicit;
|
---|
14 | import org.hl7.v3.PRPAMT201301UVPatient;
|
---|
15 | import org.hl7.v3.PRPAMT201301UVPerson;
|
---|
16 | import org.hl7.v3.PRPAMT201306UVLivingSubjectAdministrativeGender;
|
---|
17 | import org.hl7.v3.PRPAMT201306UVLivingSubjectBirthTime;
|
---|
18 | import org.hl7.v3.PRPAMT201306UVLivingSubjectId;
|
---|
19 | import org.hl7.v3.PRPAMT201306UVLivingSubjectName;
|
---|
20 | import org.hl7.v3.PRPAMT201306UVParameterList;
|
---|
21 | import org.hl7.v3.PRPAMT201306UVQueryByParameter;
|
---|
22 | import org.hl7.v3.ST;
|
---|
23 | import org.hl7.v3.TEL;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | *
|
---|
27 | * @author Jon Hoppesch
|
---|
28 | */
|
---|
29 | public class HL7QueryParamsTransforms {
|
---|
30 |
|
---|
31 | public static JAXBElement<PRPAMT201306UVQueryByParameter> createQueryParams(PRPAMT201301UVPatient patient, String localDeviceId) {
|
---|
32 | PRPAMT201306UVQueryByParameter params = new PRPAMT201306UVQueryByParameter();
|
---|
33 |
|
---|
34 | params.setQueryId(HL7MessageIdGenerator.GenerateHL7MessageId(localDeviceId));
|
---|
35 | params.setStatusCode(HL7DataTransformHelper.CSFactory("new"));
|
---|
36 |
|
---|
37 | params.setParameterList(createParamList(patient));
|
---|
38 |
|
---|
39 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "queryByParameter");
|
---|
40 | JAXBElement<PRPAMT201306UVQueryByParameter> queryParams = new JAXBElement<PRPAMT201306UVQueryByParameter>(xmlqname, PRPAMT201306UVQueryByParameter.class, params);
|
---|
41 |
|
---|
42 | return queryParams;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public static PRPAMT201306UVParameterList createParamList(PRPAMT201301UVPatient patient) {
|
---|
46 | PRPAMT201306UVParameterList paramList = new PRPAMT201306UVParameterList();
|
---|
47 | JAXBElement<PRPAMT201301UVPerson> jaxbPerson = patient.getPatientPerson();
|
---|
48 | PRPAMT201301UVPerson person = jaxbPerson.getValue();
|
---|
49 |
|
---|
50 | // Set the Subject Gender Code
|
---|
51 | if (person.getAdministrativeGenderCode() != null &&
|
---|
52 | NullChecker.isNotNullish(person.getAdministrativeGenderCode().getCode())) {
|
---|
53 | paramList.getLivingSubjectAdministrativeGender().add(createGender(person.getAdministrativeGenderCode().getCode()));
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Set the Subject Birth Time
|
---|
57 | if (person.getBirthTime() != null &&
|
---|
58 | NullChecker.isNotNullish(person.getBirthTime().getValue())) {
|
---|
59 | paramList.getLivingSubjectBirthTime().add(createBirthTime(person.getBirthTime().getValue()));
|
---|
60 | }
|
---|
61 |
|
---|
62 | // Set the Subject Name
|
---|
63 | if (person.getName() != null &&
|
---|
64 | person.getName().size() > 0) {
|
---|
65 | paramList.getLivingSubjectName().add(createName(person.getName()));
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Set the subject Id
|
---|
69 | if (patient != null &&
|
---|
70 | patient.getId() != null &&
|
---|
71 | patient.getId().size() > 0 &&
|
---|
72 | patient.getId().get(0) != null) {
|
---|
73 | paramList.getLivingSubjectId().add(createSubjectId(patient.getId().get(0)));
|
---|
74 | }
|
---|
75 |
|
---|
76 | return paramList;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public static PRPAMT201306UVLivingSubjectId createSubjectId(II subjectId) {
|
---|
80 | PRPAMT201306UVLivingSubjectId id = new PRPAMT201306UVLivingSubjectId();
|
---|
81 |
|
---|
82 | if (subjectId != null) {
|
---|
83 | id.getValue().add(subjectId);
|
---|
84 | ST text = new ST();
|
---|
85 | id.setSemanticsText(text);
|
---|
86 | }
|
---|
87 |
|
---|
88 | return id;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public static PRPAMT201306UVLivingSubjectName createName(List<PNExplicit> patientNames) {
|
---|
92 | if (patientNames.size() == 0) {
|
---|
93 | return null;
|
---|
94 | }
|
---|
95 |
|
---|
96 | PRPAMT201306UVLivingSubjectName subjectName = new PRPAMT201306UVLivingSubjectName();
|
---|
97 |
|
---|
98 | for (PNExplicit name : patientNames) {
|
---|
99 | subjectName.getValue().add(HL7DataTransformHelper.ConvertPNToEN(name));
|
---|
100 | ST text = new ST();
|
---|
101 | subjectName.setSemanticsText(text);
|
---|
102 | }
|
---|
103 |
|
---|
104 | return subjectName;
|
---|
105 | }
|
---|
106 |
|
---|
107 | public static PRPAMT201306UVLivingSubjectBirthTime createBirthTime(String birthTime) {
|
---|
108 | PRPAMT201306UVLivingSubjectBirthTime subjectBirthTime = new PRPAMT201306UVLivingSubjectBirthTime();
|
---|
109 | IVLTSExplicit bday = new IVLTSExplicit();
|
---|
110 |
|
---|
111 | if (birthTime != null &&
|
---|
112 | birthTime.length() > 0) {
|
---|
113 | bday.setValue(birthTime);
|
---|
114 | subjectBirthTime.getValue().add(bday);
|
---|
115 | ST text = new ST();
|
---|
116 | subjectBirthTime.setSemanticsText(text);
|
---|
117 | }
|
---|
118 |
|
---|
119 | return subjectBirthTime;
|
---|
120 | }
|
---|
121 |
|
---|
122 | public static PRPAMT201306UVLivingSubjectAdministrativeGender createGender(String gender) {
|
---|
123 | PRPAMT201306UVLivingSubjectAdministrativeGender adminGender = new PRPAMT201306UVLivingSubjectAdministrativeGender();
|
---|
124 | CE genderCode = new CE();
|
---|
125 |
|
---|
126 | if (gender != null &&
|
---|
127 | gender.length() > 0) {
|
---|
128 | genderCode.setCode(gender);
|
---|
129 | adminGender.getValue().add(genderCode);
|
---|
130 |
|
---|
131 | ST text = new ST();
|
---|
132 | adminGender.setSemanticsText(text);
|
---|
133 | }
|
---|
134 |
|
---|
135 | return adminGender;
|
---|
136 | }
|
---|
137 | }
|
---|