public override Task ProcessAsync(ILookupTemplate <IFhirTemplate> config, IMeasurementGroup data, Func <Exception, IMeasurementGroup, Task <bool> > errorConsumer = null) { throw new NotImplementedException(); }
protected abstract Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesInternalAsync(IMeasurementGroup input);
protected abstract string GetCacheKey(IMeasurementGroup input);
public IEnumerable <IObservationGroup> CreateObservationGroups(IFhirTemplate template, IMeasurementGroup measurementGroup) { return(CreateObservationGroupsImpl(CastTemplate(template), measurementGroup)); }
protected override IEnumerable <IObservationGroup> CreateObservationGroupsImpl(CodeValueFhirTemplate template, IMeasurementGroup measurementGroup) { return(TestCreateObservationGroupsImpl(template, measurementGroup)); }
protected override IEnumerable <IObservationGroup> CreateObservationGroupsImpl(CodeValueFhirTemplate template, IMeasurementGroup measurementGroup) { EnsureArg.IsNotNull(template, nameof(template)); IObservationGroupFactory <IMeasurementGroup> factory = new MeasurementObservationGroupFactory(template.PeriodInterval); return(factory.Build(measurementGroup)); }
protected async override Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesInternalAsync(IMeasurementGroup input) { EnsureArg.IsNotNull(input, nameof(input)); var identities = await base.ResolveResourceIdentitiesInternalAsync(input).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(input.EncounterId)) { throw new ResourceIdentityNotDefinedException(ResourceType.Encounter); } var encounter = await ResourceManagementService.GetResourceByIdentityAsync <Model.Encounter>(FhirClient, input.EncounterId, null).ConfigureAwait(false) ?? throw new FhirResourceNotFoundException(ResourceType.Encounter); identities[ResourceType.Encounter] = encounter?.Id; return(identities); }
public abstract Task ProcessAsync(ILookupTemplate <IFhirTemplate> config, IMeasurementGroup data, Func <Exception, IMeasurementGroup, Task <bool> > errorConsumer = null);
protected static string GetDeviceIdentity(IMeasurementGroup input) { EnsureArg.IsNotNull(input, nameof(input)); return(input.DeviceId); }
public abstract Task <IDictionary <ResourceType, string> > HarnessResolveResourceIdentitiesInternalAsync(IMeasurementGroup input);
protected static string GetDeviceIdentity(IMeasurementGroup input) { return(input.DeviceId); }
public abstract string HarnessGetCacheKey(IMeasurementGroup input);
protected async override Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesInternalAsync(IMeasurementGroup input) { return(await HarnessResolveResourceIdentitiesInternalAsync(input)); }
protected override string GetCacheKey(IMeasurementGroup input) { return(HarnessGetCacheKey(input)); }
protected async override Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesInternalAsync(IMeasurementGroup input) { try { return(await base.ResolveResourceIdentitiesInternalAsync(input).ConfigureAwait(false)); } catch (FhirResourceNotFoundException ex) { // Continue with create path if device or patient wasn't found. if (!(ex.FhirResourceType == ResourceType.Device || ex.FhirResourceType == ResourceType.Patient)) { throw; } } var(deviceId, patientId) = await EnsureDeviceAndPatientExistsAsync(input).ConfigureAwait(false); return(CreateIdentityLookup(deviceId, patientId)); }
protected override string GetCacheKey(IMeasurementGroup input) { return(GetDeviceIdentity(input)); }
/// <summary> /// Ensures a patient and device resource exists and returns the relevant internal ids. /// </summary> /// <param name="input">IMeasurementGroup to retrieve device and patient identifiers from.</param> /// <returns>Internal reference id to the patient and device resources found or created.</returns> /// <exception cref="PatientIdentityNotDefinedException">Thrown when a unique patient identifier isn't found in the provided input.</exception> /// <exception cref="PatientDeviceMismatchException">Thrown when expected patient internal id of the device doesn't match the actual patient internal id.</exception> protected async virtual Task <(string DeviceId, string PatientId)> EnsureDeviceAndPatientExistsAsync(IMeasurementGroup input) { EnsureArg.IsNotNull(input, nameof(input)); // Verify one unique patient identity is present in the measurement group if (string.IsNullOrWhiteSpace(input.PatientId)) { throw new ResourceIdentityNotDefinedException(ResourceType.Patient); } // Begin critical section var patient = await ResourceManagementService.EnsureResourceByIdentityAsync <Model.Patient>( FhirClient, input.PatientId, null, (p, id) => p.Identifier = new List <Model.Identifier> { id }) .ConfigureAwait(false); var device = await ResourceManagementService.EnsureResourceByIdentityAsync <Model.Device>( FhirClient, GetDeviceIdentity(input), ResourceIdentityOptions?.DefaultDeviceIdentifierSystem, (d, id) => { d.Identifier = new List <Model.Identifier> { id }; d.Patient = patient.ToReference(); }) .ConfigureAwait(false); patient.ToReference(); if (device.Patient == null) { device.Patient = patient.ToReference(); device = await FhirClient.UpdateAsync <Model.Device>(device, true).ConfigureAwait(false); } else if (device.Patient.GetId <Model.Patient>() != patient.Id) { // Device is linked to a different patient. Current behavior is undefined, throw an exception. throw new PatientDeviceMismatchException(); } // End critical section return(device.Id, patient.Id); }
protected async override Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesInternalAsync(IMeasurementGroup input) { var system = ResourceIdentityOptions?.DefaultDeviceIdentifierSystem; var(deviceId, patientId) = await LookUpDeviceAndPatientIdAsync(GetDeviceIdentity(input), system).ConfigureAwait(false); return(CreateIdentityLookup(deviceId, patientId)); }
public IEnumerable <IObservationGroup> CreateObservationGroups(ILookupTemplate <IFhirTemplate> lookup, IMeasurementGroup measurementGroup) { EnsureArg.IsNotNull(measurementGroup, nameof(measurementGroup)); var(template, processor) = GetTemplateAndProcessor(measurementGroup.MeasureType, lookup); return(processor.CreateObservationGroups(template, measurementGroup)); }
public Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesAsync(IMeasurementGroup input) { throw new NotImplementedException(); }
public override async Task ProcessAsync(ILookupTemplate <IFhirTemplate> config, IMeasurementGroup data, Func <Exception, IMeasurementGroup, Task <bool> > errorConsumer = null) { // Get required ids var ids = await ResourceIdentityService.ResolveResourceIdentitiesAsync(data).ConfigureAwait(false); var grps = _fhirTemplateProcessor.CreateObservationGroups(config, data); foreach (var grp in grps) { _ = await SaveObservationAsync(config, grp, ids).ConfigureAwait(false); } }
public async Task <IDictionary <ResourceType, string> > ResolveResourceIdentitiesAsync(IMeasurementGroup input) { EnsureArg.IsNotNull(input, nameof(input)); var cacheKey = GetCacheKey(input); return(await IdentityCache.GetOrCreateAsync( cacheKey, async e => { e.SetSlidingExpiration(TimeSpan.FromHours(2)); e.Size = 1; return await ResolveResourceIdentitiesInternalAsync(input).ConfigureAwait(false); }) .ConfigureAwait(false)); }
protected abstract IEnumerable <IObservationGroup> CreateObservationGroupsImpl(TTemplate template, IMeasurementGroup measurementGroup);
public virtual IEnumerable <IObservationGroup> TestCreateObservationGroupsImpl(CodeValueFhirTemplate template, IMeasurementGroup measurementGroup) { return(null); }