PixServiceImpl implements PixService { @Override public PixManagerBean queryPatient(String mrn, String mrnDomain) { logger.debug("Received request to PIXQuery"); PixManagerBean pixMgrBean = new PixManagerBean(); try { String xmlFilePath = hl7v3Transformer.getPixQueryXml(mrn, mrnDomain, Hl7v3Transformer.XML_PIX_QUERY); PRPAIN201309UV02 request = new PRPAIN201309UV02(); PRPAIN201310UV02 response = new PRPAIN201310UV02(); request = requestXMLToJava.getPIXQueryReqObject(xmlFilePath, PixManagerConstants.ENCODE_STRING); logDebug("PIX QUERY Request: ", request); response = pixManagerService.pixManagerPRPAIN201309UV02(request); logDebug("PIX QUERY Response: ", response); pixManagerMessageHelper.getQueryMessage(response, pixMgrBean); } catch (Hl7v3TransformerException e) { pixManagerMessageHelper.getGeneralExpMessage(e, pixMgrBean, PixManagerConstants.PIX_QUERY); throw new IllegalArgumentException(e); } catch (JAXBException | IOException e) { pixManagerMessageHelper.getGeneralExpMessage(e, pixMgrBean, PixManagerConstants.PIX_QUERY); } return pixMgrBean; } PixServiceImpl(String mrnDomain, String pidPrefix,
			PixManagerRequestXMLToJava requestXMLToJava,
			PixManagerService pixManagerService,
			PixManagerMessageHelper pixManagerMessageHelper,
			Hl7v3Transformer hl7v3Transformer, SimpleMarshaller simpleMarshaller); @Override String getEid(String mrn); @Override PixManagerBean queryPatient(String mrn, String mrnDomain); @Override PixManagerBean addPatient(PixPatientDto pixPatientDto); @Override PixManagerBean updatePatient(PixPatientDto pixPatientDto);  }
@Test public void testQueryPerson() throws Hl7v3TransformerException, JAXBException, IOException { String expectedQueryMessage = "Query Success! Given PID: PUI100010060001 Given UID: 2.16.840.1.113883.3.72.5.9.1 "; arrangeCommonValid(); PixManagerBean bean = sut.queryPatient(MRN, MRN_DOMAIN); assertNotNull(bean); assertEquals(expectedQueryMessage, bean.getQueryMessage()); assertEquals(EXPECTED_EID, bean.getQueryIdMap().get(EXPECTED_DOMAIN)); assertEquals("", bean.getAddMessage()); assertEquals("", bean.getUpdateMessage()); verify(marshallerMock, times(2)).marshal(anyObject()); }
@SuppressWarnings("unchecked") @Test public void testQueryPerson_Throws_Hl7v3TransformerException() throws Hl7v3TransformerException, JAXBException, IOException { when( hl7v3Transformer.getPixQueryXml(MRN, MRN_DOMAIN, Hl7v3Transformer.XML_PIX_QUERY)).thenThrow( Hl7v3TransformerException.class); thrown.expect(RuntimeException.class); @SuppressWarnings("unused") PixManagerBean bean = sut.queryPatient(MRN, MRN_DOMAIN); }
@SuppressWarnings("unchecked") @Test public void testQueryPerson_Query_Failure_JAXBException() throws Hl7v3TransformerException, JAXBException, IOException { String expectedErrorMessage = "Query Failure! Server error! A unexpected error has occured"; String hl7v3 = "hl7v3"; when( hl7v3Transformer.getPixQueryXml(MRN, MRN_DOMAIN, Hl7v3Transformer.XML_PIX_QUERY)).thenReturn(hl7v3); when( requestXMLToJava.getPIXQueryReqObject(hl7v3, PixManagerConstants.ENCODE_STRING)).thenThrow( JAXBException.class); PixManagerBean bean = sut.queryPatient(MRN, MRN_DOMAIN); assertEquals(expectedErrorMessage, bean.getQueryMessage()); }
@SuppressWarnings("unchecked") @Test public void testQueryPerson_Query_Failure_IOException() throws Hl7v3TransformerException, JAXBException, IOException { String expectedErrorMessage = "Query Failure! Server error! A unexpected error has occured"; String hl7v3 = "hl7v3"; when( hl7v3Transformer.getPixQueryXml(MRN, MRN_DOMAIN, Hl7v3Transformer.XML_PIX_QUERY)).thenReturn(hl7v3); when( requestXMLToJava.getPIXQueryReqObject(hl7v3, PixManagerConstants.ENCODE_STRING)).thenThrow( IOException.class); PixManagerBean bean = sut.queryPatient(MRN, MRN_DOMAIN); assertEquals(expectedErrorMessage, bean.getQueryMessage()); }