/// <summary> /// Get discrete records by id /// </summary> public RegistryQueryResult Get(VersionedDomainIdentifier[] regEvtIds, RegistryQueryRequest qd) { RegistryQueryResult retVal = new RegistryQueryResult(); try { List <VersionedDomainIdentifier> retRecordId = new List <VersionedDomainIdentifier>(100); // Query continuation if (this.m_queryPersistence != null && this.m_queryPersistence.IsRegistered(qd.QueryId.ToLower())) { throw new Exception(String.Format("The query '{0}' has already been registered. To continue this query use the QUQI_IN000003CA interaction", qd.QueryId)); } else { retVal.Results = this.GetRecordsAsync(regEvtIds, retRecordId, qd, retVal.Details); // Get the count of not-included records retVal.Results.RemoveAll(o => o == null); // Persist the query if (this.m_queryPersistence != null) { this.m_queryPersistence.RegisterQuerySet(qd.QueryId.ToLower(), regEvtIds, qd); } // Return query data retVal.TotalResults = retRecordId.Count(o => o != null); } } catch (TimeoutException ex) { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); } catch (DbException ex) { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); } catch (DataException ex) { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); } catch (Exception ex) { Trace.TraceError(ex.ToString()); retVal.Details.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex)); } return(retVal); }
/// <summary> /// Create the RSP_K23 mesasge /// </summary> public NHapi.Model.V25.Message.RSP_K23 CreateRSP_K23(RegistryQueryResult result, List <Everest.Connectors.IResultDetail> dtls) { // Return value var retVal = new NHapi.Model.V25.Message.RSP_K23(); retVal.MSH.MessageType.MessageStructure.Value = "RSP_K23"; retVal.MSH.MessageType.TriggerEvent.Value = "K23"; var qak = retVal.QAK; var msa = retVal.MSA; qak.QueryTag.Value = result.QueryTag; msa.AcknowledgmentCode.Value = "AA"; if (dtls.Exists(o => o.Type == Everest.Connectors.ResultDetailType.Error)) { qak.QueryResponseStatus.Value = "AE"; msa.AcknowledgmentCode.Value = "AE"; foreach (var dtl in dtls) { var err = retVal.GetStructure("ERR", retVal.currentReps("ERR")) as NHapi.Model.V25.Segment.ERR; MessageUtil.UpdateERR(err, dtl, Context); } } else if (result.Results == null || result.Results.Count == 0) { qak.QueryResponseStatus.Value = "NF"; } else { // Create the pid qak.QueryResponseStatus.Value = "OK"; UpdatePID(result.Results[0] as RegistrationEvent, retVal.QUERY_RESPONSE.PID, true); } return(retVal); }
/// <summary> /// Create the response message /// </summary> public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <IResultDetail> dtls) { // GEt the config services ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; ILocalizationService localeService = Context.GetService(typeof(ILocalizationService)) as ILocalizationService; var retHl7v3 = new List <MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object> >(results.Results.Count); UvDeComponentUtil dCompUtil = new UvDeComponentUtil(); dCompUtil.Context = this.Context; PRPA_IN201309UV02 rqst = request as PRPA_IN201309UV02; // Convert results to HL7v3 foreach (RegistrationEvent res in results.Results) { var retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>( false, dCompUtil.CreateRegistrationEventDetail(res, dtls) ); if (retRec.RegistrationEvent == null) { retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>( false, new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.RegistrationEvent <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>() { NullFlavor = NullFlavor.NoInformation } ); } retHl7v3.Add(retRec); } if (retHl7v3.Count > 1) { dtls.Add(new InsufficientRepetitionsResultDetail(ResultDetailType.Warning, localeService.GetString("MSGE06E"), null)); } // Create the response PRPA_IN201310UV02 response = new PRPA_IN201310UV02 ( Guid.NewGuid(), DateTime.Now, PRPA_IN201310UV02.GetInteractionId(), ProcessingID.Production, "T", AcknowledgementCondition.Never, MessageUtil.CreateReceiver(rqst.Sender), MessageUtil.CreateSenderUv(new Uri(rqst.Receiver[0].Telecom.Value), configService), null ) { Acknowledgement = new List <MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement>() { new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement( dtls.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError, new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id) ) } }; response.controlActProcess = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201307UV02.QueryByParameter, MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>("EVN") { Id = SET <II> .CreateSET(new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString())), Code = new CD <string>(PRPA_IN201310UV02.GetTriggerEvent().Code, PRPA_IN201310UV02.GetTriggerEvent().CodeSystem), QueryAck = new MARC.Everest.RMIM.UV.NE2008.QUQI_MT120001UV01.QueryAck( rqst.controlActProcess.queryByParameter.QueryId, "complete", (AcknowledgementType)response.Acknowledgement[0].TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : results.TotalResults == 0 ? QueryResponse.NoDataFound : QueryResponse.DataFound, results.TotalResults, results.Results.Count, results.TotalResults - results.Results.Count - results.StartRecordNumber ), queryByParameter = rqst.controlActProcess.queryByParameter }; response.controlActProcess.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context); if (retHl7v3.Count > 0) { response.controlActProcess.Subject.Add(retHl7v3[0]); } return(response); }
/// <summary> /// Create the interaction type /// </summary> public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <IResultDetail> dtls) { // GEt the config services ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; var retHl7v3 = new List <MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object> >(); //List<MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2<MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>> retHl7v3 = new List<MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2<MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>>(results.Results.Count()); UvDeComponentUtil dCompUtil = new UvDeComponentUtil(); dCompUtil.Context = this.Context; PRPA_IN201305UV02 rqst = request as PRPA_IN201305UV02; // Convert results to HL7v3 foreach (RegistrationEvent res in results.Results) { var retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>( true, dCompUtil.CreateRegistrationEvent(res, dtls) ); if (retRec.RegistrationEvent == null) { retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>( false, new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.RegistrationEvent <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>() { NullFlavor = NullFlavor.NoInformation } ); } retHl7v3.Add(retRec); } // HACK: Sort by confidence score (if present) //retHl7v3.Sort((a, b) => // a != null && b != null && // a.RegistrationEvent != null && b.RegistrationEvent != null && // a.RegistrationEvent.Subject1 != null && b.RegistrationEvent.Subject1 != null && // a.RegistrationEvent.Subject1.registeredRole != null && b.RegistrationEvent.Subject1.registeredRole != null && // (a.RegistrationEvent.Subject1.registeredRole.SubjectOf1.Count > 0) && (b.RegistrationEvent.Subject1.registeredRole.SubjectOf1.Count > 0) ? // (b.RegistrationEvent.Subject1.registeredRole.SubjectOf1[0].QueryMatchObservation.Value as INT).CompareTo((a.RegistrationEvent.Subject1.registeredRole.SubjectOf1[0].QueryMatchObservation.Value as INT)) : 0); // Create the response PRPA_IN201306UV02 response = new PRPA_IN201306UV02 ( Guid.NewGuid(), DateTime.Now, PRPA_IN201306UV02.GetInteractionId(), ProcessingID.Production, "T", AcknowledgementCondition.Never, MessageUtil.CreateReceiver(rqst.Sender), MessageUtil.CreateSenderUv(new Uri(rqst.Receiver[0].Telecom.Value), configService), null ) { Acknowledgement = new List <MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement>() { new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement( dtls.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError, new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id) ) } }; response.controlActProcess = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter, MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>("EVN") { Id = SET <II> .CreateSET(new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString())), Code = new CD <string>(PRPA_IN201306UV02.GetTriggerEvent().Code, PRPA_IN201306UV02.GetTriggerEvent().CodeSystem), QueryAck = new MARC.Everest.RMIM.UV.NE2008.QUQI_MT120001UV01.QueryAck( rqst.controlActProcess.queryByParameter.QueryId, "complete", (AcknowledgementType)response.Acknowledgement[0].TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : results.TotalResults == 0 ? QueryResponse.NoDataFound : QueryResponse.DataFound, results.TotalResults, results.Results.Count, results.TotalResults - results.Results.Count - results.StartRecordNumber ), queryByParameter = rqst.controlActProcess.queryByParameter }; response.controlActProcess.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context); if (retHl7v3.Count > 0) { response.controlActProcess.Subject.AddRange(retHl7v3); } return(response); }
/// <summary> /// Create audit data /// </summary> public AuditData CreateAuditData(string itiName, ActionType action, OutcomeIndicator outcome, Hl7MessageReceivedEventArgs msgEvent, RegistryQueryResult result) { // Create the call to the other create audit data message by constructing the list of disclosed identifiers List <VersionedDomainIdentifier> vids = new List <VersionedDomainIdentifier>(result.Results.Count); foreach (var res in result.Results) { if (res == null) { continue; } var subj = res.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as Person; if (subj == null) { continue; } vids.Add(new VersionedDomainIdentifier() { Domain = this.m_configService.OidRegistrar.GetOid("CR_CID").Oid, Identifier = subj.Id.ToString() }); } return(CreateAuditData(itiName, action, outcome, msgEvent, vids)); }
/// <summary> /// Create the interaction /// </summary> public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <MARC.Everest.Connectors.IResultDetail> details) { // GEt the config services ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; List <MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity> > retHl7v3 = new List <MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity> >(results.Results.Count()); CaDeComponentUtil dCompUtil = new CaDeComponentUtil(); dCompUtil.Context = this.Context; PRPA_IN101103CA rqst = request as PRPA_IN101103CA; // Convert results to HL7v3 foreach (RegistrationEvent res in results.Results) { var retRec = new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>( dCompUtil.CreateRegistrationEvent(res, details) ); if (retRec.RegistrationEvent == null) { retRec = new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>( new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.RegistrationEvent <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>() { NullFlavor = NullFlavor.NoInformation } ); } retHl7v3.Add(retRec); } // HACK: Sort by confidence score (if present) retHl7v3.Sort((a, b) => b.RegistrationEvent.Subject.registeredRole.SubjectOf.ObservationEvent.Value.CompareTo(a.RegistrationEvent.Subject.registeredRole.SubjectOf.ObservationEvent.Value)); // Create the response PRPA_IN101104CA response = new PRPA_IN101104CA ( Guid.NewGuid(), DateTime.Now, ResponseMode.Immediate, PRPA_IN101104CA.GetInteractionId(), PRPA_IN101104CA.GetProfileId(), ProcessingID.Production, AcknowledgementCondition.Never, MessageUtil.CreateReceiver(rqst.Sender), MessageUtil.CreateSender(rqst.Receiver.Telecom == null ? null : new Uri(rqst.Receiver.Telecom.Value), configService), new MARC.Everest.RMIM.CA.R020403.MCCI_MT002200CA.Acknowledgement( details.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError, new MARC.Everest.RMIM.CA.R020403.MCCI_MT002200CA.TargetMessage(request.Id) ) ); response.Acknowledgement.AcknowledgementDetail = MessageUtil.CreateAckDetails(details.ToArray()); response.controlActEvent = PRPA_IN101104CA.CreateControlActEvent( new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString()), PRPA_IN101104CA.GetTriggerEvent(), new MARC.Everest.RMIM.CA.R020403.QUQI_MT120008CA.QueryAck( rqst.controlActEvent.QueryByParameter.QueryId, results.TotalResults == 0 ? QueryResponse.NoDataFound : (AcknowledgementType)response.Acknowledgement.TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : QueryResponse.DataFound, results.TotalResults, results.Results.Count, results.TotalResults - results.Results.Count - results.StartRecordNumber ), rqst.controlActEvent.QueryByParameter ); response.controlActEvent.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context); if (details.Count(o => o is DetectedIssueResultDetail) > 0) { response.controlActEvent.SubjectOf.AddRange(MessageUtil.CreateDetectedIssueEventsQuery(details.OfType <DetectedIssueResultDetail>().Select(o => o.Issue).ToList())); } response.controlActEvent.Subject.AddRange(retHl7v3); return(response); }
/// <summary> /// Create RSP_K21 message /// </summary> internal NHapi.Base.Model.IMessage CreateRSP_K21(RegistryQueryResult result, RegistryQueryRequest filter, List <Everest.Connectors.IResultDetail> dtls) { // Return value var retVal = new NHapi.Model.V25.Message.RSP_K21(); retVal.MSH.MessageType.MessageStructure.Value = "RSP_K21"; var qak = retVal.QAK; var msa = retVal.MSA; var dsc = retVal.DSC; var qpd = retVal.QPD; qak.QueryTag.Value = result.QueryTag; msa.AcknowledgmentCode.Value = "AA"; if (dtls.Exists(o => o.Type == Everest.Connectors.ResultDetailType.Error)) { qak.QueryResponseStatus.Value = "AE"; msa.AcknowledgmentCode.Value = "AE"; foreach (var dtl in dtls) { var err = retVal.GetStructure("ERR", retVal.currentReps("ERR")) as NHapi.Model.V25.Segment.ERR; MessageUtil.UpdateERR(err, dtl, Context); } } else if (result.Results == null || result.Results.Count == 0) { qak.QueryResponseStatus.Value = "NF"; } else { // Create the pid qak.QueryResponseStatus.Value = "OK"; qak.HitCount.Value = result.TotalResults.ToString(); qak.ThisPayload.Value = result.Results.Count.ToString(); //qak.HitsRemaining.Value = (result.TotalResults - result.StartRecordNumber).ToString(); foreach (RegistrationEvent res in result.Results) { var pid = retVal.GetQUERY_RESPONSE(retVal.QUERY_RESPONSERepetitionsUsed); UpdatePID(res, pid.PID, false); UpdateQRI(res, pid.QRI); pid.PID.SetIDPID.Value = retVal.QUERY_RESPONSERepetitionsUsed.ToString(); } // DSC segment? if (result.TotalResults > result.Results.Count) { retVal.DSC.ContinuationPointer.Value = result.ContinuationPtr; retVal.DSC.ContinuationStyle.Value = "I"; } } // Actual query paramaeters var regFilter = filter.QueryRequest.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as RegistrationEvent; var personFilter = regFilter.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as Person; qpd.QueryTag.Value = filter.QueryTag; qpd.MessageQueryName.Identifier.Value = "IHE PDQ Query"; var terser = new Terser(retVal); int qpdRep = 0; if (personFilter.GenderCode != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.8"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), personFilter.GenderCode); } if (personFilter.AlternateIdentifiers != null && personFilter.AlternateIdentifiers.Count > 0) { var altId = personFilter.AlternateIdentifiers[0]; if (altId.Domain != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.2"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Domain); terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.3"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), "ISO"); } if (altId.Identifier != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Identifier); } if (altId.AssigningAuthority != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.AssigningAuthority); } } if (personFilter.Names != null && personFilter.Names.Count > 0) { var name = personFilter.Names[0]; foreach (var pt in name.Parts) { string pidNo = ComponentUtility.XPN_MAP.First(o => o.Value == pt.Type).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.5.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.Value); } if (name.Use != NameSet.NameSetUse.Search) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.5.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), ComponentUtility.XPN_USE_MAP.First(o => o.Value == name.Use).Key); } } if (personFilter.BirthTime != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), new TS(personFilter.BirthTime.Value).Value); } if (personFilter.Addresses != null && personFilter.Addresses.Count > 0) { var addr = personFilter.Addresses[0]; foreach (var pt in addr.Parts) { string pidNo = ComponentUtility.AD_MAP.First(o => o.Value == pt.PartType).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.11.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.AddressValue); } if (addr.Use != AddressSet.AddressSetUse.Search) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.11.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), ComponentUtility.AD_USE_MAP.First(o => o.Value == addr.Use).Key); } } var ma = personFilter.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.RepresentitiveOf) as PersonalRelationship; if (ma != null) { if (ma.LegalName != null) { foreach (var pt in ma.LegalName.Parts) { string pidNo = ComponentUtility.XPN_MAP.First(o => o.Value == pt.Type).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.6.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.Value); } } if (ma.AlternateIdentifiers != null && ma.AlternateIdentifiers.Count > 0) { var altId = ma.AlternateIdentifiers[0]; if (altId.Domain != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.2"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Domain); terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.3"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), "ISO"); } if (altId.Identifier != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Identifier); } if (altId.AssigningAuthority != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.AssigningAuthority); } } } return(retVal); }
/// <summary> /// Handle a PIX query /// </summary> private IMessage HandlePixQuery(NHapi.Model.V25.Message.QBP_Q21 request, Hl7MessageReceivedEventArgs evt) { // Get config var config = this.Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; var locale = this.Context.GetService(typeof(ILocalizationService)) as ILocalizationService; var dataService = this.Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; // Create a details array List <IResultDetail> dtls = new List <IResultDetail>(); // Validate the inbound message MessageUtil.Validate((IMessage)request, config, dtls, this.Context); IMessage response = null; // Control if (request == null) { return(null); } // Construct appropriate audit AuditData audit = null; // Data controller AuditUtil auditUtil = new AuditUtil() { Context = this.Context }; //DataUtil dataUtil = new DataUtil() { Context = this.Context }; try { // Create Query Data ComponentUtility cu = new ComponentUtility() { Context = this.Context }; DeComponentUtility dcu = new DeComponentUtility() { Context = this.Context }; var data = cu.CreateQueryComponents(request, dtls); if (data == null) { throw new InvalidOperationException(locale.GetString("MSGE00A")); } RegistryQueryResult result = dataService.Query(data); dtls.AddRange(result.Details); // Update locations? foreach (var dtl in dtls) { if (dtl is PatientNotFoundResultDetail) { dtl.Location = "QPD^1^3^1^1"; } else if (dtl is UnrecognizedPatientDomainResultDetail) { dtl.Location = "QPD^1^3^1^4"; } else if (dtl is UnrecognizedTargetDomainResultDetail) { dtl.Location = "QPD^1^4^"; } } audit = auditUtil.CreateAuditData("ITI-9", ActionType.Execute, OutcomeIndicator.Success, evt, result); // Now process the result response = dcu.CreateRSP_K23(result, dtls); //var r = dcu.CreateRSP_K23(null, null); // Copy QPD try { (response as NHapi.Model.V25.Message.RSP_K23).QPD.MessageQueryName.Identifier.Value = request.QPD.MessageQueryName.Identifier.Value; Terser reqTerser = new Terser(request), rspTerser = new Terser(response); rspTerser.Set("/QPD-1", reqTerser.Get("/QPD-1")); rspTerser.Set("/QPD-2", reqTerser.Get("/QPD-2")); rspTerser.Set("/QPD-3-1", reqTerser.Get("/QPD-3-1")); rspTerser.Set("/QPD-3-4-1", reqTerser.Get("/QPD-3-4-1")); rspTerser.Set("/QPD-3-4-2", reqTerser.Get("/QPD-3-4-2")); rspTerser.Set("/QPD-3-4-3", reqTerser.Get("/QPD-3-4-3")); rspTerser.Set("/QPD-4-1", reqTerser.Get("/QPD-4-1")); rspTerser.Set("/QPD-4-4-1", reqTerser.Get("/QPD-4-4-1")); rspTerser.Set("/QPD-4-4-2", reqTerser.Get("/QPD-4-4-2")); rspTerser.Set("/QPD-4-4-3", reqTerser.Get("/QPD-4-4-3")); } catch (Exception e) { Trace.TraceError(e.ToString()); } //MessageUtil.((response as NHapi.Model.V25.Message.RSP_K23).QPD, request.QPD); MessageUtil.UpdateMSH(new NHapi.Base.Util.Terser(response), request, config); } catch (Exception e) { Trace.TraceError(e.ToString()); if (!dtls.Exists(o => o is UnrecognizedPatientDomainResultDetail || o is UnrecognizedTargetDomainResultDetail || o.Message == e.Message || o.Exception == e)) { dtls.Add(new ResultDetail(ResultDetailType.Error, e.Message, e)); } response = MessageUtil.CreateNack(request, dtls, this.Context, typeof(RSP_K23)); Terser errTerser = new Terser(response); // HACK: Fix the generic ACK with a real ACK for this message errTerser.Set("/MSH-9-2", "K23"); errTerser.Set("/MSH-9-3", "RSP_K23"); errTerser.Set("/QAK-2", "AE"); errTerser.Set("/MSA-1", "AE"); errTerser.Set("/QAK-1", request.QPD.QueryTag.Value); audit = auditUtil.CreateAuditData("ITI-9", ActionType.Execute, OutcomeIndicator.EpicFail, evt, new List <VersionedDomainIdentifier>()); } finally { IAuditorService auditSvc = this.Context.GetService(typeof(IAuditorService)) as IAuditorService; if (auditSvc != null) { auditSvc.SendAudit(audit); } } return(response); }
/// <summary> /// Query for a series of results which match the query parameter /// </summary> public RegistryQueryResult Query(RegistryQueryRequest query) { RegistryQueryResult retVal = new RegistryQueryResult(); try { List <VersionedDomainIdentifier> returnedRecordIdentifiers = new List <VersionedDomainIdentifier>(100); // Query continuation? if (this.m_registrationService == null) { throw new InvalidOperationException("No record registration service is registered. Querying for records cannot be done unless this service is configured"); } else if (query.IsContinue) // Continuation { // Sanity check, ensure the query exists! if (this.m_queryPersistence == null || !this.m_queryPersistence.IsRegistered(query.QueryId)) { retVal.Details.Add(new ValidationResultDetail(ResultDetailType.Error, String.Format("The query {0} has not been registered", query.QueryId), null, null)); throw new InvalidOperationException("Cannot conitnue query due to errors"); } // sanity check // Validate the sender RegistryQueryRequest queryTag = (RegistryQueryRequest)this.m_queryPersistence.GetQueryTag(query.QueryId); retVal.OriginalRequestId = queryTag.OriginalMessageQueryId; if (query.Originator != queryTag.Originator) { retVal.Details.Add(new UnrecognizedSenderResultDetail(new DomainIdentifier() { Domain = query.Originator })); throw new SecurityException("Sender mismatch"); } // Return value retVal.Results = this.GetRecordsAsync(this.m_queryPersistence.GetQueryResults(query.QueryId, query.Offset, query.Limit), returnedRecordIdentifiers, query, retVal.Details); // Return continued query retVal.TotalResults = (int)this.m_queryPersistence.QueryResultTotalQuantity(query.QueryId); } else if (this.m_queryPersistence != null && this.m_queryPersistence.IsRegistered(query.QueryId) && !query.IsContinue) { throw new Exception(String.Format("The query '{0}' has already been registered. To continue this query use the appropriate interaction", query.QueryId)); } else { VersionedDomainIdentifier[] recordIds = this.m_registrationService.QueryRecord(query.QueryRequest as QueryEvent); // Persist the query if (!String.IsNullOrEmpty(query.QueryId) && this.m_queryPersistence != null && recordIds.Length > query.Limit) { this.m_queryPersistence.RegisterQuerySet(query.QueryId, recordIds, query); this.m_queryPersistence.GetQueryResults(query.QueryId, query.Offset, query.Limit); } retVal.TotalResults = recordIds.Length; // Get the results recordIds = recordIds.Skip(query.Offset).Take(query.Limit).ToArray(); retVal.Results = this.GetRecordsAsync(recordIds, returnedRecordIdentifiers, query, retVal.Details); if (retVal.Results.Count == 0 && query.IsSummary) { retVal.Details.Add(new PatientNotFoundResultDetail(this.m_localeService)); } // Sort control? TODO: Support sort control } retVal.ContinuationPtr = query.QueryId; retVal.QueryTag = query.QueryTag; return(retVal); } catch (TimeoutException ex) { retVal.Details.Add(new PersistenceResultDetail(Everest.Connectors.ResultDetailType.Error, ex.Message, ex)); throw; } catch (DbException ex) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); throw; } catch (DataException ex) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); throw; } catch (Exception ex) { retVal.Details.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex)); throw; } }
/// <summary> /// Handle the pdq query /// </summary> private IMessage HandlePdqQuery(QBP_Q21 request, Hl7MessageReceivedEventArgs evt) { // Get config var config = this.Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; var locale = this.Context.GetService(typeof(ILocalizationService)) as ILocalizationService; var dataService = this.Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; // Create a details array List <IResultDetail> dtls = new List <IResultDetail>(); // Validate the inbound message MessageUtil.Validate((IMessage)request, config, dtls, this.Context); IMessage response = null; // Control if (request == null) { return(null); } // Data controller //DataUtil dataUtil = new DataUtil() { Context = this.Context }; AuditUtil auditUtil = new AuditUtil() { Context = this.Context }; // Construct appropriate audit AuditData audit = null; try { // Create Query Data ComponentUtility cu = new ComponentUtility() { Context = this.Context }; DeComponentUtility dcu = new DeComponentUtility() { Context = this.Context }; var data = cu.CreateQueryComponentsPdq(request, dtls); if (data == null) { Trace.TraceError("{0} problems mapping message:", dtls.Count); foreach (var itm in dtls) { Trace.TraceError($"\t{itm.Type} : {itm.Message}"); } throw new InvalidOperationException();// locale?.GetString("MSGE00A") ?? "Could not process components"); } // Is this a continue or new query? RegistryQueryResult result = dataService.Query(data); audit = auditUtil.CreateAuditData("ITI-21", ActionType.Execute, OutcomeIndicator.Success, evt, result); // Now process the result response = dcu.CreateRSP_K21(result, data, dtls); //MessageUtil.CopyQPD((response as RSP_K21).QPD, request.QPD, data); MessageUtil.UpdateMSH(new NHapi.Base.Util.Terser(response), request, config); Terser ters = new Terser(response); ters.Set("/MSH-9-2", "K22"); } catch (Exception e) { Trace.TraceError(e.ToString()); if (!dtls.Exists(o => o.Message == e.Message || o.Exception == e)) { if (dtls.Count == 0) { dtls.Add(new ResultDetail(ResultDetailType.Error, e.Message, e)); } } // HACK: Only one error allowed in nHAPI for some reason : // TODO: Fix NHapi dtls.RemoveAll(o => o.Type != ResultDetailType.Error); while (dtls.Count > 1) { dtls.RemoveAt(1); } response = MessageUtil.CreateNack(request, dtls, this.Context, typeof(RSP_K21)); Terser errTerser = new Terser(response); // HACK: Fix the generic ACK with a real ACK for this message errTerser.Set("/MSH-9-2", "K22"); errTerser.Set("/MSH-9-3", "RSP_K21"); errTerser.Set("/QAK-2", "AE"); errTerser.Set("/MSA-1", "AE"); errTerser.Set("/QAK-1", request.QPD.QueryTag.Value); audit = auditUtil.CreateAuditData("ITI-21", ActionType.Execute, OutcomeIndicator.EpicFail, evt, new List <VersionedDomainIdentifier>()); } finally { IAuditorService auditSvc = this.Context.GetService(typeof(IAuditorService)) as IAuditorService; if (auditSvc != null) { auditSvc.SendAudit(audit); } } return(response); }