/// <summary> /// Update a patient /// </summary> public SVC.Messaging.FHIR.FhirOperationResult Update(string id, SVC.Messaging.FHIR.Resources.ResourceBase target, SVC.Core.Services.DataPersistenceMode mode) { // Create a registration event ... subject FhirOperationResult retVal = new FhirOperationResult(); retVal.Details = new List <IResultDetail>(); // Get query parameters var resourceProcessor = FhirMessageProcessorUtil.GetMessageProcessor(this.ResourceName); // Parse the incoming request if (target != null) { target.Id = id; } var storeContainer = resourceProcessor.ProcessResource(target, retVal.Details); if (storeContainer == null) { retVal.Outcome = ResultCode.AcceptedNonConformant; } else { // Now store the container try { // HACK: Store the container storeContainer = DataUtil.Update(storeContainer, id, mode, retVal.Details); retVal.Outcome = ResultCode.Accepted; retVal.Results = new List <ResourceBase>(); retVal.Results.Add(resourceProcessor.ProcessComponent(storeContainer, retVal.Details)); } catch (MissingPrimaryKeyException e) { retVal.Details.Add(new ResultDetail(ResultDetailType.Error, e.Message, e)); retVal.Outcome = ResultCode.TypeNotAvailable; throw e; } catch (Exception e) { retVal.Details.Add(new ResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("DTPE001"), e)); retVal.Outcome = ResultCode.Error; } } return(retVal); }
/// <summary> /// Merge two items together /// </summary> public void Resolve(IEnumerable <SVC.Core.DataTypes.VersionedDomainIdentifier> victimIds, SVC.Core.DataTypes.VersionedDomainIdentifier survivorId, SVC.Core.Services.DataPersistenceMode mode) { // First, we load the survivor if (survivorId.Domain != ApplicationContext.ConfigurationService.OidRegistrar.GetOid(ClientRegistryOids.REGISTRATION_EVENT).Oid) { throw new ArgumentException(String.Format("Must be drawn from the '{0}' domain", ApplicationContext.ConfigurationService.OidRegistrar.GetOid(ClientRegistryOids.REGISTRATION_EVENT).Oid), "survivorId"); } // Load the survivor var persistenceService = this.Context.GetService(typeof(IDataPersistenceService)) as IDataPersistenceService; var survivorRegistrationEvent = persistenceService.GetContainer(survivorId, true) as RegistrationEvent; if (survivorRegistrationEvent == null) { throw new InvalidOperationException("Could not load target registration event"); } var survivorPerson = survivorRegistrationEvent.FindComponent(HealthServiceRecordSiteRoleType.SubjectOf) as Person; if (survivorPerson == null) { throw new InvalidOperationException("Target registration event has no SubjectOf relationship of type Person"); } // Create the merge registration event RegistrationEvent mergeRegistrationEvent = new RegistrationEvent() { Mode = RegistrationEventType.Replace, EventClassifier = RegistrationEventType.Register, LanguageCode = survivorRegistrationEvent.LanguageCode }; mergeRegistrationEvent.EventType = new CodeValue("ADMIN_MRG"); mergeRegistrationEvent.Add(new ChangeSummary() { ChangeType = new CodeValue("ADMIN_MRG"), EffectiveTime = new TimestampSet() { Parts = new List <TimestampPart>() { new TimestampPart(TimestampPart.TimestampPartType.Standlone, DateTime.Now, "F") } }, Timestamp = DateTime.Now, LanguageCode = survivorRegistrationEvent.LanguageCode }, "CHG", HealthServiceRecordSiteRoleType.ReasonFor | HealthServiceRecordSiteRoleType.OlderVersionOf, null); survivorPerson.Site = null; mergeRegistrationEvent.Add(survivorPerson, "SUBJ", HealthServiceRecordSiteRoleType.SubjectOf, null); // Next, we do a replaces relationship for each of the victims (loading them as well since the ID is of the patient not reg event) foreach (var id in victimIds) { var replacementReg = persistenceService.GetContainer(id, true) as RegistrationEvent; if (replacementReg == null) { throw new InvalidOperationException("Could not load victim registration event"); } var replacementPerson = replacementReg.FindComponent(HealthServiceRecordSiteRoleType.SubjectOf) as Person; if (replacementPerson == null) { throw new InvalidOperationException("Victim registration event has no SubjectOf relationship of type Person"); } // Now, create replaces survivorPerson.Add(new PersonRegistrationRef() { AlternateIdentifiers = new List <DomainIdentifier>() { new DomainIdentifier() { Domain = ApplicationContext.ConfigurationService.OidRegistrar.GetOid(ClientRegistryOids.CLIENT_CRID).Oid, Identifier = replacementPerson.Id.ToString() } } }, Guid.NewGuid().ToString(), HealthServiceRecordSiteRoleType.ReplacementOf, null); } // Now persist the replacement IDbConnection conn = DatabasePersistenceService.ConnectionManager.GetConnection(); IDbTransaction tx = null; try { // Update container var vid = persistenceService.UpdateContainer(mergeRegistrationEvent, DataPersistenceMode.Production); tx = conn.BeginTransaction(); foreach (var id in victimIds) { using (IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx)) { cmd.CommandText = "mrg_cand"; cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "from_id_in", DbType.Decimal, Decimal.Parse(id.Identifier))); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "to_id_in", DbType.Decimal, Decimal.Parse(survivorId.Identifier))); cmd.ExecuteNonQuery(); } // Obsolete the victim identifier merges using (IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx)) { cmd.CommandText = "obslt_mrg"; cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "from_id_in", DbType.Decimal, Decimal.Parse(id.Identifier))); cmd.ExecuteNonQuery(); } } tx.Commit(); } catch (Exception e) { if (tx != null) { tx.Rollback(); } throw; } finally { DatabasePersistenceService.ConnectionManager.ReleaseConnection(conn); } }
/// <summary> /// Delete a resource /// </summary> public virtual SVC.Messaging.FHIR.FhirOperationResult Delete(string id, SVC.Core.Services.DataPersistenceMode mode) { throw new NotSupportedException("Cannot delete resources of this type"); }
/// <summary> /// Delete a value set /// </summary> public SVC.Messaging.FHIR.FhirOperationResult Delete(string id, SVC.Core.Services.DataPersistenceMode mode) { throw new NotSupportedException(); }
/// <summary> /// Create a value set .. Method not allowed /// </summary> public SVC.Messaging.FHIR.FhirOperationResult Create(ResourceBase target, SVC.Core.Services.DataPersistenceMode mode) { throw new NotSupportedException(); }
public RegistryStoreResult UnMerge(ComponentModel.RegistrationEvent evt, SVC.Core.Services.DataPersistenceMode mode) { throw new NotImplementedException(); }
/// <summary> /// Ensures an update event is properly represented for a merge /// </summary> public RegistryStoreResult Merge(ComponentModel.RegistrationEvent mergeEvent, SVC.Core.Services.DataPersistenceMode mode) { mergeEvent.EventClassifier = RegistrationEventType.Register; mergeEvent.Mode = RegistrationEventType.Replace; // A merge must have at least one subjectOf var subjectOf = mergeEvent.FindAllComponents(HealthServiceRecordSiteRoleType.SubjectOf); if (subjectOf.Count == 0) { throw new ArgumentException("mergeEvent", "Merge event must have at least one subjectOf component"); } // Each subjectOf shall have a replacement foreach (Person cntr in subjectOf) { var rplc = cntr.FindAllComponents(HealthServiceRecordSiteRoleType.ReplacementOf).OfType <PersonRegistrationRef>(); if (rplc.Count() == 0) { throw new InvalidOperationException("Merge subjectOf has no replacement marker"); } } return(this.Update(mergeEvent, mode)); }
/// <summary> /// Update the registration event /// </summary> public RegistryStoreResult Update(ComponentModel.RegistrationEvent evt, SVC.Core.Services.DataPersistenceMode mode) { RegistryStoreResult retVal = new RegistryStoreResult(); try { // Can't find persistence if (this.m_persistenceService == null) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, "Couldn't locate an implementation of a PersistenceService object, storage is aborted", null)); return(null); } else if (evt == null) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, "Can't register null health service record data", null)); return(null); } else if (retVal.Details.Count(o => o.Type == ResultDetailType.Error) > 0) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, "Won't attempt to persist invalid message", null)); return(null); } // Call the dss if (this.m_decisionSupportService != null) { foreach (var iss in this.m_decisionSupportService.RecordPersisting(evt)) { retVal.Details.Add(new DetectedIssueResultDetail(iss.Priority == SVC.Core.Issues.IssuePriorityType.Error ? ResultDetailType.Error : ResultDetailType.Warning, iss.Text, (string)null, iss)); } } // Any errors? if (retVal.Details.Count(o => o.Type == ResultDetailType.Error) > 0) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, "Won't attempt to persist message due to detected issues", null)); } // Persist retVal.VersionId = this.m_persistenceService.UpdateContainer(evt, mode); retVal.VersionId.UpdateMode = UpdateModeType.Update; // Call the dss if (this.m_decisionSupportService != null) { this.m_decisionSupportService.RecordPersisted(evt); } // Call sub if (this.m_subscriptionService != null) { this.m_subscriptionService.PublishContainer(evt); } // Register the document set if it is a document if (retVal != null && this.m_registrationService != null && !this.m_registrationService.RegisterRecord(evt, mode)) { retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Warning, "Wasn't able to register event in the event registry, event exists in repository but not in registry. You may not be able to query for this event", null)); } } catch (DuplicateNameException ex) // Already persisted stuff { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, m_localeService.GetString("DTPE005"), ex)); } catch (MissingPrimaryKeyException ex) // Already persisted stuff { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, m_localeService.GetString("DTPE005"), ex)); } catch (ConstraintException ex) { Trace.TraceError(ex.ToString()); retVal.Details.Add(new PersistenceResultDetail(ResultDetailType.Error, m_localeService.GetString("DTPE005"), ex)); } catch (Exception ex) { retVal.Details.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex)); } return(retVal); }