private PatientDuplicateEntry GetPatientDuplicateEntry(XmlDocument xmlDocRequest) { XmlElement root = null; XmlNodeList nodeListOldPatient = null; XmlNode nodeNewPatient = null; PatientIdentityFeedRecord oldPatientFeedRecord = null; PatientDuplicateEntry patientDuplicateEntry = new PatientDuplicateEntry(); root = xmlDocRequest.DocumentElement; //New Patient UID nodeNewPatient = root.SelectSingleNode(".//*[local-name()='controlActProcess']/*[local-name()='subject']/*[local-name()='registrationEvent']/*[local-name()='subject1']/*[local-name()='patient']/*[local-name()=\"id\"]"); if (nodeNewPatient == null) { throw new Exception("Node registrationEvent does not exists in the request xml."); } //New Patient patientDuplicateEntry.NewPatient = new PatientIdentityFeedRecord(); patientDuplicateEntry.NewPatient.Root = nodeNewPatient.Attributes["root"].Value; patientDuplicateEntry.NewPatient.Extension = nodeNewPatient.Attributes["extension"].Value; //Old Patient UIDs //Commented below line of code during Europe Connect-a-thon //Bug Fixed: Sample xml used during development was incorrect, the new xpath expression gets the patient id //nodeListOldPatient = root.SelectNodes(".//*[local-name()=\"replacementOf\"]/*[local-name()=\"priorRegistration\"]/*[local-name()=\"subject2\"]/*[local-name()=\"priorRegisteredRole\"]/*[local-name()=\"id\"]"); nodeListOldPatient = root.SelectNodes(".//*[local-name()=\"replacementOf\"]/*[local-name()=\"priorRegistration\"]/*[local-name()=\"id\"]"); if (nodeListOldPatient == null) { throw new Exception("Node replacementOf or one it's child nodes does not exists in the request xml."); } //Old Patients patientDuplicateEntry.OldPatientList = new List <PatientIdentityFeedRecord>(); for (int oldPatientCount = 0; oldPatientCount < nodeListOldPatient.Count; oldPatientCount++) { oldPatientFeedRecord = new PatientIdentityFeedRecord(); oldPatientFeedRecord.Root = nodeListOldPatient[oldPatientCount].Attributes["root"].Value; oldPatientFeedRecord.Extension = nodeListOldPatient[oldPatientCount].Attributes["extension"].Value; patientDuplicateEntry.OldPatientList.Add(oldPatientFeedRecord); } return(patientDuplicateEntry); }
public void ProcessPatientDuplicatesResolvedATNAEvent(PatientDuplicateEntry patientDuplicateEntry, string sourceUserID, string destinationUserID, string eventOutcomeIndicator) { try { //Log ATNA - Repository Event ATNALogic atnaLogic = new ATNALogic(); AuditMessageConfiguration auditMsgConfig = null; PatientIdentityFeedRecord patientNotFound = null; if (patientDuplicateEntry != null) { patientNotFound = patientDuplicateEntry.OldPatientList.Find( delegate(PatientIdentityFeedRecord patFeedRecord) { if (patFeedRecord.ResultCode == PatientIdentityFeedResultCode.PATIENT_NOT_FOUND) { return(true); } return(false); } ); if (patientNotFound != null) { eventOutcomeIndicator = "8"; } } //Patient Add/Update ATNA Event auditMsgConfig = atnaLogic.GetAuditMessageConfigurationDetails("REGISTRY-PATIENT-RECORD-DUPLICATES-RESOLVED-UPDATE-ITI-44"); if (auditMsgConfig != null) { auditMsgConfig = ATNALogic.SetParameterValue(auditMsgConfig, "$XDSPatientID$", patientDuplicateEntry.NewPatient.PatientUID); //$ActiveParticipant.UserID.Source$ auditMsgConfig = ATNALogic.SetParameterValue(auditMsgConfig, "$ActiveParticipant.UserID.Source$", sourceUserID); //$ActiveParticipant.UserID.Destination$ auditMsgConfig = ATNALogic.SetParameterValue(auditMsgConfig, "$ActiveParticipant.UserID.Destination$", destinationUserID); //New Patient Add Event atnaLogic.ProcessEvent(auditMsgConfig, ATNAEvent.XDSREGISTRY_TYPE, eventOutcomeIndicator, ATNAEvent.UDP_TAG_APPNAME_REGISTRY); } //Patient Delete ATNA Event auditMsgConfig = atnaLogic.GetAuditMessageConfigurationDetails("REGISTRY-PATIENT-RECORD-DUPLICATES-RESOLVED-DELETE-ITI-44"); if ((auditMsgConfig != null) && (patientNotFound == null)) { //ATNA Log for all the deleted patient uids for (int oldPatientCount = 0; oldPatientCount < patientDuplicateEntry.OldPatientList.Count; oldPatientCount++) { auditMsgConfig = ATNALogic.SetParameterValue(auditMsgConfig, "$XDSPatientID$", patientDuplicateEntry.OldPatientList[oldPatientCount].PatientUID); //$ActiveParticipant.UserID.Destination$ auditMsgConfig = ATNALogic.SetParameterValue(auditMsgConfig, "$ActiveParticipant.UserID.Destination$", ATNAEvent.XDSREGISTRY_SERVICE_ADDRESS); //Old Patient Delete Event atnaLogic.ProcessEvent(auditMsgConfig, ATNAEvent.XDSREGISTRY_TYPE, "0", ATNAEvent.UDP_TAG_APPNAME_REGISTRY); } } } catch { //Oops...ATNA event failed...probably UDP failure....can't afford to stop XDSRepository service sorry :( } }
public XDSResponse PatientRegistryDuplicatesResolved(XmlDocument xmlDocRequest, out PatientDuplicateEntry oldPatientDuplicateEntry) { XDSResponse xdsResponse = null; XmlDocument xmlDocResponse = null; PatientDuplicateEntry patientDuplicateEntry = null; PatientIdentityFeedDataAccess patientDataAccess = null; List <RegistryXmlEntries> registryXmlEntriesList = null; RegistryXmlEntries registryXmlEntry = null; int newPatientID = 0; int oldPatientID = 0; string resultCode = "CA"; string eventOutcomeIndicator = "0"; oldPatientDuplicateEntry = new PatientDuplicateEntry(); try { xdsResponse = new XDSResponse(); xdsResponse.AtnaParameters = new StringDictionary(); patientDataAccess = new PatientIdentityFeedDataAccess(); //Gets the Primary & Replacement Of Patient Entries from the xml patientDuplicateEntry = GetPatientDuplicateEntry(xmlDocRequest); oldPatientDuplicateEntry = patientDuplicateEntry; //New Patient ID IsPatientUIDExists(patientDuplicateEntry.NewPatient.PatientUID, out newPatientID); //PatientUID does not exist if (newPatientID == 0) { //Generate Response Message xmlDocResponse = ConstructPatientAcknowledgementMessage(xmlDocRequest, "CE", "PATIENT-DUPLICATES-RESOLVED-ACK"); xdsResponse.XDSResponseDocument = xmlDocResponse; //ATNA eventOutcomeIndicator = "8"; xdsResponse.AtnaParameters.Add("$EventIdentification.EventOutcomeIndicator$", eventOutcomeIndicator); return(xdsResponse); } else { patientDuplicateEntry.NewPatient.PatientID = newPatientID; } //Old Patient IDs registryXmlEntriesList = new List <RegistryXmlEntries>(); for (int oldPatientCount = 0; oldPatientCount < patientDuplicateEntry.OldPatientList.Count; oldPatientCount++) { IsPatientUIDExists(patientDuplicateEntry.OldPatientList[oldPatientCount].PatientUID, out oldPatientID); //Patient Does Not Exists, Stop processing the request & respond with a failure message if (oldPatientID <= 0) { patientDuplicateEntry.OldPatientList[oldPatientCount].ResultCode = PatientIdentityFeedResultCode.PATIENT_NOT_FOUND; //Generate Response Message xmlDocResponse = ConstructPatientAcknowledgementMessage(xmlDocRequest, "CE", "PATIENT-DUPLICATES-RESOLVED-ACK"); xdsResponse.XDSResponseDocument = xmlDocResponse; //ATNA eventOutcomeIndicator = "8"; xdsResponse.AtnaParameters.Add("$EventIdentification.EventOutcomeIndicator$", eventOutcomeIndicator); return(xdsResponse); } patientDuplicateEntry.OldPatientList[oldPatientCount].PatientID = oldPatientID; //Get xml entries from registry tables registryXmlEntry = new RegistryXmlEntries(); registryXmlEntry = patientDataAccess.GetRegistryXmlEntries(patientDuplicateEntry.OldPatientList[oldPatientCount].PatientID); registryXmlEntriesList.Add(registryXmlEntry); } if (registryXmlEntriesList != null && registryXmlEntriesList.Count != 0) { for (int count = 0; count < registryXmlEntriesList.Count; count++) { registryXmlEntriesList[count].PatientUID = patientDuplicateEntry.NewPatient.PatientUID; registryXmlEntriesList[count] = UpdatePatientUIDInRegistryXmlEntries(registryXmlEntriesList[count]); } } //Transaction Scope - Start using (TransactionScope ts = new TransactionScope()) { for (int patientCount = 0; patientCount < patientDuplicateEntry.OldPatientList.Count; patientCount++) { //Update the Patient IDs in all the referecing tables patientDataAccess.UpdateRegistryPatientID(patientDuplicateEntry.OldPatientList[patientCount].PatientUID, patientDuplicateEntry.NewPatient.PatientUID); //Delete Patient patientDataAccess.DeleteRegistryPatientUID(patientDuplicateEntry.OldPatientList[patientCount].PatientUID); } for (int registryXmlCount = 0; registryXmlCount < registryXmlEntriesList.Count; registryXmlCount++) { //Update Xml Data stored in tables with new PatientUIDs //TABLES: //TABLE::DocumentEntry // -- sourcePatientId // -- extrinsicObjectXML // ----> sourcePatientId // ----> value (Example: <ExternalIdentifier id="urn:uuid:9afb1c3f-942c-6676-77e2-38fdc3f32a47" registryObject="theDocument" identificationScheme="urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427" value="$PatientId">) patientDataAccess.UpdateDocumentEntryPatientUID(registryXmlEntriesList[registryXmlCount].PatientUID, registryXmlEntriesList[registryXmlCount].DocumentEntryList); //TABLE::Folder // -- folderXml // ----> value (Example: <ExternalIdentifier id="urn:uuid:2876acb1-e84c-9fe4-d356-f98d6e8afd82" registryObject="Folder" identificationScheme="urn:uuid:f64ffdf0-4b97-4e06-b79f-a52b38ec2f8a" value="$PatientId">) patientDataAccess.UpdateFolderPatientUID(registryXmlEntriesList[registryXmlCount].FolderList); //TABLE::SubmissionSet // -- submissionSet // ----> value (Example: <ExternalIdentifier id="urn:uuid:6e11c871-91c3-0206-9df2-0cb245d2e888" registryObject="SubmissionSet06" identificationScheme="urn:uuid:6b5aea1a-874d-4603-a4bc-96a0a7b38446" value="$PatientId">) patientDataAccess.UpdateSubmissionSetPatientUID(registryXmlEntriesList[registryXmlCount].SubmissionSetList); } //Commit ts.Complete(); } //Transaction Scope - End } catch { resultCode = "CE"; eventOutcomeIndicator = "8"; } //ATNA xdsResponse.AtnaParameters.Add("$EventIdentification.EventOutcomeIndicator$", eventOutcomeIndicator); //Generate Response Message xmlDocResponse = ConstructPatientAcknowledgementMessage(xmlDocRequest, resultCode, "PATIENT-DUPLICATES-RESOLVED-ACK"); xdsResponse.XDSResponseDocument = xmlDocResponse; return(xdsResponse); }
Message IDocumentRegistry.PatientRegistryDuplicatesResolved(System.ServiceModel.Channels.Message input) { Message msgResult = null; XmlDocument xmlDocRequest = null; XmlDocument xmlDocResponse = null; XDSResponse xdsResponse = null; PatientDuplicateEntry patientDuplicateEntry = null; PatientIdentityFeedLogic patientFeedLogic = null; RegistryLogic objRegistryLogic = null; string eventOutcomeIndicator = "0"; string sourceUserID = string.Empty; string destinationUserID = string.Empty; try { //ATNA Event - Active Participant Source UserID sourceUserID = GetSourceUserID(); //ATNA Event - Active Participant Destination UserID destinationUserID = GetDestinationUserID(); xdsResponse = new XDSResponse(); xmlDocRequest = new XmlDocument(); xmlDocRequest.Load(input.GetReaderAtBodyContents()); objRegistryLogic = new RegistryLogic(); patientFeedLogic = new PatientIdentityFeedLogic(); xdsResponse = patientFeedLogic.PatientRegistryDuplicatesResolved(xmlDocRequest, out patientDuplicateEntry); xmlDocResponse = xdsResponse.XDSResponseDocument; //ATNA eventOutcomeIndicator = xdsResponse.AtnaParameters["$EventIdentification.EventOutcomeIndicator$"]; } catch (Exception) { //Log Error objRegistryLogic.CreateRegistryLogEntry(xmlDocRequest.InnerXml, GlobalValues.CONST_RESPONSE_STATUS_TYPE_FAILURE, DateTime.Now); eventOutcomeIndicator = "8"; } //Log ATNA Event if (patientDuplicateEntry != null) { patientFeedLogic.ProcessPatientDuplicatesResolvedATNAEvent(patientDuplicateEntry, sourceUserID, destinationUserID, eventOutcomeIndicator); } //Create Soap Message msgResult = Message.CreateMessage(input.Headers.MessageVersion, GlobalValues.CONST_ACTION_PatientIdentityFeedResponse, new XmlNodeReader(xmlDocResponse)); return(msgResult); }