use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.
the class EncounterReportBundleServiceTest method shouldMapIncomingReferralWithPractitioners.
@Test
@SuppressWarnings("MagicNumber")
public void shouldMapIncomingReferralWithPractitioners() throws XmlException {
ItkReportHeader itkReportHeader = new ItkReportHeader();
List<Reference> recipients = new ArrayList<>();
when(reference.getResource()).thenReturn(PRACTITIONER);
recipients.add(reference);
REFERRAL_REQUEST.setRecipient(recipients);
Bundle encounterBundle = encounterReportBundleService.createEncounterBundle(document, itkReportHeader, MESSAGEID);
List<BundleEntryComponent> entries = encounterBundle.getEntry();
verifyEntry(entries.get(7), REFERRAL_REQUEST_ID.getValue(), ResourceType.ReferralRequest);
verifyEntry(entries.get(8), PRACTITIONER_ID.getValue(), ResourceType.Practitioner);
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.
the class MessageHeaderServiceTest method shouldCreateMessageHeader.
@Test
public void shouldCreateMessageHeader() {
ItkReportHeader itkReportHeader = new ItkReportHeader();
itkReportHeader.setSpecKey(SPECIFICATION_KEY);
itkReportHeader.setSpecVal(SPECIFICATION_VALUE);
itkReportHeader.setAddressList(Arrays.asList(ADDRESS));
MessageHeader messageHeader = messageHeaderService.createMessageHeader(itkReportHeader, MESSAGEID, EFFECTIVE_TIME);
assertThat(messageHeader.getId()).isEqualTo(MESSAGEID);
Coding event = messageHeader.getEvent();
assertThat(event.getSystem()).isEqualTo(MessageHeaderEvent.SYSTEM);
assertThat(event.getCode()).isEqualTo(DISCHARGE_DETAILS.getCode());
assertThat(event.getDisplay()).isEqualTo(DISCHARGE_DETAILS.getDisplay());
MessageSourceComponent source = messageHeader.getSource();
assertThat(source.getName()).isEqualTo(MESSAGE_SOURCE_NAME);
assertThat(source.getEndpoint()).isEqualTo(ENDPOINT);
assertThat(messageHeader.getReason().getCodingFirstRep().getSystem()).isEqualTo(SPECIFICATION_KEY);
assertThat(messageHeader.getReason().getCodingFirstRep().getCode()).isEqualTo(SPECIFICATION_VALUE);
assertThat(messageHeader.getDestinationFirstRep().getEndpoint()).isEqualTo(ADDRESS);
assertThat(messageHeader.getTimestampElement()).isEqualToComparingFieldByField(DateUtil.parseToInstantType(EFFECTIVE_TIME));
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.
the class ReportController method postReport.
@PostMapping(value = "/report", consumes = { APPLICATION_XML_VALUE, TEXT_XML_VALUE }, produces = TEXT_XML_VALUE)
@ResponseStatus(value = ACCEPTED)
public ResponseEntity<String> postReport(@RequestBody String reportXml) {
String toAddress = null;
String messageId;
try {
ReportItems reportItems = reportParserUtil.parseReportXml(reportXml);
itkValidator.checkItkConformance(reportItems);
soapValidator.checkSoapItkConformance(reportItems.getSoapHeader());
itkAddressValidator.checkItkOdsAndDosId(reportItems.getItkHeader());
ItkReportHeader headerValues = headerParserUtil.getHeaderValues(reportItems.getItkHeader());
toAddress = getValueOrDefaultAddress(reportItems.getSoapAddress());
LOGGER.info("ITK SOAP message received. MessageId: {}, ItkTrackingId: {}", reportItems.getMessageId(), headerValues.getTrackingId());
DistributionEnvelopeDocument distributionEnvelope = reportRequestUtils.extractDistributionEnvelope(reportItems.getDistributionEnvelope());
validate(distributionEnvelope);
POCDMT000002UK01ClinicalDocument1 clinicalDocument = reportRequestUtils.extractClinicalDocument(distributionEnvelope);
validate(clinicalDocument);
encounterReportService.transformAndPopulateToGP(clinicalDocument, reportItems.getMessageId(), headerValues);
return new ResponseEntity<>(itkResponseUtil.createSuccessResponseEntity(reportItems.getMessageId(), randomUUID().toString().toUpperCase()), OK);
} catch (SAXException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "This is not a valid XML message", e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (XmlException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "schema validation failed", e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (ItkXmlException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (SoapClientException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (SoapMustUnderstandException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_MUSTUNDERSTAND, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(toAddress, INTERNAL_PROCESSING_ERROR_CODE, FAULT_CODE_CLIENT, INTERNAL_USER_ERROR_MESSAGE, INTERNAL_ERROR_MESSAGE), INTERNAL_SERVER_ERROR);
}
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.
the class EncounterReportBundleServiceTest method shouldCreateEncounterBundle.
@Test
@SuppressWarnings("MagicNumber")
public void shouldCreateEncounterBundle() throws XmlException {
ItkReportHeader itkReportHeader = new ItkReportHeader();
itkReportHeader.setSpecKey(SPECIFICATION_KEY);
itkReportHeader.setSpecVal(SPECIFICATION_VALUE);
Bundle encounterBundle = encounterReportBundleService.createEncounterBundle(document, itkReportHeader, MESSAGEID);
assertThat(encounterBundle.getType()).isEqualTo(MESSAGE);
assertThat(encounterBundle.getIdentifier().getValue()).isEqualTo(TWO.toString());
assertThat(encounterBundle.getEntry().size()).isEqualTo(22);
List<BundleEntryComponent> entries = encounterBundle.getEntry();
verifyEntry(entries.get(0), MESSAGE_HEADER_ID.getValue(), ResourceType.MessageHeader);
verifyEntry(entries.get(1), ENCOUNTER_ID.getValue(), ResourceType.Encounter);
verifyEntry(entries.get(2), SERVICE_PROVIDER_ID.getValue(), ResourceType.Organization);
verifyEntry(entries.get(3), PRACTITIONER_ID.getValue(), ResourceType.Practitioner);
verifyEntry(entries.get(4), LOCATION_ID.getValue(), ResourceType.Location);
verifyEntry(entries.get(5), PATIENT_ID.getValue(), ResourceType.Patient);
verifyEntry(entries.get(6), HEALTHCARE_SERVICE_ID.getValue(), ResourceType.HealthcareService);
verifyEntry(entries.get(7), REFERRAL_REQUEST_ID.getValue(), ResourceType.ReferralRequest);
verifyEntry(entries.get(8), APPOINTMENT_ID.getValue(), ResourceType.Appointment);
verifyEntry(entries.get(9), COMPOSITION_ID.getValue(), ResourceType.Composition);
verifyEntry(entries.get(10), CAREPLAN_ID.getValue(), ResourceType.CarePlan);
verifyEntry(entries.get(11), CONSENT_ID.getValue(), ResourceType.Consent);
verifyEntry(entries.get(12), CONDITION_ID.getValue(), ResourceType.Condition);
verifyEntry(entries.get(13), QUESTIONNAIRE_RESPONSE_ID.getValue(), ResourceType.QuestionnaireResponse);
verifyEntry(entries.get(14), OBSERVATION_ID.getValue(), ResourceType.Observation);
verifyEntry(entries.get(15), AUTHOR_ROLE_ID.getValue(), ResourceType.PractitionerRole);
verifyEntry(entries.get(16), AUTHOR_ORG_ID.getValue(), ResourceType.Organization);
verifyEntry(entries.get(17), PRACTITIONER_ROLE_ID.getValue(), ResourceType.PractitionerRole);
verifyEntry(entries.get(18), PRACTITIONER_ORG_ID.getValue(), ResourceType.Organization);
verifyEntry(entries.get(19), RELATED_PERSON_ID.getValue(), ResourceType.RelatedPerson);
verifyEntry(entries.get(20), DEVICE_ID.getValue(), ResourceType.Device);
verifyEntry(entries.get(21), LIST_RESOURCE_ID.getValue(), ResourceType.List);
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader in project integration-adaptor-111 by nhsconnect.
the class EncounterReportServiceTest method shouldTransformAndPopulateToGP.
@Test
public void shouldTransformAndPopulateToGP() throws JMSException, XmlException {
ItkReportHeader header = new ItkReportHeader();
header.setTrackingId(TRACKING_ID);
header.setSpecKey(SPECIFICATION_KEY);
header.setSpecVal(SPECIFICATION_VALUE);
POCDMT000002UK01ClinicalDocument1 clinicalDoc = mock(POCDMT000002UK01ClinicalDocument1.class);
Bundle encounterBundle = mock(Bundle.class);
when(encounterReportBundleService.createEncounterBundle(clinicalDoc, header, MESSAGE_ID)).thenReturn(encounterBundle);
IParser parser = mock(IParser.class);
when(fhirContext.newJsonParser()).thenReturn(parser);
when(parser.setPrettyPrint(true)).thenReturn(parser);
when(parser.encodeResourceToString(encounterBundle)).thenReturn(ENCOUNTER_REPORT_MAPPING);
Session session = mock(Session.class);
when(session.createTextMessage(any())).thenReturn(textMessage);
encounterReportService.transformAndPopulateToGP(clinicalDoc, MESSAGE_ID, header);
ArgumentCaptor<MessageCreator> argumentCaptor = ArgumentCaptor.forClass(MessageCreator.class);
verify(jmsTemplate).send(eq(QUEUE_NAME), argumentCaptor.capture());
argumentCaptor.getValue().createMessage(session);
verify(session).createTextMessage(ENCOUNTER_REPORT_MAPPING);
}
Aggregations