Example #1
0
        public void TestPersistGenericAct()
        {
            var underTest = new QuantityObservation()
            {
                MoodConceptKey        = ActMoodKeys.Eventoccurrence,
                ActTime               = DateTimeOffset.Now,
                InterpretationConcept = new Concept()
                {
                    Mnemonic = "N"
                },
                TypeConcept = new Concept()
                {
                    Mnemonic = "VitalSigns-Weight"
                },
                Value         = (decimal)1.2,
                UnitOfMeasure = new Concept()
                {
                    Mnemonic = "kg"
                }
            };

            var afterTest = base.DoTestInsert(underTest) as QuantityObservation;

            Assert.IsNotNull(afterTest.InterpretationConcept);
            Assert.IsNotNull(afterTest.UnitOfMeasure);
            Assert.AreEqual((decimal)1.2, afterTest.Value);
        }
        public void DiffShouldCascadeToNestedSingleObjectRef()
        {
            Act a = new QuantityObservation()
            {
                Template = new Model.DataTypes.TemplateDefinition()
                {
                    Mnemonic    = "TESTTEMPLATE",
                    Key         = Guid.NewGuid(),
                    Description = "This is a test"
                }
            },
                b = new QuantityObservation()
            {
                Template = new Model.DataTypes.TemplateDefinition()
                {
                    Mnemonic    = "OBSERVATION",
                    Key         = Guid.NewGuid(),
                    Description = "This is a different template"
                }
            };

            var patchService = new SimplePatchService();
            var patch        = patchService.Diff(a, b);
            var patchString  = patch.ToString();
        }
Example #3
0
        public void ObservationShouldSetReferenceRange()
        {
            QuantityObservation qobs = new QuantityObservation()
            {
                Value          = (Decimal)2.3,
                Participations = new List <ActParticipation>()
                {
                    new ActParticipation()
                    {
                        ParticipationRole = new Core.Model.DataTypes.Concept()
                        {
                            Mnemonic = "RecordTarget"
                        },
                        PlayerEntity = new Patient()
                        {
                            DateOfBirth   = DateTime.Now,
                            GenderConcept = new Core.Model.DataTypes.Concept()
                            {
                                Key      = Guid.Parse("094941e9-a3db-48b5-862c-bc289bd7f86c"),
                                Mnemonic = "Female"
                            }
                        }
                    }
                },
                TypeConceptKey = Guid.Parse("a261f8cd-69b0-49aa-91f4-e6d3e5c612ed")
            };

            var breService = ApplicationServiceContext.Current.GetService(typeof(IBusinessRulesService <QuantityObservation>)) as IBusinessRulesService <QuantityObservation>;

            Assert.IsNotNull(breService);
            qobs = breService.BeforeInsert(qobs);
            Assert.IsNotNull(qobs.InterpretationConceptKey);
        }
Example #4
0
        public void TestPersistQuantityObservationWithParticipation()
        {
            var weightAct = new QuantityObservation()
            {
                ClassConceptKey       = ActClassKeys.Observation,
                MoodConceptKey        = ActMoodKeys.Eventoccurrence,
                ActTime               = DateTimeOffset.Now,
                InterpretationConcept = new Concept()
                {
                    Mnemonic = "N"
                },
                TypeConcept = new Concept()
                {
                    Mnemonic = "VitalSigns-Weight"
                },
                Participations = new List <ActParticipation>
                {
                    new ActParticipation
                    {
                        ParticipationRole = new Concept
                        {
                            Mnemonic = "RecordTarget"
                        },
                        PlayerEntity = new Patient
                        {
                            StatusConceptKey = StatusKeys.Active,
                            Names            = new List <EntityName>
                            {
                                new EntityName(NameUseKeys.Legal, "Johnson", "William")
                            },
                            Addresses = new List <EntityAddress>
                            {
                                new EntityAddress(AddressUseKeys.HomeAddress, "123 Main Street West", "Hamilton", "ON", "CA", "L8K5N2")
                            },
                            Identifiers = new List <EntityIdentifier>
                            {
                                new EntityIdentifier(new AssigningAuthority()
                                {
                                    Name = "OHIPCARD", DomainName = "OHIPCARD", Oid = "1.2.3.4.5.6"
                                }, "12343120423")
                            },
                            Telecoms = new List <EntityTelecomAddress>
                            {
                                new EntityTelecomAddress(AddressUseKeys.WorkPlace, "mailto:[email protected]")
                            },
                            Tags = new List <EntityTag>
                            {
                                new EntityTag("hasBirthCertificate", "true")
                            },
                            Notes = new List <EntityNote>
                            {
                                new EntityNote
                                {
                                    Author = new Provider
                                    {
                                    },
                                    Text = "He doesn't even like Peanutbutter!!!!!"
                                }
                            },
                            GenderConceptKey      = Guid.Parse("F4E3A6BB-612E-46B2-9F77-FF844D971198"),
                            DateOfBirth           = new DateTime(1984, 03, 22),
                            MultipleBirthOrder    = 2,
                            DeceasedDate          = new DateTime(2016, 05, 02),
                            DeceasedDatePrecision = DatePrecision.Hour,
                            DateOfBirthPrecision  = DatePrecision.Day
                        }
                    }
                },
                Value         = (decimal)1.2,
                UnitOfMeasure = new Concept
                {
                    Mnemonic = "kg"
                }
            };

            var afterTest = base.DoTestInsert(weightAct) as QuantityObservation;

            Assert.IsNotNull(afterTest.InterpretationConcept);
            Assert.IsNotNull(afterTest.UnitOfMeasure);
            Assert.AreEqual((decimal)1.2, afterTest.Value);

            Assert.AreEqual(1, afterTest.Participations.Count);
            Assert.IsNotNull(afterTest.Participations.First().PlayerEntity);
            Assert.IsInstanceOfType(afterTest.Participations.First().PlayerEntity, typeof(Patient));
        }
Example #5
0
 /// <summary>
 /// Save sbadm
 /// </summary>
 public QuantityObservation Save(QuantityObservation data)
 {
     return(this.Save <QuantityObservation>(data));
 }
Example #6
0
 /// <summary>
 /// Insert SBADM
 /// </summary>
 public QuantityObservation Insert(QuantityObservation data)
 {
     return(this.Insert <QuantityObservation>(data));
 }
        /// <summary>
        /// Map to model
        /// </summary>
        protected override Core.Model.Acts.Observation MapToModel(Observation resource)
        {
            //value type and value
            Core.Model.Acts.Observation retVal;
            switch (resource.Value)
            {
            case CodeableConcept codeableConcept:
                retVal = new CodedObservation
                {
                    ValueType = "CD",
                    Value     = DataTypeConverter.ToConcept(codeableConcept)
                };
                break;

            case Quantity quantity:
                retVal = new QuantityObservation
                {
                    ValueType     = "PQ",
                    Value         = quantity.Value.Value,
                    UnitOfMeasure = DataTypeConverter.ToConcept(quantity.Unit, "http://hl7.org/fhir/sid/ucum")
                };
                break;

            case FhirString fhirString:
                retVal = new TextObservation
                {
                    ValueType = "ST",
                    Value     = fhirString.Value
                };
                break;

            default:
                retVal = new Core.Model.Acts.Observation();
                break;
            }

            retVal.Extensions  = resource.Extension.Select(DataTypeConverter.ToActExtension).ToList();
            retVal.Identifiers = resource.Identifier.Select(DataTypeConverter.ToActIdentifier).ToList();

            retVal.Key = Guid.TryParse(resource.Id, out var id) ? id : Guid.NewGuid();

            // Observation
            var status = resource.Status;

            //status concept key

            switch (status)
            {
            case ObservationStatus.Preliminary:
                retVal.StatusConceptKey = StatusKeys.Active;
                break;

            case ObservationStatus.Cancelled:
                retVal.StatusConceptKey = StatusKeys.Cancelled;
                break;

            case ObservationStatus.EnteredInError:
                retVal.StatusConceptKey = StatusKeys.Nullified;
                break;

            case ObservationStatus.Final:
                retVal.StatusConceptKey = StatusKeys.Completed;
                break;

            case ObservationStatus.Amended:
            case ObservationStatus.Corrected:
                throw new NotSupportedException(this.m_localizationService.GetString("error.messaging.fhir.observationStatus"));

            case ObservationStatus.Unknown:
                retVal.StatusConceptKey = StatusKeys.Obsolete;
                break;
            }

            //Effective

            switch (resource.Effective)
            {
            case Period period:
                retVal.StartTime = DataTypeConverter.ToDateTimeOffset(period.Start);
                retVal.StopTime  = DataTypeConverter.ToDateTimeOffset(period.End);
                break;

            case FhirDateTime fhirDateTime:
                retVal.ActTime = DataTypeConverter.ToDateTimeOffset(fhirDateTime) ?? DateTimeOffset.MinValue;
                break;
            }


            retVal.TypeConcept = DataTypeConverter.ToConcept(resource.Code);


            //issued
            if (resource.Issued.HasValue)
            {
                retVal.CreationTime = (DateTimeOffset)resource.Issued;
            }

            //interpretation
            if (resource.Interpretation.Any())
            {
                retVal.InterpretationConcept = DataTypeConverter.ToConcept(resource.Interpretation.First());
            }


            //subject

            if (resource.Subject != null)
            {
                // if the subject is a UUID then add the record target key
                // otherwise attempt to resolve the reference
                retVal.Participations.Add(resource.Subject.Reference.StartsWith("urn:uuid:") ?
                                          new ActParticipation(ActParticipationKey.RecordTarget, Guid.Parse(resource.Subject.Reference.Substring(9))) :
                                          new ActParticipation(ActParticipationKey.RecordTarget, DataTypeConverter.ResolveEntity <Core.Model.Roles.Patient>(resource.Subject, resource)));
                //else
                //{
                //    this.m_tracer.TraceError("Only UUID references are supported");
                //    throw new NotSupportedException(this.m_localizationService.FormatString("error.type.NotSupportedException.paramOnlySupported", new
                //    {
                //        param = "UUID"
                //    }));
                //}
            }

            //performer
            if (resource.Performer.Any())
            {
                foreach (var res in resource.Performer)
                {
                    retVal.Participations.Add(res.Reference.StartsWith("urn:uuid:") ?
                                              new ActParticipation(ActParticipationKey.Performer, Guid.Parse(res.Reference.Substring(9))) :
                                              new ActParticipation(ActParticipationKey.Performer, DataTypeConverter.ResolveEntity <Provider>(res, resource)));

                    //if (res.Reference.StartsWith("urn:uuid:"))
                    //{
                    //    retVal.Participations.Add(new ActParticipation(ActParticipationKey.Performer, Guid.Parse(res.Reference.Substring(9))));
                    //}
                    //else
                    //{
                    //    this.m_tracer.TraceError("Only UUID references are supported");
                    //    throw new NotSupportedException(this.m_localizationService.FormatString("error.type.NotSupportedException.paramOnlySupported", new
                    //    {
                    //        param = "UUID"
                    //    }));
                    //}
                }
            }

            // to bypass constraint at function 'CK_IS_CD_SET_MEM'
            retVal.MoodConceptKey = ActMoodKeys.Eventoccurrence;

            return(retVal);
        }