Ejemplo n.º 1
0
        public SynapseResource Handle(SynapseResource resource)
        {
            ValidateObservation(resource);

            var observationRoot = resource as ObservationRoot;

            if (IsAmended(observationRoot))
            {
                HandleAmendedObservation(observationRoot);
            }
            else
            {
                HandleObservation(observationRoot);
            }

            var savedStatus = _coreObservationEventRepo.SaveChanges();

            //var savedObsStatus = _observationService.SaveChanges();

            if (savedStatus > 0)
            {
                var newObservationRoot = GetSavedObservation(observationRoot);

                AddNewMaterialisedObservation(newObservationRoot);

                return(newObservationRoot);
            }

            return(null);
        }
        public SynapseResource Handle(IKey key, SynapseResource resource) // Just for the observation, temporary implementation -- can be removed later
        {
            var hl7Type = key.TypeName.GetHl7ModelType();

            var modelFactory = this._provider.GetService(typeof(ResourceCommandHandlerFactory)) as ResourceCommandHandlerFactory;

            IResourceCommandHandler commandHandler = modelFactory.GetHandler(hl7Type);

            var fhirParam = FHIRParam.Create(key.TypeName, key.ResourceId, key.VersionId);

            var synapseResource = commandHandler.Handle(resource);

            if (synapseResource == null)
            {
                throw new InterneuronBusinessException(StatusCodes.Status500InternalServerError);
            }

            return(synapseResource);
        }
Ejemplo n.º 3
0
        private static void ValidateObservation(SynapseResource resource)
        {
            if (resource.IsNull() || !(resource is ObservationRoot observationRoot))
            {
                throw new InterneuronBusinessException(400, "Invalid observation object.");
            }

            if (observationRoot.IsNull() || observationRoot.ObservationEvent.IsNull())
            {
                throw new InterneuronBusinessException(400, "Should have observation event object.");
            }

            if (!observationRoot.ObservationEvent.Datestarted.HasValue)
            {
                throw new InterneuronBusinessException(400, "Should have observation event start date.");
            }

            if (IsAmended(observationRoot) && observationRoot.ObservationEvent.Observationevent_Id.IsEmpty())
            {
                throw new InterneuronBusinessException(400, "Amended observation event should have observation event identifier.");
            }
        }