source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincLib/test/gov/hhs/fha/nhinc/util/format/PatientIdFomatUtilTest.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 3.2 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package gov.hhs.fha.nhinc.util.format;
7
8import org.junit.AfterClass;
9import org.junit.BeforeClass;
10import org.junit.Test;
11import static org.junit.Assert.*;
12
13/**
14 *
15 * @author webbn
16 */
17public class PatientIdFomatUtilTest {
18
19 @Test
20 public void testPatientIdParse()
21 {
22 try
23 {
24 String toParse = "1234";
25 String expected = "1234";
26
27 String parsed = PatientIdFormatUtil.parsePatientId(toParse);
28 assertNotNull("Parsed - no HL7 was null", parsed);
29 assertEquals("Parsed - no HL7 was incorrect", expected, parsed);
30
31 toParse = "4567^^^&2.16.840.1.113883.3.166.1.1&ISO";
32 expected = "4567";
33
34 parsed = PatientIdFormatUtil.parsePatientId(toParse);
35 assertNotNull("Parsed - HL7 was null", parsed);
36 assertEquals("Parsed - HL7 was incorrect", expected, parsed);
37 }
38 catch(Throwable t)
39 {
40 t.printStackTrace();
41 fail("Failed to parse patient id: " + t.getMessage());
42 }
43 }
44
45 @Test
46 public void testCommunityIdParse()
47 {
48 try
49 {
50 String toParse = "4567^^^&2.16.840.1.113883.3.166.1.1&ISO";
51 String expectedHomeCommunity = "2.16.840.1.113883.3.166.1.1";
52
53 String parsedHomeCommunity = PatientIdFormatUtil.parseCommunityId(toParse);
54 assertNotNull("Parsed home community was null", parsedHomeCommunity);
55 assertEquals("Parsed home community was incorrect", expectedHomeCommunity, parsedHomeCommunity);
56
57 toParse = "4567^^^";
58 parsedHomeCommunity = PatientIdFormatUtil.parseCommunityId(toParse);
59 assertNull("Parsed home community was not null when invalid", parsedHomeCommunity);
60
61 toParse = "4567";
62 parsedHomeCommunity = PatientIdFormatUtil.parseCommunityId(toParse);
63 assertNull("Parsed home community was not null when not HL7 formatted", parsedHomeCommunity);
64
65 toParse = null;
66 parsedHomeCommunity = PatientIdFormatUtil.parseCommunityId(toParse);
67 assertNull("Parsed home community was not null when id was null", parsedHomeCommunity);
68
69 }
70 catch(Throwable t)
71 {
72 t.printStackTrace();
73 fail("Failed to parse community id: " + t.getMessage());
74 }
75 }
76
77 @Test
78 public void testPatientIdFormat()
79 {
80 try
81 {
82 String patientId = "1234";
83 String homeCommunityId = "2.16.840.1.113883.3.166.1.1";
84 String expected = "'1234^^^&2.16.840.1.113883.3.166.1.1&ISO'";
85
86 String formatted = PatientIdFormatUtil.hl7EncodePatientId(patientId, homeCommunityId);
87 assertNotNull("Formatted - id was null", formatted);
88 assertEquals("Formatted - id was incorrect", expected, formatted);
89
90 }
91 catch(Throwable t)
92 {
93 t.printStackTrace();
94 fail("Failed to parse patient id: " + t.getMessage());
95 }
96 }
97
98}
Note: See TracBrowser for help on using the repository browser.