source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/ConsumerPreferencesProfileGUI/test/gov/hhs/fha/nhinc/cpp/CPPOperationsTest.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.9 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.cpp;
7
8import gov.hhs.fha.nhinc.mpilib.Identifier;
9import gov.hhs.fha.nhinc.mpilib.Identifiers;
10import gov.hhs.fha.nhinc.mpilib.MiniMpi;
11import gov.hhs.fha.nhinc.mpilib.Patient;
12import gov.hhs.fha.nhinc.mpilib.PersonName;
13import javax.xml.parsers.DocumentBuilder;
14import javax.xml.parsers.DocumentBuilderFactory;
15import org.junit.After;
16import org.junit.AfterClass;
17import org.junit.Before;
18import org.junit.BeforeClass;
19import org.junit.Test;
20import org.w3c.dom.Document;
21import static org.junit.Assert.*;
22
23/**
24 *
25 * @author svalluripalli
26 */
27public class CPPOperationsTest {
28
29 private static final String orgId = "123";
30 private static final String patId = "123-123";
31
32 public CPPOperationsTest() {
33 }
34
35 @BeforeClass
36 public static void setUpClass() throws Exception {
37 }
38
39 @AfterClass
40 public static void tearDownClass() throws Exception {
41 }
42
43 @Before
44 public void setUp() {
45 }
46
47 @After
48 public void tearDown() {
49 }
50
51 @Test
52 public void testSaveCPP()
53 {
54 CPPOperations ops = new CPPOperations();
55 //ops.saveCPP("123", "123", "<test>asdf</test>");
56 }
57
58 @Test
59 public void testUpdateOptInNoMpi()
60 {
61 String xacml = getXMLStringForOptOut();
62 CPPOperations ops = new CPPOperations();
63 String ack = ops.updateOptIn(patId, orgId, xacml);
64 assertEquals("Patient Not Found in MPI",ack);
65 }
66
67 @Test
68 public void testUpdateOptInMpi(){
69 String xacml = getXMLStringForOptOut();
70 //removePatient();
71 createPatient();
72 CPPOperations ops = new CPPOperations();
73 String ack = ops.updateOptIn(patId, orgId, xacml);
74 removePatient();
75 assertEquals("Patient OptInOut Flag Updated Successfully",ack);
76 }
77
78 @Test
79 public void testUpdateOptInNotifyDocument(){
80 String xacml = getXMLStringForOptOut();
81 gov.hhs.fha.nhinc.repository.model.Document doc = new gov.hhs.fha.nhinc.repository.model.Document();
82 doc.setDocumentUniqueId("12345");
83 createPatient();
84 CPPOperations ops = new CPPOperations();
85 //Commented this line build server will fail...Uncomment to test with Actual Service EntitySubscription...
86 //ops.updateOptInNotifyDocument(patId, orgId, xacml,doc);
87 removePatient();
88 }
89
90 private String getXMLStringForOptOut(){
91 Document doc = null;
92 Identifier id = null;
93 try
94 {
95 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance( );
96 DocumentBuilder builder = builderFactory.newDocumentBuilder( );
97 doc = builder.parse (new org.xml.sax.InputSource ("test/gov/hhs/fha/nhinc/cpp/OptOut.xml"));
98 id = CPPUtils.extractPatientId(doc);
99 boolean opt = CPPUtils.isOptedIn(doc);
100 System.out.println("Opted in status is ----->"+opt);
101 }catch (Exception ex)
102 {
103 assertEquals(1,0);
104 }
105 return CPPUtils.DocumentToString(doc);
106 }
107
108 private void createPatient(){
109 Patient p = new Patient();
110 PersonName name = new PersonName("Test", "Dummy");
111 p.setName(name);
112
113 Identifiers ids = new Identifiers();
114 Identifier id = new Identifier(patId,orgId);
115
116 ids.add(id);
117 p.setIdentifiers(ids);
118 p.setOptedIn(true);
119
120 MiniMpi mpi = MiniMpi.GetMpiInstance();
121 mpi.Reset();
122 mpi.AddUpdate(p);
123 }
124
125 private void removePatient(){
126 Patient p = new Patient();
127 PersonName name = new PersonName("Test", "Dummy");
128 p.setName(name);
129 Identifiers ids = new Identifiers();
130 Identifier id = new Identifier(patId,orgId);
131 ids.add(id);
132 p.setIdentifiers(ids);
133 MiniMpi mpi = MiniMpi.GetMpiInstance();
134 mpi.Reset();
135 mpi.Delete(p, orgId);
136 }
137}
Note: See TracBrowser for help on using the repository browser.