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); }
private RegistryXmlEntries UpdatePatientUIDInRegistryXmlEntries(RegistryXmlEntries registryXmlEntries) { XmlDocument xmlDocDocumentEntry = null; XmlDocument xmlDocFolder = null; XmlDocument xmlDocSubmissionSet = null; XmlElement root = null; XmlNode node = null; if (registryXmlEntries == null) { throw new ArgumentNullException("registryXmlEntries"); } if (string.IsNullOrEmpty(registryXmlEntries.PatientUID)) { throw new Exception("registryXmlEntries.PatientUID cannot be null or empty."); } //TABLE::DocumentEntry for (int documentEntryCount = 0; documentEntryCount < registryXmlEntries.DocumentEntryList.Count; documentEntryCount++) { xmlDocDocumentEntry = new XmlDocument(); xmlDocDocumentEntry.LoadXml(registryXmlEntries.DocumentEntryList[documentEntryCount].ExtrinsicObjectXML); root = xmlDocDocumentEntry.DocumentElement; //ExtrinsicObject/Slot(With name attribute equal to 'sourcePatientId')/ValueList/Value node = root.SelectSingleNode("//*[local-name()='ExtrinsicObject']/*[local-name()='Slot'][@name=\"sourcePatientId\"]/*[local-name()='ValueList']/*[local-name()='Value']"); //Updating sourcePatientId value if (node != null) { node.InnerText = registryXmlEntries.PatientUID; } //ExtrinsicObject/ExternalIdentifier(With identificationScheme='urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427')/value=**PATIENTUID** node = root.SelectSingleNode("//*[local-name()='ExtrinsicObject']/*[local-name()='ExternalIdentifier'][@identificationScheme=\"urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427\"]"); if (node != null) { node.Attributes["value"].Value = registryXmlEntries.PatientUID; node = root.SelectSingleNode("//*[local-name()='ExtrinsicObject']"); registryXmlEntries.DocumentEntryList[documentEntryCount].ExtrinsicObjectXML = node.OuterXml; } } //TABLE::DocumentEntry //TABLE::Folder for (int folderCount = 0; folderCount < registryXmlEntries.FolderList.Count; folderCount++) { xmlDocFolder = new XmlDocument(); xmlDocFolder.LoadXml(registryXmlEntries.FolderList[folderCount].FolderXml); root = xmlDocFolder.DocumentElement; //RegistryPackage/ExternalIdentifier(With identificationScheme='urn:uuid:f64ffdf0-4b97-4e06-b79f-a52b38ec2f8a')/value=**PATIENTUID** node = root.SelectSingleNode("//*[local-name()='RegistryPackage']/*[local-name()='ExternalIdentifier'][@identificationScheme=\"urn:uuid:f64ffdf0-4b97-4e06-b79f-a52b38ec2f8a\"]"); if (node != null) { node.Attributes["value"].Value = registryXmlEntries.PatientUID; node = root.SelectSingleNode("//*[local-name()='RegistryPackage']"); registryXmlEntries.FolderList[folderCount].FolderXml = node.OuterXml; } } //TABLE::Folder //TABLE::SubmissionSet for (int submissionSetCount = 0; submissionSetCount < registryXmlEntries.SubmissionSetList.Count; submissionSetCount++) { xmlDocSubmissionSet = new XmlDocument(); xmlDocSubmissionSet.LoadXml(registryXmlEntries.SubmissionSetList[submissionSetCount].SubmissionSetXml); root = xmlDocSubmissionSet.DocumentElement; //RegistryPackage/ExternalIdentifier(With identificationScheme='urn:uuid:6b5aea1a-874d-4603-a4bc-96a0a7b38446')/value=**PATIENTUID** node = root.SelectSingleNode("//*[local-name()='RegistryPackage']/*[local-name()='ExternalIdentifier'][@identificationScheme=\"urn:uuid:6b5aea1a-874d-4603-a4bc-96a0a7b38446\"]"); if (node != null) { node.Attributes["value"].Value = registryXmlEntries.PatientUID; node = root.SelectSingleNode("//*[local-name()='RegistryPackage']"); registryXmlEntries.SubmissionSetList[submissionSetCount].SubmissionSetXml = node.OuterXml; } } //TABLE::SubmissionSet return(registryXmlEntries); }
public RegistryXmlEntries GetRegistryXmlEntries(int patientID) { int resultSetCount = 0; RegistryXmlEntries registryXmlEntries = null; DocumentEntry documentEntry = null; Folder folder = null; SubmissionSet submissionSet = null; Database db = DatabaseFactory.CreateDatabase(CONST_CONNECTIONSTRING_NAME); DbCommand selectCommand = db.GetStoredProcCommand("usp_get_xmlEntries"); db.AddInParameter(selectCommand, "patientID", DbType.Int32, patientID); using (IDataReader dbReader = db.ExecuteReader(selectCommand)) { registryXmlEntries = new RegistryXmlEntries(); do { while (dbReader.Read()) { if (resultSetCount == 0) { documentEntry = new DocumentEntry(); if (!dbReader.IsDBNull(dbReader.GetOrdinal("documentEntryID"))) { documentEntry.ID = dbReader.GetInt32(dbReader.GetOrdinal("documentEntryID")); } if (!dbReader.IsDBNull(dbReader.GetOrdinal("extrinsicObjectXML"))) { documentEntry.ExtrinsicObjectXML = dbReader.GetString(dbReader.GetOrdinal("extrinsicObjectXML")); } registryXmlEntries.DocumentEntryList.Add(documentEntry); } else if (resultSetCount == 1) { folder = new Folder(); if (!dbReader.IsDBNull(dbReader.GetOrdinal("folderID"))) { folder.ID = dbReader.GetInt32(dbReader.GetOrdinal("folderID")); } if (!dbReader.IsDBNull(dbReader.GetOrdinal("folderXml"))) { folder.FolderXml = dbReader.GetString(dbReader.GetOrdinal("folderXml")); } registryXmlEntries.FolderList.Add(folder); } else if (resultSetCount == 2) { submissionSet = new SubmissionSet(); if (!dbReader.IsDBNull(dbReader.GetOrdinal("submissionSetID"))) { submissionSet.ID = dbReader.GetInt32(dbReader.GetOrdinal("submissionSetID")); } if (!dbReader.IsDBNull(dbReader.GetOrdinal("submissionSetXml"))) { submissionSet.SubmissionSetXml = dbReader.GetString(dbReader.GetOrdinal("submissionSetXml")); } registryXmlEntries.SubmissionSetList.Add(submissionSet); } } resultSetCount++; } while (dbReader.NextResult()); } return(registryXmlEntries); }