/// <summary> /// Query the data store /// </summary> public static IComponent Register(IComponent storeContainer, DataPersistenceMode mode, List <IResultDetail> details) { IClientRegistryDataService dataService = ApplicationContext.CurrentContext.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; try { // Sanity check if (dataService == null) { throw new InvalidOperationException("No persistence service has been configured, registrations cannot continue without this service"); } // Store var result = dataService.Register(storeContainer as RegistrationEvent, mode); details.AddRange(result.Details); if (result == null || result.VersionId == null) { throw new Exception(ApplicationContext.LocalizationService.GetString("DTPE001")); } // Now read and return return(dataService.Get( new VersionedDomainIdentifier[] { result.VersionId }, new RegistryQueryRequest() { IsContinue = false, IsSummary = true, Limit = 1, Offset = 0, QueryId = Guid.NewGuid().ToString() } ).Results?.FirstOrDefault() as IComponent); //return null; } catch (Exception ex) { Trace.TraceError(ex.ToString()); details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); throw; } }
/// <summary> /// Patient registry get identifiers query /// </summary> /// <param name="e"></param> /// <param name="receivedMessage"></param> /// <returns></returns> private IGraphable PatientRegistryGetIdentifiers(UnsolicitedDataEventArgs e, IReceiveResult receivedMessage) { // Setup the lists of details and issues List <IResultDetail> dtls = new List <IResultDetail>(receivedMessage.Details); // System configuration service ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // Localization service ILocalizationService locale = Context.GetService(typeof(ILocalizationService)) as ILocalizationService; // Data Service IClientRegistryDataService dataSvc = Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; // Do basic check and add common validation errors MessageUtil.ValidateTransportWrapperUv(receivedMessage.Structure as IInteraction, configService, dtls); // Check the request is valid var request = receivedMessage.Structure as PRPA_IN201309UV02; if (request == null) { return(null); } // Determine if the received message was interpreted properly bool isValid = MessageUtil.IsValid(receivedMessage); // set the URI if (request.controlActProcess != null) { request.controlActProcess.Code = request.controlActProcess.Code ?? Util.Convert <CD <String> >(PRPA_IN201302UV02.GetTriggerEvent()); } if (request.Receiver.Count > 0) { request.Receiver[0].Telecom = request.Receiver[0].Telecom ?? e.ReceiveEndpoint.ToString(); } // Construct the acknowledgment var response = new PRPA_IN201310UV02( new II(configService.OidRegistrar.GetOid("CR_MSGID").Oid, Guid.NewGuid().ToString()), DateTime.Now, PRPA_IN201310UV02.GetInteractionId(), request.ProcessingCode, request.ProcessingModeCode, AcknowledgementCondition.Never, MessageUtil.CreateReceiver(request.Sender), MessageUtil.CreateSenderUv(e.ReceiveEndpoint, configService), null ); // Create the support classes AuditData audit = null; IheAuditUtil dataUtil = new IheAuditUtil() { Context = this.Context }; // Try to execute the record try { // Determine if the message is valid if (!isValid) { throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure); } // Construct the canonical data structure GetIdentifiersQueryResponseFactory fact = new GetIdentifiersQueryResponseFactory() { Context = this.Context }; RegistryQueryRequest filter = fact.CreateFilterData(request, dtls); if (filter.QueryRequest == null) { throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure); } // Query var results = dataSvc.Query(filter); dtls.AddRange(results.Details); // Prepare for audit audit = dataUtil.CreateAuditData("ITI-45", ActionType.Execute, dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success, e, receivedMessage, results, filter.QueryRequest.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant ); response = fact.Create(request, results, dtls) as PRPA_IN201310UV02; } catch (Exception ex) { Trace.TraceError(ex.ToString()); // Prepare for audit audit = dataUtil.CreateAuditData("ITI-45", ActionType.Execute, OutcomeIndicator.EpicFail, e, receivedMessage, new List <VersionedDomainIdentifier>(), null ); dtls.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex)); response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement( AcknowledgementType.AcceptAcknowledgementCommitError, new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id) )); } finally { IAuditorService auditService = Context.GetService(typeof(IAuditorService)) as IAuditorService; if (auditService != null) { auditService.SendAudit(audit); } } // Common response parameters response.ProfileId = new SET <II>(MCCI_IN000002UV01.GetProfileId()); response.VersionCode = HL7StandardVersionCode.Version3_Prerelease1; response.AcceptAckCode = AcknowledgementCondition.Never; response.Acknowledgement[0].AcknowledgementDetail.AddRange(MessageUtil.CreateAckDetailsUv(dtls.ToArray())); return(response); }
/// <summary> /// Query the data store /// </summary> public static FhirQueryResult Query(ClientRegistryFhirQuery querySpec, List <IResultDetail> details) { // Get the services IClientRegistryDataService dataService = ApplicationContext.CurrentContext.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; IQueryPersistenceService queryService = ApplicationContext.CurrentContext.GetService(typeof(IQueryPersistenceService)) as IQueryPersistenceService; try { if (querySpec.Quantity > 100) { throw new ConstraintException("Query limit must not exceed 100"); } if (dataService == null) { throw new InvalidOperationException("No persistence service has been configured, queries cannot continue without this service"); } FhirQueryResult result = new FhirQueryResult(); result.Query = querySpec; result.Issues = new List <DetectedIssue>(); result.Details = details; result.Results = new List <SVC.Messaging.FHIR.Resources.ResourceBase>(querySpec.Quantity); VersionedDomainIdentifier[] identifiers; RegistryQueryRequest queryRequest = new RegistryQueryRequest() { QueryRequest = querySpec.Filter, QueryId = querySpec.QueryId != Guid.Empty ? querySpec.QueryId.ToString() : null, QueryTag = querySpec.QueryId != Guid.Empty ? querySpec.QueryId.ToString(): null, IsSummary = !querySpec.IncludeHistory, Offset = querySpec.Start, Limit = querySpec.Quantity }; // Is this a continue? queryRequest.IsContinue = (!String.IsNullOrEmpty(queryRequest.QueryId) && queryRequest.Offset > 0); var dataResults = dataService.Query(queryRequest); details.AddRange(dataResults.Details); result.TotalResults = dataResults.TotalResults; // Fetch the results foreach (HealthServiceRecordContainer res in dataResults.Results) { if (res == null) { continue; } var resultSubject = res.FindComponent(HealthServiceRecordSiteRoleType.SubjectOf) as HealthServiceRecordContainer ?? res; var processor = FhirMessageProcessorUtil.GetComponentProcessor(resultSubject.GetType()); if (processor == null) { result.Details.Add(new NotImplementedResultDetail(ResultDetailType.Error, String.Format("Will not include {1}^^^&{2}&ISO in result set, cannot find converter for {0}", resultSubject.GetType().Name, resultSubject.Id, ApplicationContext.ConfigurationService.OidRegistrar.GetOid("CR_CID").Oid), null, null)); } else { result.Results.Add(processor.ProcessComponent(resultSubject, details)); } } // Sort control? // TODO: Support sort control but for now just sort according to confidence then date //retVal.Sort((a, b) => b.Id.CompareTo(a.Id)); // Default sort by id //if (queryPersistence != null) // result.TotalResults = (int)queryPersistence.QueryResultTotalQuantity(querySpec.QueryId.ToString()); //else // result.TotalResults = retRecordId.Count(o => o != null); return(result); } catch (Exception ex) { Trace.TraceError(ex.ToString()); details.Add(new PersistenceResultDetail(ResultDetailType.Error, ex.Message, ex)); throw; } }
/// <summary> /// Handle duplicates resolved message /// </summary> private IGraphable HandlePatientRegistryDuplicatesResolved(MARC.Everest.Connectors.UnsolicitedDataEventArgs e, MARC.Everest.Connectors.IReceiveResult receivedMessage) { // Setup the lists of details and issues List <IResultDetail> dtls = new List <IResultDetail>(receivedMessage.Details); // System configuration service ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // Localization service ILocalizationService locale = Context.GetService(typeof(ILocalizationService)) as ILocalizationService; // Data Service IClientRegistryDataService dataSvc = Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService; // Do basic check and add common validation errors MessageUtil.ValidateTransportWrapperUv(receivedMessage.Structure as IInteraction, configService, dtls); // Check the request is valid var request = receivedMessage.Structure as PRPA_IN201304UV02; if (request == null) { return(null); } // Determine if the received message was interpreted properly bool isValid = MessageUtil.IsValid(receivedMessage); // set the URI if (request.controlActProcess != null) { request.controlActProcess.Code = request.controlActProcess.Code ?? Util.Convert <CD <String> >(PRPA_IN201302UV02.GetTriggerEvent()); } if (request.Receiver.Count > 0) { request.Receiver[0].Telecom = request.Receiver[0].Telecom ?? e.ReceiveEndpoint.ToString(); } // Construct the acknowledgment var response = new MCCI_IN000002UV01( new II(configService.OidRegistrar.GetOid("CR_MSGID").Oid, Guid.NewGuid().ToString()), DateTime.Now, MCCI_IN000002UV01.GetInteractionId(), request.ProcessingCode, request.ProcessingModeCode, MessageUtil.CreateReceiver(request.Sender), MessageUtil.CreateSenderUv(e.ReceiveEndpoint, configService) ); // Create the support classes List <AuditData> audits = new List <AuditData>(); IheAuditUtil dataUtil = new IheAuditUtil() { Context = this.Context }; // Try to execute the record try { // Determine if the message is valid if (!isValid) { throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure); } // Construct the canonical data structure UvComponentUtil cu = new UvComponentUtil() { Context = this.Context }; RegistrationEvent data = cu.CreateComponents(request.controlActProcess, dtls); // Componentization fail? if (data == null || !dataUtil.ValidateIdentifiers(data, dtls)) { throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure); } // Store var result = dataSvc.Merge(data, request.ProcessingCode != ProcessingID.Production ? DataPersistenceMode.Debugging : DataPersistenceMode.Production); if (result == null || result.VersionId == null) { throw new Exception(locale.GetString("DTPE001")); } dtls.AddRange(result.Details); // prepare the delete audit var person = data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as Person; var replc = person.FindAllComponents(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.ReplacementOf); foreach (PersonRegistrationRef rplc in replc) { audits.Add(dataUtil.CreateAuditData("ITI-44", ActionType.Delete, dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success, e, receivedMessage, new List <VersionedDomainIdentifier>() { new VersionedDomainIdentifier() { Domain = rplc.AlternateIdentifiers[0].Domain, Identifier = rplc.AlternateIdentifiers[0].Identifier } }, data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant)); } // Prepare for audit audits.Add(dataUtil.CreateAuditData("ITI-44", ActionType.Update, dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success, e, receivedMessage, new List <VersionedDomainIdentifier>() { result.VersionId }, data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant )); // Add ack response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Acknowledgement( AcknowledgementType.AcceptAcknowledgementCommitAccept, new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id) )); } catch (Exception ex) { Trace.TraceError(ex.ToString()); // Prepare for audit audits.Add(dataUtil.CreateAuditData("ITI-44", ActionType.Create, OutcomeIndicator.EpicFail, e, receivedMessage, new List <VersionedDomainIdentifier>(), null )); dtls.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex)); response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Acknowledgement( AcknowledgementType.AcceptAcknowledgementCommitError, new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id) )); } finally { IAuditorService auditService = Context.GetService(typeof(IAuditorService)) as IAuditorService; if (auditService != null) { foreach (var aud in audits) { auditService.SendAudit(aud); } } } // Common response parameters response.ProfileId = new SET <II>(MCCI_IN000002UV01.GetProfileId()); response.VersionCode = HL7StandardVersionCode.Version3_Prerelease1; response.AcceptAckCode = AcknowledgementCondition.Never; response.Acknowledgement[0].AcknowledgementDetail.AddRange(MessageUtil.CreateAckDetailsUv(dtls.ToArray())); return(response); }