public XDSResponse PatientRegistryRecordAdded(XmlDocument xmlDocPatientRecordAddedRequest) { int patientID = 0; string resultCode = "CA"; string eventOutcomeIndicator = "0"; XDSResponse xdsResponse = null; XmlDocument xmlDocResponse = null; PatientIdentityFeedRecord patientIdentityFeedRecord = null; PatientIdentityFeedDataAccess patientDataAccess = new PatientIdentityFeedDataAccess(); try { xdsResponse = new XDSResponse(); xdsResponse.AtnaParameters = new StringDictionary(); //Parse Xml & get Patient UID patientIdentityFeedRecord = GetPatient(xmlDocPatientRecordAddedRequest); //Insert/Feed Patient UID in the DB //First validates whether the patient uid already exists in the DB if (IsPatientUIDExists(patientIdentityFeedRecord.PatientUID, out patientID)) { patientIdentityFeedRecord.ResultCode = PatientIdentityFeedResultCode.PATIENT_ALREADY_EXISTS; resultCode = "CE"; } else { patientIdentityFeedRecord = patientDataAccess.PatientRegistryRecordAdded(patientIdentityFeedRecord); } } catch (Exception ex) { patientIdentityFeedRecord.ResultCode = PatientIdentityFeedResultCode.FAILURE; resultCode = "CE"; eventOutcomeIndicator = "8"; } //Generate Response Message //xmlDocResponse = ConstructPatientRegistryRecordAddedResponse(patientIdentityFeedRecord); if (patientIdentityFeedRecord.ResultCode != PatientIdentityFeedResultCode.SUCCESS) { resultCode = "CE"; eventOutcomeIndicator = "8"; } xmlDocResponse = ConstructPatientAcknowledgementMessage(xmlDocPatientRecordAddedRequest, resultCode, "PATIENT-ADD-ACK"); xdsResponse.XDSResponseDocument = xmlDocResponse; xdsResponse.AtnaParameters.Add("$EventIdentification.EventOutcomeIndicator$", eventOutcomeIndicator); return(xdsResponse); }
public XmlDocument ConstructPatientAcknowledgementMessage(XmlDocument requestMessage, string resultCode, string patientMessageKey) { XmlDocument xmlDocResponse = null; PatientIdentityFeedDataAccess patientDataAccess = null; PatientMessageConfiguration patientMsgConfig = null; XmlElement root = null; XmlNode node = null; string originalMessageID = null; string interactionIDRoot = null; string receiverRoot = null; string senderRoot = null; //Get Patient Record Added Acknowledgement Message patientDataAccess = new PatientIdentityFeedDataAccess(); patientMsgConfig = patientDataAccess.GetPatientMessageConfiguration(patientMessageKey); root = requestMessage.DocumentElement; //id node = root.SelectSingleNode(".//*[local-name()='id']"); originalMessageID = node.Attributes["root"].Value; //interactionId\root node = root.SelectSingleNode(".//*[local-name()='interactionId']"); interactionIDRoot = node.Attributes["root"].Value; //receiver node = root.SelectSingleNode(".//*[local-name()='receiver']/*[local-name()='device']/*[local-name()='id']"); receiverRoot = node.Attributes["root"].Value; //sender node = root.SelectSingleNode(".//*[local-name()='sender']/*[local-name()='device']/*[local-name()='id']"); senderRoot = node.Attributes["root"].Value; //Replace Values //$NEW.GUID$ patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$NEW.GUID$", Guid.NewGuid().ToString()); //$creationTime$ patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$creationTime$", DateTime.Now.ToString(PATIENT_ACK_DATETIME_FORMAT)); //$INTERACTION.ID$ patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$INTERACTION.ID$", interactionIDRoot); //$RECEIVER.ROOT$ - Swap Sender & Receiver fromthe original message patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$RECEIVER.ROOT$", senderRoot); //$SENDER.ROOT$ - Swap Sender & Receiver fromthe original message patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$SENDER.ROOT$", receiverRoot); //$RESULT.CODE$ patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$RESULT.CODE$", resultCode); //$ORIGINAL.MESSAGE.ID$ patientMsgConfig.PatientMessageValue = patientMsgConfig.PatientMessageValue.Replace("$ORIGINAL.MESSAGE.ID$", originalMessageID); xmlDocResponse = new XmlDocument(); xmlDocResponse.LoadXml(patientMsgConfig.PatientMessageValue); return(xmlDocResponse); }
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); }