1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 |
|
---|
6 | package gov.hhs.fha.nhinc.adaptermpimanager.HL7Parsers;
|
---|
7 |
|
---|
8 | import gov.hhs.fha.nhinc.mpilib.*;
|
---|
9 | import java.util.List;
|
---|
10 | import java.io.Serializable;
|
---|
11 | import java.util.Iterator;
|
---|
12 | import javax.xml.bind.JAXBElement;
|
---|
13 | import org.apache.commons.logging.Log;
|
---|
14 | import org.apache.commons.logging.LogFactory;
|
---|
15 | import org.hl7.v3.*;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | *
|
---|
19 | * @author jhoppesc
|
---|
20 | */
|
---|
21 | public class HL7Parser201303 {
|
---|
22 | private static Log log = LogFactory.getLog(HL7Parser201303.class);
|
---|
23 | public static void PrintMessageIdFromMessage(org.hl7.v3.PRPAIN201303UV message) {
|
---|
24 | if (!(message == null)) {
|
---|
25 | HL7Parser.PrintId(message.getId(), "message");
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static PRPAMT201305UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201303UV message) {
|
---|
30 | //assume one subject for now
|
---|
31 | PRPAMT201305UVPatient patient = null;
|
---|
32 | log.info("in ExtractPatient");
|
---|
33 |
|
---|
34 | if (message != null &&
|
---|
35 | message.getControlActProcess() != null &&
|
---|
36 | message.getControlActProcess().getSubject() != null &&
|
---|
37 | message.getControlActProcess().getSubject().size() > 0) {
|
---|
38 | List<PRPAIN201303UVMFMIMT700701UV01Subject1> subjects = message.getControlActProcess().getSubject();
|
---|
39 |
|
---|
40 | //for now, assume we only need one subject, this will need to be modified later
|
---|
41 | PRPAIN201303UVMFMIMT700701UV01Subject1 subject = subjects.get(0);
|
---|
42 |
|
---|
43 | patient = subject.getRegistrationEvent().getSubject1().getPatient();
|
---|
44 | } else {
|
---|
45 | log.info("no message.controlactprocess.subjects");
|
---|
46 | }
|
---|
47 |
|
---|
48 | log.info("done with ExtractPatient");
|
---|
49 | return patient;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public static String ExtractGender(PRPAMT201305UVPerson person) {
|
---|
53 | String genderCode = null;
|
---|
54 | CE administrativeGenderCode = person.getAdministrativeGenderCode();
|
---|
55 | if (administrativeGenderCode == null) {
|
---|
56 | log.info("message does not contain a gender code");
|
---|
57 | } else {
|
---|
58 | log.info("person.getAdministrativeGenderCode().getCode()=" + person.getAdministrativeGenderCode().getCode());
|
---|
59 | log.info("person.getAdministrativeGenderCode().getDisplayName()=" + person.getAdministrativeGenderCode().getDisplayName());
|
---|
60 | genderCode = person.getAdministrativeGenderCode().getCode();
|
---|
61 | }
|
---|
62 | return genderCode;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public static String ExtractBirthdate(PRPAMT201305UVPerson person) {
|
---|
66 | String birthDate = person.getBirthTime().getValue();
|
---|
67 | if (birthDate == null) {
|
---|
68 | log.info("message does not contain a birthtime");
|
---|
69 | } else {
|
---|
70 | log.info("person.getBirthTime().getValue()=" + birthDate);
|
---|
71 | }
|
---|
72 | return birthDate;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public static PersonName ExtractPersonName(PRPAMT201305UVPerson person) {
|
---|
76 | //temp logic to prove i can get to name - long term would want to store discrete name parts
|
---|
77 | //also assume one name, not multiple names
|
---|
78 | PersonName personname = new PersonName();
|
---|
79 |
|
---|
80 | log.info("patientPerson.getName().size() " + person.getName().size());
|
---|
81 | if (person.getName() != null &&
|
---|
82 | person.getName().size() > 0 &&
|
---|
83 | person.getName().get(0) != null &&
|
---|
84 | person.getName().get(0).getContent() != null) {
|
---|
85 |
|
---|
86 | List<Serializable> choice = person.getName().get(0).getContent();
|
---|
87 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
88 |
|
---|
89 | String nameString = null;
|
---|
90 | EnExplicitFamily lastname = new EnExplicitFamily();
|
---|
91 | EnExplicitGiven firstname = new EnExplicitGiven();
|
---|
92 |
|
---|
93 | while (iterSerialObjects.hasNext()) {
|
---|
94 | Serializable contentItem = iterSerialObjects.next();
|
---|
95 |
|
---|
96 | if (contentItem instanceof String) {
|
---|
97 | String strValue = (String) contentItem;
|
---|
98 |
|
---|
99 | if (nameString != null) {
|
---|
100 | nameString += strValue;
|
---|
101 | } else {
|
---|
102 | nameString = strValue;
|
---|
103 | }
|
---|
104 | } else if (contentItem instanceof JAXBElement) {
|
---|
105 | JAXBElement oJAXBElement = (JAXBElement) contentItem;
|
---|
106 |
|
---|
107 | if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
|
---|
108 | lastname = (EnExplicitFamily) oJAXBElement.getValue();
|
---|
109 | } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
|
---|
110 | firstname = (EnExplicitGiven) oJAXBElement.getValue();
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | // If text string in patient name, then set in name
|
---|
116 | // else set in element.
|
---|
117 | if (nameString != null) {
|
---|
118 | personname.setLastName(nameString);
|
---|
119 | } else {
|
---|
120 | if (lastname.getContent() != null &&
|
---|
121 | lastname.getContent().length() > 0) {
|
---|
122 | personname.setLastName(lastname.getContent());
|
---|
123 | log.info("FamilyName : " + personname.getLastName());
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (firstname.getContent() != null &&
|
---|
127 | firstname.getContent().length() > 0) {
|
---|
128 | personname.setFirstName(firstname.getContent());
|
---|
129 | log.info("GivenName : " + personname.getFirstName());
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | return personname;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public static Identifiers ExtractPersonIdentifiers(PRPAMT201305UVPatient patient) {
|
---|
138 | Identifiers ids = new Identifiers();
|
---|
139 | for (II patientid : patient.getId()) {
|
---|
140 | Identifier id = new Identifier();
|
---|
141 | id.setId(patientid.getExtension());
|
---|
142 | id.setOrganizationId(patientid.getRoot());
|
---|
143 | log.info("Created id from patient identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
|
---|
144 | ids.add(id);
|
---|
145 | }
|
---|
146 |
|
---|
147 | PRPAMT201305UVPerson person = ExtractHL7PatientPersonFromHL7Patient(patient);
|
---|
148 | for (II personid : person.getId()) {
|
---|
149 | Identifier id = new Identifier();
|
---|
150 | id.setId(personid.getExtension());
|
---|
151 | id.setOrganizationId(personid.getRoot());
|
---|
152 | log.info("Created id from person identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
|
---|
153 | ids.add(id);
|
---|
154 | }
|
---|
155 |
|
---|
156 | return ids;
|
---|
157 | }
|
---|
158 |
|
---|
159 | public static PRPAMT201305UVPerson ExtractHL7PatientPersonFromHL7Patient(PRPAMT201305UVPatient patient) {
|
---|
160 | JAXBElement<PRPAMT201305UVPerson> patientPersonElement = patient.getPatientPerson();
|
---|
161 | PRPAMT201305UVPerson patientPerson = patientPerson = patientPersonElement.getValue();
|
---|
162 | return patientPerson;
|
---|
163 | }
|
---|
164 |
|
---|
165 | public static Patient ExtractMpiPatientFromHL7Patient(PRPAMT201305UVPatient patient) {
|
---|
166 | PRPAMT201305UVPerson patientPerson = ExtractHL7PatientPersonFromHL7Patient(patient);
|
---|
167 | Patient mpiPatient = new Patient();
|
---|
168 | mpiPatient.setName(ExtractPersonName(patientPerson));
|
---|
169 | mpiPatient.setGender(ExtractGender(patientPerson));
|
---|
170 | mpiPatient.setDateOfBirth(ExtractBirthdate(patientPerson));
|
---|
171 |
|
---|
172 | Identifiers ids = ExtractPersonIdentifiers(patient);
|
---|
173 | mpiPatient.setIdentifiers(ids);
|
---|
174 | return mpiPatient;
|
---|
175 | }
|
---|
176 | }
|
---|