/
openmrs_v3.patch
4264 lines (4241 loc) · 161 KB
/
openmrs_v3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Index: .settings/org.eclipse.m2e.core.prefs
===================================================================
--- .settings/org.eclipse.m2e.core.prefs (revision 0)
+++ .settings/org.eclipse.m2e.core.prefs (revision 0)
@@ -0,0 +1,5 @@
+#Sat Oct 29 20:14:22 EDT 2011
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=false
+version=1
Index: .settings/org.eclipse.core.resources.prefs
===================================================================
--- .settings/org.eclipse.core.resources.prefs (revision 24091)
+++ .settings/org.eclipse.core.resources.prefs (working copy)
@@ -1,4 +1,4 @@
-#Tue Jan 25 11:03:23 EST 2011
+#Tue Oct 25 02:57:34 EDT 2011
eclipse.preferences.version=1
encoding//web/WEB-INF/messages_es.properties=UTF-8
encoding//web/WEB-INF/messages_fr.properties=UTF-8
@@ -15,3 +15,4 @@
encoding//webapp/src/main/webapp/WEB-INF/module_messages_fr.properties=UTF-8
encoding//webapp/src/main/webapp/WEB-INF/module_messages_it.properties=UTF-8
encoding//webapp/src/main/webapp/WEB-INF/module_messages_pt.properties=UTF-8
+encoding/<project>=UTF-8
Index: diff_file.diff
===================================================================
Index: api/pom.xml
===================================================================
--- api/pom.xml (revision 24091)
+++ api/pom.xml (working copy)
@@ -209,17 +209,6 @@
<grammars>ArdenRecognizer.g</grammars>
</configuration>
</plugin>
- <plugin>
- <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
- <artifactId>maven-java-formatter-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>format</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Index: api/src/main/resources/hibernate.cfg.xml
===================================================================
--- api/src/main/resources/hibernate.cfg.xml (revision 24091)
+++ api/src/main/resources/hibernate.cfg.xml (working copy)
@@ -77,6 +77,7 @@
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InQueue.hbm.xml" />
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InArchive.hbm.xml" />
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml" />
+ <mapping resource="org/openmrs/hl7/db/hibernate/HL7OutQueue.hbm.xml" />
<!-- Reporting -->
<mapping resource="org/openmrs/reporting/db/hibernate/Report.hbm.xml" />
Index: api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7OutQueue.hbm.xml
===================================================================
--- api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7OutQueue.hbm.xml (revision 0)
+++ api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7OutQueue.hbm.xml (revision 0)
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.openmrs">
+
+ <class name="org.openmrs.hl7.HL7OutQueue" table="hl7_out_queue">
+
+ <id name="HL7OutQueueId" type="int" column="hl7_out_queue_id" unsaved-value="0">
+ <generator class="native">
+ <param name="sequence">hl7_out_queue_hl7_out_queue_id_seq</param>
+ </generator>
+ </id>
+
+ <discriminator column="hl7_out_queue_id" insert="false" />
+
+ <property name="HL7Data" type="java.lang.String"
+ column="hl7_data" not-null="true" length="16777215" />
+
+ <property name="dateCreated" type="java.util.Date"
+ column="date_created" not-null="false" length="19" />
+
+ <property name="dateProcessed" type="java.util.Date"
+ column="date_processed" not-null="false" length="19" />
+
+ <property name="errorMessage" type="java.lang.String"
+ column="error_msg" not-null="false" length="16777215" />
+
+ <property name="messageState" type="java.lang.Integer"
+ column="message_state" not-null="true" length="4" />
+
+ <property name="uuid" type="java.lang.String"
+ column="uuid" length="38" unique="true" />
+ </class>
+</hibernate-mapping>
Index: api/src/main/resources/liquibase-update-to-latest.xml
===================================================================
--- api/src/main/resources/liquibase-update-to-latest.xml (revision 24091)
+++ api/src/main/resources/liquibase-update-to-latest.xml (working copy)
@@ -5959,6 +5959,24 @@
<column name="template" type="text"/>
</addColumn>
</changeSet>
-
+ <changeSet id="201010291835" author="thothathri">
+ <preConditions onFail="MARK_RAN">
+ <not><tableExists tableName="hl7_out_queue"/></not>
+ </preConditions>
+ <comment>
+ Create the hl7_out_queue table
+ </comment>
+ <createTable tableName="hl7_out_queue">
+ <column name="hl7_out_queue_id" type="int" autoIncrement="true">
+ <constraints primaryKey="true" nullable="false" />
+ </column>
+ <column name="hl7_data" type="text"><constraints nullable="false" /></column>
+ <column defaultValueNumeric="0" name="message_state" type="int(11)"><constraints nullable="false" /> </column>
+ <column name="date_processed" type="datetime" defaultValue="null"></column>
+ <column name="error_msg" type="text"/>
+ <column name="date_created" type="datetime" defaultValue="null" />
+ <column name="uuid" type="char(38)" defaultValue="null"><constraints unique="true" /></column>
+ </createTable>
+ </changeSet>
</databaseChangeLog>
Index: api/src/main/java/org/openmrs/hl7/impl/HL7ServiceImpl.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/impl/HL7ServiceImpl.java (revision 24091)
+++ api/src/main/java/org/openmrs/hl7/impl/HL7ServiceImpl.java (working copy)
@@ -50,6 +50,7 @@
import org.openmrs.hl7.HL7InArchive;
import org.openmrs.hl7.HL7InError;
import org.openmrs.hl7.HL7InQueue;
+import org.openmrs.hl7.HL7OutQueue;
import org.openmrs.hl7.HL7QueueItem;
import org.openmrs.hl7.HL7Service;
import org.openmrs.hl7.HL7Source;
@@ -61,6 +62,8 @@
import org.openmrs.util.OpenmrsUtil;
import org.openmrs.util.PrivilegeConstants;
import org.openmrs.validator.PatientIdentifierValidator;
+import org.openmrs.hl7.handler.HL7ADTA28Encoder;
+import org.openmrs.hl7.handler.HL7ORUR01Encoder;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.app.Application;
@@ -249,6 +252,14 @@
}
/**
+ * @see org.openmrs.hl7.HL7Service#getHL7OutQueueBatch(int, int, java.lang.String)
+ */
+ @Override
+ public List<HL7OutQueue> getHL7OutQueueBatch(int start, int length, int messageState, String query) throws APIException {
+ return dao.getHL7Batch(HL7OutQueue.class, start, length, messageState, query);
+ }
+
+ /**
* @see org.openmrs.hl7.HL7Service#getHL7InErrorBatch(int, int, java.lang.String)
*/
@Override
@@ -273,6 +284,15 @@
return dao.countHL7s(HL7InQueue.class, messageState, query);
}
+
+ /**
+ * @see org.openmrs.hl7.HL7Service#countHL7OutQueue(int, java.lang.String)
+ */
+ @Override
+ public Integer countHL7OutQueue(int messageState, String query) throws APIException {
+ return dao.countHL7s(HL7OutQueue.class, messageState, query);
+ }
+
/**
* @see org.openmrs.hl7.HL7Service#countHL7InError(java.lang.String)
*/
@@ -310,6 +330,46 @@
}
/**
+ * @see org.openmrs.hl7.HL7Service#saveHL7OutQueue(org.openmrs.hl7.HL7OutQueue)
+ */
+ public HL7OutQueue addToOutQueue(Patient patient, HL7OutQueue hl7outqueue) throws APIException {
+ HL7ADTA28Encoder A28Encoder = new HL7ADTA28Encoder();
+ String encodedMessage = new String();
+ try{
+ encodedMessage = A28Encoder.HL7EncodeAdtA05Msg(patient.getPatientId());
+ }
+ catch(HL7Exception e) {
+ log.error("HL7 Exception while saving out queue for patient "+ patient.getPatientId() ,e);
+ }
+ hl7outqueue.setHL7Data(encodedMessage);
+ hl7outqueue.setErrorMessage("");
+ if (hl7outqueue.getMessageState() == null)
+ hl7outqueue.setMessageState(HL7Constants.HL7_STATUS_PENDING);
+ return dao.saveHL7OutQueue(hl7outqueue);
+ }
+
+ /**
+ * @see org.openmrs.hl7.HL7Service#saveEncounterHL7OutQueue(org.openmrs.hl7.HL7OutQueue)
+ */
+ public HL7OutQueue addToOutQueue(Encounter encounter, HL7OutQueue hl7outqueue) throws APIException {
+ HL7ORUR01Encoder ORUEncoder = new HL7ORUR01Encoder();
+ String encodedMessage = new String();
+ try{
+ String [] a = {"CE","TX"};
+ String [] b = {"TestMessage","TestMessage2"};
+ encodedMessage = ORUEncoder.HL7EncodeOruR01Msg(encounter.getPatient().getPatientId(), a,b);
+ }
+ catch(HL7Exception e) {
+ log.error("HL7 Exception while saving encounter for patient "+encounter.getPatient().getPatientId() ,e);
+ }
+ hl7outqueue.setHL7Data(encodedMessage);
+ hl7outqueue.setErrorMessage("");
+ if (hl7outqueue.getMessageState() == null)
+ hl7outqueue.setMessageState(HL7Constants.HL7_STATUS_PENDING);
+
+ return dao.saveHL7OutQueue(hl7outqueue);
+ }
+ /**
* @see org.openmrs.hl7.HL7Service#createHL7InQueue(org.openmrs.hl7.HL7InQueue)
* @deprecated
*/
Index: api/src/main/java/org/openmrs/hl7/HL7OutQueue.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/HL7OutQueue.java (revision 0)
+++ api/src/main/java/org/openmrs/hl7/HL7OutQueue.java (revision 0)
@@ -0,0 +1,157 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.hl7;
+
+import java.io.Serializable;
+import org.openmrs.BaseOpenmrsObject;
+import java.util.Date;
+
+
+/**
+ * Represents an hl7 message that is saved when a new Patient is saved or when new Encounter is saved.
+ *
+ * @see HL7Service
+ */
+public class HL7OutQueue extends BaseOpenmrsObject implements Serializable {
+
+ private static final long serialVersionUID = 8882704913734764446L;
+
+ private Integer hl7OutQueueId;
+
+ private String errorMessage;
+
+ private Integer messageState;
+
+ private String hl7Data;
+
+ private Date dateCreated;
+
+ private Date dateProcessed;
+
+ /**
+ * Default constructor
+ */
+ public HL7OutQueue() {
+ }
+
+ /**
+ * @return Returns the hl7Data.
+ */
+ public String getHL7Data() {
+ return hl7Data;
+ }
+ /**
+ * @param hl7Data The hl7Data to set.
+ */
+ public void setHL7Data(String hl7Data) {
+ this.hl7Data = hl7Data;
+ }
+
+
+ /**
+ * @return Returns the dateCreated.
+ */
+ public Date getDateCreated() {
+ return dateCreated;
+ }
+
+ /**
+ * @param dateCreated The dateCreated to set.
+ */
+ public void setDateCreated(Date dateCreated) {
+ this.dateCreated = dateCreated;
+ }
+
+ /**
+ * @return Returns the dateCreated.
+ */
+ public Date getDateProcessed() {
+ return dateProcessed;
+ }
+
+ /**
+ * @param dateCreated The dateCreated to set.
+ */
+ public void setDateProcessed(Date dateProcessed) {
+ this.dateCreated = dateProcessed;
+ }
+
+ /**
+ * @return Returns the hl7OutQueueId.
+ */
+ public Integer getHL7OutQueueId() {
+ return hl7OutQueueId;
+ }
+
+ /**
+ * @param hl7OutQueueId The hl7OutQueueId to set.
+ */
+ public void setHL7OutQueueId(Integer hl7OutQueueId) {
+ this.hl7OutQueueId = hl7OutQueueId;
+ }
+
+ /**
+ * @return Returns the errorMessage.
+ * @since 1.5
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * @param errorMessage The errorMessage to set.
+ * @since 1.5
+ */
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ /**
+ * Can be one of the states in the {@link HL7Constants} file.
+ *
+ * @return Returns the message State.
+ * @see HL7Constants#HL7_STATUS_PENDING
+ * @see HL7Constants#HL7_STATUS_ERROR
+ * @see HL7Constants#HL7_STATUS_PROCESSED
+ * @see HL7Constants#HL7_STATUS_PROCESSING
+ * @see HL7Constants#HL7_STATUS_DELETED
+ */
+ public Integer getMessageState() {
+ return messageState;
+ }
+
+ /**
+ * @param messageState The message State to set.
+ */
+ public void setMessageState(Integer messageState) {
+ this.messageState = messageState;
+ }
+
+ /**
+ * @see org.openmrs.OpenmrsObject#getId()
+ * @since 1.5
+ */
+ public Integer getId() {
+ return getHL7OutQueueId();
+ }
+
+ /**
+ * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
+ * @since 1.5
+ */
+ public void setId(Integer id) {
+ setHL7OutQueueId(id);
+ }
+
+}
Index: api/src/main/java/org/openmrs/hl7/HL7Service.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/HL7Service.java (revision 24091)
+++ api/src/main/java/org/openmrs/hl7/HL7Service.java (working copy)
@@ -19,6 +19,7 @@
import org.openmrs.Encounter;
import org.openmrs.Person;
+import org.openmrs.Patient;
import org.openmrs.annotation.Authorized;
import org.openmrs.annotation.Logging;
import org.openmrs.api.APIException;
@@ -49,6 +50,25 @@
public void setHL7DAO(HL7DAO dao);
/**
+ * Save the given <code>hl7OutQueue</code> to the database for each
+ * {@link org.openmrs.api.impl.PatientServiceImpl#savePatient(Patient) savePatient()} call made in PatientServiceImpl class
+ *
+ * @param patient the Patient object
+ * @param hl7OutQueue the item to be saved into the database
+ * @return the saved HL7OutQueue object
+ */
+ public HL7OutQueue addToOutQueue(Patient patient, HL7OutQueue hl7OutQueue) throws APIException;
+
+ /**
+ * Save the given <code>hl7OutQueue</code> to the database for each
+ * {@link org.openmrs.api.impl.EncounterServiceImpl#saveEncounter(Encounter) saveEncounter()} call made in EncounterServiceImpl class
+ *
+ * @param patient the Patient object
+ * @param hl7OutQueue the item to be saved into the database
+ * @return the saved HL7OutQueue object
+ */
+ public HL7OutQueue addToOutQueue(Encounter encounter, HL7OutQueue hl7outqueue) throws APIException;
+ /**
* Save the given <code>hl7Source</code> to the database
*
* @param hl7Source the source to save
@@ -207,6 +227,22 @@
@Authorized(HL7Constants.PRIV_VIEW_HL7_IN_QUEUE)
public List<HL7InQueue> getHL7InQueueBatch(int start, int length, int messageState, String query) throws APIException;
+
+ /**
+ * Return a list of all hl7 in queues based on batch settings and a query string
+ *
+ * @param start beginning index
+ * @param length size of the batch
+ * @param messageState status of the HL7InQueue message
+ * @param query search string
+ * @return all matching hl7 queue items within batch window
+ * @throws APIException
+ * @since 1.7
+ */
+ @Transactional(readOnly = true)
+ //@Authorized(HL7Constants.PRIV_VIEW_HL7_IN_QUEUE)
+ public List<HL7OutQueue> getHL7OutQueueBatch(int start, int length, int messageState, String query) throws APIException;
+
/**
* the total count of all HL7InQueue objects in the database
*
@@ -221,6 +257,19 @@
public Integer countHL7InQueue(int messageState, String query) throws APIException;
/**
+ * the total count of all HL7OutQueue objects in the database
+ *
+ * @param messageState HL7OutQueue status
+ * @param query search string
+ * @return the count of matching HL7OutQueue items
+ * @throws APIException
+ * @since 1.7
+ */
+ @Transactional(readOnly = true)
+ //@Authorized(HL7Constants.PRIV_VIEW_HL7_IN_QUEUE)
+ public Integer countHL7OutQueue(int messageState, String query) throws APIException;
+
+ /**
* Return a list of all hl7 in errors based on batch settings and a query string
*
* @param start beginning index
Index: api/src/main/java/org/openmrs/hl7/handler/HL7ORUR01Encoder.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/handler/HL7ORUR01Encoder.java (revision 0)
+++ api/src/main/java/org/openmrs/hl7/handler/HL7ORUR01Encoder.java (revision 0)
@@ -0,0 +1,239 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.hl7.handler;
+
+import org.openmrs.Person;
+import org.openmrs.PersonName;
+import org.openmrs.api.context.Context;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.Location;
+import org.openmrs.Patient;
+import org.openmrs.PatientIdentifier;
+import org.openmrs.PatientIdentifierType;
+import org.openmrs.PersonName;
+import org.openmrs.User;
+import org.openmrs.api.PatientIdentifierException;
+import org.openmrs.api.context.Context;
+import org.openmrs.util.OpenmrsConstants;
+import org.openmrs.validator.PatientIdentifierValidator;
+
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.app.Application;
+import ca.uhn.hl7v2.app.ApplicationException;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.Varies;
+import ca.uhn.hl7v2.model.v25.datatype.*;
+import ca.uhn.hl7v2.model.v25.group.ORU_R01_ORDER_OBSERVATION;
+import ca.uhn.hl7v2.model.v25.datatype.CX;
+import ca.uhn.hl7v2.model.v25.datatype.ID;
+import ca.uhn.hl7v2.model.v25.datatype.TS;
+import ca.uhn.hl7v2.model.v25.datatype.XPN;
+import ca.uhn.hl7v2.model.v25.message.ADT_A05;
+import ca.uhn.hl7v2.model.v25.message.ADT_A01;
+import ca.uhn.hl7v2.model.v25.message.ORU_R01;
+import ca.uhn.hl7v2.model.v25.segment.MSH;
+import ca.uhn.hl7v2.model.v25.segment.PID;
+import ca.uhn.hl7v2.model.v25.segment.OBR;
+import ca.uhn.hl7v2.model.v25.segment.OBX;
+import ca.uhn.hl7v2.parser.DefaultXMLParser;
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.parser.PipeParser;
+
+/* HL7 using HAPI to encode into ORU R01 Messages
+ *
+ * ADT/ACK - Add person or patient information (Event R01)
+ *
+ * FYI: The 3rd field of MSH contains the sending application.
+ * For example, the Rwanda lab system uses 'neal_lims'.
+ * If neal_lims exists as an OpenMRS username, then this handler
+ * will use that user as the creator for patients it creates.
+ * If the sending application isn't setup as an OpenMRS user,
+ * the creator will default to the user running this task.
+ *
+ * TODO: You may wonder why the createPatient, validate, getMSH,
+ * getPIH and tsToDate code is duplicated in this file (and the R01
+ * message handler file? It would be more useful to have these in the
+ * HL7 Utility file. It's a good question, and it will happen
+ * soon.
+ *
+ * The HL7 v2.5 manual table 0354 (section 2.17.3) describes A28.
+ *
+ * There are many cases in HL7 where events (like A05, A14, A28, and A31)
+ * share a common structure. This table also represented in HL7APIs
+ * eventmap properties file (http://tinyurl.com/2almfx) -- describes
+ * exactly which events share which structures.
+ *
+ * So the answer to the A28 event is to use the ADT_A05 message
+ * structure from within the v2.5 object hierarchy. Without going
+ * to the table, you can see this relationship in the description
+ * of the A28 event message structure (3.3.28), which is labeled as
+ * ADT^A28^ADT_A05. This represents the message type (ADT),
+ * event (A28), and message structure (ADT_A05).
+ *
+ * TODO: This ADT A28 handler does NOT currently handle ALL possible segments.
+ * Some of the segments that are not handled include these:
+ *
+ * EVN (Event type) - required to be backwardly compatible
+ * SFT (Software segment)
+ * PD1 (Additional demographics) (*)
+ * ROL (Role)
+ * NK1 (Next of Kin / associated parties) (*)
+ * PV1/2 (Patient visit - additional information) (*)
+ * DB1 (Disability information)
+ * OBX (Observation / result) (***)
+ * AL1 (Allergy information)
+ * DG1 (Diagnosis information)
+ * DRG (Diagnosis related group)
+ * PR1 (Procedures)
+ * GT1 (Guarantor)
+ * IN1 (Insurance)
+ * ACC (Accident information)
+ * UB1/2 (Universal Bill Information)
+ *
+ * NOTE: The ones with (*) could be useful in the near future.
+ */
+
+/**
+ *
+ * Encodes the HL7 messages(ORU_R01) using V25 of HAPI library
+ *
+ */
+public class HL7ORUR01Encoder {
+
+ private static int sequenceNumber = 0;
+
+ private Log log = LogFactory.getLog(HL7ORUR01Encoder.class);
+
+ public HL7ORUR01Encoder() {
+ /* Default Constructor*/
+ }
+
+ /**
+ * @param mshSegment the MSH object, which is the Message Header of the ADT_A05 message
+ * @param msgType the message code, in this case "ADT"
+ * @param trigEvent the trigger event, in this case "A05"
+ */
+ public void getGeneralMshSeg(MSH mshSegment,String msgType, String trigEvent) {
+ Calendar currentDate = Calendar.getInstance();
+ SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMddHHmm");
+ String dateNow = formatter.format(currentDate.getTime());
+ System.out.println("Now the date is :=> " + dateNow);
+ // Populate the MSH Segment
+ try{
+ mshSegment.getFieldSeparator().setValue("|");
+ mshSegment.getEncodingCharacters().setValue("^~\\&");
+ mshSegment.getDateTimeOfMessage().getTime().setValue(dateNow);
+ mshSegment.getSendingApplication().getNamespaceID().setValue("OpenMrs");
+ mshSegment.getSequenceNumber().setValue(Integer.toString(sequenceNumber++));
+ mshSegment.getMessageType().getMessageCode().setValue(msgType);
+ mshSegment.getMessageType().getTriggerEvent().setValue(trigEvent);
+ mshSegment.getMessageType().getMessageStructure().setValue(msgType+" "+trigEvent);
+ }
+ catch(Exception e) {
+ System.out.println("Exception at getGeneralMshSeg");
+ }
+ }
+
+ /**
+ * @param pid the PID header
+ * @param person a Person object
+ * @param patientId the ID of the Patient
+ */
+ public void getPatientInfo(PID pid,Person person,Integer patientId) {
+ try {
+ pid.getPatientName(0).getFamilyName().getSurname().setValue(person.getFamilyName());
+ pid.getPatientName(0).getGivenName().setValue(person.getGivenName());
+ pid.getPatientIdentifierList(0).getIDNumber().setValue(patientId.toString());
+ }
+
+ catch(Exception e) {
+ log.error("Error casting to HL7ORU_R01", e);
+ }
+ }
+
+ /**
+ * @param patientId the ID of the Patient
+ * @param obxTypes[] a String array with the various types
+ * @param obxMsg[] a String array with the various corresponding messages
+ * @return the encoded String
+ */
+ public String HL7EncodeOruR01Msg(Integer patientId, String obxTypes[], String obxMsg[]) throws HL7Exception {
+
+ ORU_R01 oru = new ORU_R01();
+
+ // Populate the MSH Segment
+ MSH mshSegment = oru.getMSH();
+ getGeneralMshSeg(mshSegment,"ORU","R01");
+
+
+ ORU_R01_ORDER_OBSERVATION orderObservation = oru.getPATIENT_RESULT().getORDER_OBSERVATION();
+
+ // Populate the OBR
+ OBR obr = orderObservation.getOBR();
+ obr.getSetIDOBR().setValue("1");
+ obr.getFillerOrderNumber().getEntityIdentifier().setValue("1234");
+ obr.getFillerOrderNumber().getNamespaceID().setValue("OpenMrs");
+ obr.getUniversalServiceIdentifier().getIdentifier().setValue("88304");
+
+ for (int i = 0; i < obxTypes.length; i = i + 1) {
+ // Populate the OBX
+ OBX obx = orderObservation.getOBSERVATION(i).getOBX();
+ obx.getSetIDOBX().setValue(Integer.toString(i+1));
+ obx.getObservationIdentifier().getIdentifier().setValue("88304");
+
+ if( obxTypes[i] == "CE") {
+ // The OBX has a value type of CE. So first, we populate OBX-2 with "CE"...
+ obx.getValueType().setValue("CE");
+ // ... then we create a CE instance to put in OBX-5.
+ CE ce = new CE(oru);
+ ce.getIdentifier().setValue("T57000");
+ ce.getText().setValue(obxMsg[i]);
+ ce.getNameOfCodingSystem().setValue("SNM");
+ Varies value = obx.getObservationValue(0);
+ value.setData(ce);
+ }
+ else if ( obxTypes[i] == "TX") {
+ // The OBX has a value type of TX. So first, we populate OBX-2 with "TX"...
+ obx.getValueType().setValue("TX");
+
+ // ... then we create a SN instance to put in OBX-5.
+ TX tx = new TX(oru);
+ tx.setValue(obxMsg[i]);
+ Varies value = obx.getObservationValue(0);
+ value.setData(tx);
+ }
+
+ }
+
+ // Print the message (remember, the MSH segment was not fully or correctly populated)
+ Parser parser = new PipeParser();
+ String encodedMessage = parser.encode(oru);
+
+ System.out.println("Printing Encoded Message:");
+ System.out.println(encodedMessage);
+
+ return encodedMessage;
+ }
+}
+
+
Index: api/src/main/java/org/openmrs/hl7/handler/HL7ADTA28Encoder.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/handler/HL7ADTA28Encoder.java (revision 0)
+++ api/src/main/java/org/openmrs/hl7/handler/HL7ADTA28Encoder.java (revision 0)
@@ -0,0 +1,224 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.hl7.handler;
+
+import org.openmrs.Person;
+import org.openmrs.PersonName;
+import org.openmrs.api.context.Context;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.Location;
+import org.openmrs.Patient;
+import org.openmrs.PatientIdentifier;
+import org.openmrs.PatientIdentifierType;
+import org.openmrs.PersonName;
+import org.openmrs.User;
+import org.openmrs.api.PatientIdentifierException;
+import org.openmrs.api.context.Context;
+import org.openmrs.util.OpenmrsConstants;
+import org.openmrs.validator.PatientIdentifierValidator;
+
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.app.Application;
+import ca.uhn.hl7v2.app.ApplicationException;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.model.v25.datatype.CX;
+import ca.uhn.hl7v2.model.v25.datatype.ID;
+import ca.uhn.hl7v2.model.v25.datatype.TS;
+import ca.uhn.hl7v2.model.v25.datatype.XPN;
+import ca.uhn.hl7v2.model.v25.message.ADT_A05;
+import ca.uhn.hl7v2.model.v25.message.ADT_A01;
+import ca.uhn.hl7v2.model.v25.segment.MSH;
+import ca.uhn.hl7v2.model.v25.segment.PID;
+import ca.uhn.hl7v2.parser.DefaultXMLParser;
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.parser.PipeParser;
+
+/* HL7 using HAPI to encode into ADT A05 Messages
+ *
+ * ADT/ACK - Add person or patient information (Event A28)
+ *
+ * FYI: The 3rd field of MSH contains the sending application.
+ * For example, the Rwanda lab system uses 'neal_lims'.
+ * If neal_lims exists as an OpenMRS username, then this handler
+ * will use that user as the creator for patients it creates.
+ * If the sending application isn't setup as an OpenMRS user,
+ * the creator will default to the user running this task.
+ *
+ * TODO: You may wonder why the createPatient, validate, getMSH,
+ * getPIH and tsToDate code is duplicated in this file (and the R01
+ * message handler file? It would be more useful to have these in the
+ * HL7 Utility file. It's a good question, and it will happen
+ * soon.
+ *
+ * The HL7 v2.5 manual table 0354 (section 2.17.3) describes A28.
+ *
+ * There are many cases in HL7 where events (like A05, A14, A28, and A31)
+ * share a common structure. This table also represented in HL7APIs
+ * eventmap properties file (http://tinyurl.com/2almfx) -- describes
+ * exactly which events share which structures.
+ *
+ * So the answer to the A28 event is to use the ADT_A05 message
+ * structure from within the v2.5 object hierarchy. Without going
+ * to the table, you can see this relationship in the description
+ * of the A28 event message structure (3.3.28), which is labeled as
+ * ADT^A28^ADT_A05. This represents the message type (ADT),
+ * event (A28), and message structure (ADT_A05).
+ *
+ * TODO: This ADT A28 handler does NOT currently handle ALL possible segments.
+ * Some of the segments that are not handled include these:
+ *
+ * EVN (Event type) - required to be backwardly compatible
+ * SFT (Software segment)
+ * PD1 (Additional demographics) (*)
+ * ROL (Role)
+ * NK1 (Next of Kin / associated parties) (*)
+ * PV1/2 (Patient visit - additional information) (*)
+ * DB1 (Disability information)
+ * OBX (Observation / result) (***)
+ * AL1 (Allergy information)
+ * DG1 (Diagnosis information)
+ * DRG (Diagnosis related group)
+ * PR1 (Procedures)
+ * GT1 (Guarantor)
+ * IN1 (Insurance)
+ * ACC (Accident information)
+ * UB1/2 (Universal Bill Information)
+ *
+ * NOTE: The ones with (*) could be useful in the near future.
+ */
+
+/**
+ *
+ * Encodes the HL7 messages(ADT_A28) using V25 of HAPI library
+ *
+ */
+public class HL7ADTA28Encoder {
+
+ private static int sequenceNumber = 0;
+ public HL7ADTA28Encoder() {
+ /* Default Constructor*/
+ }
+ /**
+ * @param mshSegment the MSH object, which is the Message Header of the ADT_A05 message
+ * @param msgType the message code, in this case "ADT"
+ * @param trigEvent the trigger event, in this case "A05"
+ */
+ public void getGeneralMshSeg(MSH mshSegment,String msgType, String trigEvent) {
+ Calendar currentDate = Calendar.getInstance();
+ SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMddHHmm");
+ String dateNow = formatter.format(currentDate.getTime());
+ System.out.println("Now the date is :=> " + dateNow);
+ // Populate the MSH Segment
+ try{
+ mshSegment.getFieldSeparator().setValue("|");
+ mshSegment.getEncodingCharacters().setValue("^~\\&");
+ mshSegment.getDateTimeOfMessage().getTime().setValue(dateNow);
+ mshSegment.getSendingApplication().getNamespaceID().setValue("OpenMrs");
+ mshSegment.getSequenceNumber().setValue(Integer.toString(sequenceNumber++));
+ mshSegment.getMessageType().getMessageCode().setValue(msgType);
+ mshSegment.getMessageType().getTriggerEvent().setValue(trigEvent);
+ mshSegment.getMessageType().getMessageStructure().setValue(msgType+" "+trigEvent);
+ }
+ catch(Exception e) {
+ System.out.println("Exception Encountered!");
+ }
+ }
+
+ /**
+ * @param pid the PID header
+ * @param person a Person object
+ * @param patientId the ID of the Patient
+ */
+ public void getPatientInfo(PID pid,Person person,Integer patientId) {
+ try {
+ pid.getPatientName(0).getFamilyName().getSurname().setValue(person.getFamilyName());
+ pid.getPatientName(0).getGivenName().setValue(person.getGivenName());
+ pid.getPatientIdentifierList(0).getIDNumber().setValue(patientId.toString());
+ }
+ catch(Exception e) {
+ System.out.println("Exception in HL7ADTA28Encoder#getPatientInfo");
+ }
+ }
+
+ /**
+ * @param patientId the ID of the Patient
+ * @return String with the encoded message
+ */
+ public String HL7EncodeAdtA01Msg(Integer patientId) throws HL7Exception {
+
+ ADT_A01 adt = new ADT_A01();
+
+ // Populate the MSH Segment
+ MSH mshSegment = adt.getMSH();
+ getGeneralMshSeg(mshSegment,"ADT","A01");
+
+ // Populate the PID Segment
+ PersonName newPersonName = new PersonName();
+
+ try {
+ newPersonName = Context.getPersonService().getPersonName(patientId);
+ }
+ catch(Exception e) {
+ System.out.println("Exception in HL7ADTA28Encoder");
+ }
+
+ getPatientInfo(adt.getPID(),newPersonName.getPerson(),patientId);
+
+ Parser parser = new PipeParser();
+ String encodedMessage = parser.encode(adt);
+
+ return encodedMessage;
+ }
+
+ /**
+ * @param patientId the ID of the Patient object
+ * @return String with the encoded message
+ */
+ public String HL7EncodeAdtA05Msg(Integer patientId) throws HL7Exception {
+
+ ADT_A05 adt = new ADT_A05();
+
+ // Populate the MSH Segment
+ MSH mshSegment = adt.getMSH();
+ getGeneralMshSeg(mshSegment,"ADT","A05");
+
+ // Populate the PID Segment
+ PersonName newPersonName = new PersonName();
+
+ try {
+ newPersonName = Context.getPersonService().getPersonName(patientId);
+ }
+
+ catch(Exception e) {
+ System.out.println("Exception in HL7ADTA28Encoder");
+ }
+
+ getPatientInfo(adt.getPID(),newPersonName.getPerson(),patientId);
+
+ Parser parser = new PipeParser();
+ String encodedMessage = parser.encode(adt);
+
+ return encodedMessage;
+ }
+}
+
+
Index: api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java (revision 24091)
+++ api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java (working copy)
@@ -32,6 +32,7 @@
import org.openmrs.hl7.HL7InArchive;
import org.openmrs.hl7.HL7InError;
import org.openmrs.hl7.HL7InQueue;
+import org.openmrs.hl7.HL7OutQueue;
import org.openmrs.hl7.HL7Source;
import org.openmrs.hl7.Hl7InArchivesMigrateThread;
import org.openmrs.hl7.db.HL7DAO;
@@ -118,6 +119,7 @@
return (HL7InQueue) sessionFactory.getCurrentSession().get(HL7InQueue.class, hl7InQueueId);
}
+
@Override
public HL7InQueue getHL7InQueueByUuid(String uuid) throws DAOException {
return (HL7InQueue) sessionFactory.getCurrentSession().createCriteria(HL7InQueue.class).add(
@@ -135,6 +137,22 @@
}
/**
+ * @see org.openmrs.hl7.db.HL7DAO#saveHL7OutQueue(org.openmrs.hl7.HL7OutQueue)
+ */
+ public HL7OutQueue saveHL7OutQueue(HL7OutQueue hl7OutQueue) throws DAOException {
+ sessionFactory.getCurrentSession().saveOrUpdate(hl7OutQueue);
+ return hl7OutQueue;
+ }
+
+ /**
+ * @see org.openmrs.hl7.db.HL7DAO#getHL7OutQueue(java.lang.Integer)
+ */
+ public HL7OutQueue getHL7OutQueue(Integer hl7OutQueueId) throws DAOException {
+ return (HL7OutQueue) sessionFactory.getCurrentSession().get(HL7OutQueue.class, hl7OutQueueId);
+ }
+
+
+ /**
* creates a Criteria object for use with counting and finding HL7InQueue objects
*
* @param messageState status of HL7InQueue object
Index: api/src/main/java/org/openmrs/hl7/db/HL7DAO.java
===================================================================
--- api/src/main/java/org/openmrs/hl7/db/HL7DAO.java (revision 24091)
+++ api/src/main/java/org/openmrs/hl7/db/HL7DAO.java (working copy)
@@ -19,6 +19,7 @@
import org.openmrs.hl7.HL7InArchive;
import org.openmrs.hl7.HL7InError;
import org.openmrs.hl7.HL7InQueue;
+import org.openmrs.hl7.HL7OutQueue;