/// <summary> /// Query data from the client registry /// </summary> public SVC.Messaging.FHIR.FhirQueryResult Query(System.Collections.Specialized.NameValueCollection parameters) { FhirQueryResult result = new FhirQueryResult(); result.Details = new List <IResultDetail>(); // Get query parameters var resourceProcessor = FhirMessageProcessorUtil.GetMessageProcessor(this.ResourceName); // Process incoming request NameValueCollection goodParameters = new NameValueCollection(); for (int i = 0; i < parameters.Count; i++) { for (int v = 0; v < parameters.GetValues(i).Length; v++) { if (!String.IsNullOrEmpty(parameters.GetValues(i)[v])) { goodParameters.Add(parameters.GetKey(i), MessageUtil.Escape(parameters.GetValues(i)[v])); } } } parameters = goodParameters; var queryObject = resourceProcessor.ParseQuery(goodParameters, result.Details); result.Query = queryObject; // sanity check #if !DEBUG if (result.Query.ActualParameters.Count == 0) { result.Outcome = ResultCode.Rejected; result.Details.Add(new ValidationResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("MSGE077"), null, null)); } else #endif if (result.Details.Exists(o => o.Type == ResultDetailType.Error)) { result.Outcome = ResultCode.Error; result.Details.Add(new ResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("MSGE00A"), null, null)); } else if (queryObject.Filter == null || result.Outcome != ResultCode.Accepted) { throw new InvalidOperationException("Could not process query parameters!"); } else { result = DataUtil.Query(queryObject, result.Details); } return(result); }
/// <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> /// Read a patint resource /// </summary> public SVC.Messaging.FHIR.FhirOperationResult Read(string id, string versionId) { FhirOperationResult result = new FhirOperationResult(); result.Details = new List <IResultDetail>(); result.Results = new List <ResourceBase>(); // Data persistence service IDataPersistenceService dataPersistence = ApplicationContext.CurrentContext.GetService(typeof(IDataPersistenceService)) as IDataPersistenceService; var container = dataPersistence.GetContainer(new VersionedDomainIdentifier() { Domain = this.DataDomain, Identifier = id, Version = String.IsNullOrEmpty(versionId) ? null : versionId }, String.IsNullOrEmpty(versionId)); // Container was not found if (container == null) { result.Outcome = ResultCode.NotAvailable; } else { var processor = FhirMessageProcessorUtil.GetComponentProcessor(container.GetType()); // Was there a history? if (versionId == null) { result.Results.Add(processor.ProcessComponent(container as IComponent, result.Details)); } else if (versionId == String.Empty) // Get all versions { while (container != null) { var hsrc = container as HealthServiceRecordContainer; var resource = processor.ProcessComponent(container as IComponent, result.Details); if (hsrc.IsMasked) // record is masked so add a detected issue { result.Issues.Add(new SVC.Core.Issues.DetectedIssue() { MitigatedBy = ManagementType.OtherActionTaken, Severity = IssueSeverityType.Moderate, Text = String.Format("{0}/_history/{1} will not be returned as it has been masked", resource.Id, resource.VersionId), Type = IssueType.DetectedIssue }); } else { result.Results.Add(resource); } container = hsrc.FindComponent(HealthServiceRecordSiteRoleType.OlderVersionOf) as IContainer; } } else // Some version { while (container != null) { var hsrc = container as HealthServiceRecordContainer; var resource = processor.ProcessComponent(container as IComponent, result.Details); container = hsrc.FindComponent(HealthServiceRecordSiteRoleType.ReplacementOf) as IContainer; if (resource != null && resource.VersionId.ToString() != versionId) { continue; } if (hsrc.IsMasked) // record is masked so add a detected issue { result.Issues.Add(new SVC.Core.Issues.DetectedIssue() { MitigatedBy = ManagementType.OtherActionTaken, Severity = IssueSeverityType.Moderate, Text = String.Format("{0}/_history/{1} will not be returned as it has been masked", resource.Id, resource.VersionId), Type = IssueType.DetectedIssue }); } else { result.Results.Add(resource); } } } result.Outcome = ResultCode.Accepted; } result.Results.RemoveAll(o => o == null); return(result); }
public override SVC.Messaging.FHIR.Resources.ResourceBase ProcessComponent(System.ComponentModel.IComponent component, List <Everest.Connectors.IResultDetail> dtls) { // Create a component HealthcareParticipant ptcpt = component as HealthcareParticipant; if (ptcpt.Classifier != HealthcareParticipant.HealthcareParticipantType.Organization) { ; // Not an organization pass off } // Organization Organization retVal = new Organization(); retVal.Id = ptcpt.Id.ToString(); retVal.VersionId = ptcpt.Id.ToString(); // Other identifiers foreach (var id in ptcpt.AlternateIdentifiers) { retVal.Extension.Add(ExtensionUtil.CreateIdentificationExtension(id)); } if (ptcpt.Type != null) { retVal.Type = base.ConvertCode(ptcpt.Type); } retVal.Name = ptcpt.LegalName.Parts[0].Value; retVal.Active = true; // Address if (ptcpt.PrimaryAddress != null) { retVal.Address = base.ConvertAddressSet(ptcpt.PrimaryAddress); } // Telecoms if (ptcpt.TelecomAddresses != null) { foreach (var tel in ptcpt.TelecomAddresses) { retVal.Telecom.AddRange(base.ConvertTelecom(tel)); } } var contacts = ptcpt.FindAllComponents(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.RepresentitiveOf); foreach (HealthcareParticipant contact in contacts) { ContactEntity ce = new ContactEntity(); // Link var processor = FhirMessageProcessorUtil.GetComponentProcessor(contact.GetType()); var processResult = processor.ProcessComponent(contact, dtls); if (processResult is Practictioner) { var prac = processResult as Practictioner; ce.Name = prac.Name[0]; ce.Address = prac.Address[0]; ce.Gender = prac.Gender; ce.Telecom = prac.Telecom; } if (ce.Name != null) { ce.Name = base.ConvertNameSet(contact.LegalName); } if (contact.TelecomAddresses != null) { foreach (var t in contact.TelecomAddresses) { ce.Telecom.AddRange(base.ConvertTelecom(t)); } } if (contact.PrimaryAddress != null) { ce.Address = base.ConvertAddressSet(contact.PrimaryAddress)[0]; } retVal.ContactEntity.Add(ce); } return(retVal); }