[507] | 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.cpp;
|
---|
| 7 |
|
---|
| 8 | import gov.hhs.fha.nhinc.mpilib.Identifier;
|
---|
| 9 | import gov.hhs.fha.nhinc.mpilib.Identifiers;
|
---|
| 10 | import gov.hhs.fha.nhinc.mpilib.MiniMpi;
|
---|
| 11 | import gov.hhs.fha.nhinc.mpilib.Patient;
|
---|
| 12 | import gov.hhs.fha.nhinc.mpilib.PersonName;
|
---|
| 13 | import javax.xml.parsers.DocumentBuilder;
|
---|
| 14 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
| 15 | import org.junit.After;
|
---|
| 16 | import org.junit.AfterClass;
|
---|
| 17 | import org.junit.Before;
|
---|
| 18 | import org.junit.BeforeClass;
|
---|
| 19 | import org.junit.Test;
|
---|
| 20 | import org.w3c.dom.Document;
|
---|
| 21 | import static org.junit.Assert.*;
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | *
|
---|
| 25 | * @author svalluripalli
|
---|
| 26 | */
|
---|
| 27 | public 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 | }
|
---|