Esempio n. 1
0
        public void Equals_GivenVariousScenarios_ReturnsAsExpected()
        {
            LabFacility first;
            LabFacility second;

            first  = new LabFacility(null, null, null, null, null);
            second = new LabFacility(null, null, null, null, null);
            Assert.IsTrue(first.Equals(second));

            first  = new LabFacility(null, null, null, null, null);
            second = new LabFacility("", null, null, null, null);
            Assert.IsFalse(first.Equals(second));

            first  = new LabFacility("", null, null, null, null);
            second = new LabFacility("", null, null, null, null);
            Assert.IsTrue(first.Equals(second));
        }
Esempio n. 2
0
        public void Equals_GivenVariousScenarios_ReturnsAsExpected()
        {
            LabFacility first;
            LabFacility second;

            first = new LabFacility(null, null, null, null, null);
            second = new LabFacility(null, null, null, null, null);
            Assert.IsTrue(first.Equals(second));

            first = new LabFacility(null, null, null, null, null);
            second = new LabFacility("", null, null, null, null);
            Assert.IsFalse(first.Equals(second));

            first = new LabFacility("", null, null, null, null);
            second = new LabFacility("", null, null, null, null);
            Assert.IsTrue(first.Equals(second));
        }
Esempio n. 3
0
 /// <summary>
 /// Revises the lab facility.
 /// </summary>
 /// <param name="labFacility">The lab facility.</param>
 public virtual void ReviseLabFacility(LabFacility labFacility)
 {
     Check.IsNotNull(labFacility, () => LabFacility);
     LabFacility = labFacility;
 }
Esempio n. 4
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(SaveLabResultRequest request)
        {
            var response = CreateTypedResponse();

            response.ErrorMessages = new List <string> ();
            var parser = new PipeParser();

            var encoding       = new UTF8Encoding();
            var decodedMessage = encoding.GetString(request.HL7Message);
            var hl7Message     = parser.Parse(decodedMessage);

            if (hl7Message.Version != "2.5.1")
            {
                response.ErrorMessages.Add("Lab Result is using the version other than 2.5.1");
                return(response);
            }

            var message          = ( ORU_R01 )hl7Message;
            var patientResult    = message.GetPATIENT_RESULT();
            var pidSegment       = patientResult.PATIENT.PID;
            var observation      = patientResult.GetORDER_OBSERVATION();
            var specimentSegment = observation.SPECIMEN.SPM;
            var obResultSegment  = observation.OBSERVATION.OBX;
            var obRequest        = observation.OBR;

            if (pidSegment == null)
            {
                response.ErrorMessages.Add("PID segment is missing");
                return(response);
            }

            if (pidSegment.PatientID.IDNumber.Value == null)
            {
                response.ErrorMessages.Add(string.Format("Patient Id is missing"));
                return(response);
            }

            var patient = Session.Get <Patient> (Convert.ToInt64(pidSegment.PatientID.IDNumber.Value));

            if (patient == null)
            {
                response.ErrorMessages.Add(string.Format("Patient not found with id : {0}", pidSegment.PatientID.IDNumber.Value));
                return(response);
            }

            var clinicalCaseCriteria =
                DetachedCriteria.For <ClinicalCase> ().SetProjection(Projections.Id()).Add(
                    Restrictions.Eq(
                        Projections.Property <ClinicalCase> (p => p.Patient.Key),
                        pidSegment.PatientID.IDNumber.Value));
            var checkedInStatus = _visitStatusRepository.GetByWellKnownName(WellKnownNames.VisitModule.VisitStatus.CheckedIn);
            var visitCriteria   =
                Session.CreateCriteria <Visit> ().Add(Subqueries.PropertyIn("ClinicalCase.Key", clinicalCaseCriteria))
                ////.Add(Restrictions.Eq(Projections.Property<Visit>(v => v.VisitStatus), checkedInStatus ))
                ////TODO: Right now, the CheckedInDateTime is the time when the user click the button to change the VisitStatus. This is not right
                .Add(
                    Restrictions.Eq(Projections.Property <Visit> (v => v.CheckedInDateTime), obRequest.ObservationDateTime.Time.GetAsDate()));

            var visitList = visitCriteria.List();

            if (visitList.Count > 0)
            {
                var visit = ( Visit )visitList[0];

                var labSpecimenType = _labSpecimenTypeRepository.GetByCodedConceptCode(specimentSegment.SpecimenType.Identifier.Value);
                if (labSpecimenType == null)
                {
                    labSpecimenType = new LabSpecimenType
                    {
                        CodedConceptCode   = specimentSegment.SpecimenType.Identifier.Value,
                        Name               = specimentSegment.SpecimenType.Text.Value,
                        EffectiveDateRange = new DateRange(DateTime.Now, null)
                    };
                    labSpecimenType = _labSpecimenTypeRepository.MakePersistent(labSpecimenType);
                }

                var labSpecimen = _labSpecimenFactory.CreateLabSpecimen(
                    visit);
                labSpecimen.ReviseLabSpecimenType(labSpecimenType);

                var labFacility = new LabFacility(
                    obResultSegment.PerformingOrganizationName.OrganizationName.Value,
                    obResultSegment.PerformingOrganizationAddress.StreetAddress.StreetOrMailingAddress.Value,
                    obResultSegment.PerformingOrganizationAddress.City.Value,
                    obResultSegment.PerformingOrganizationAddress.StateOrProvince.Value,
                    obResultSegment.PerformingOrganizationAddress.ZipOrPostalCode.Value);
                labSpecimen.ReviseLabFacility(labFacility);

                if (specimentSegment.GetSpecimenRejectReason().Count() > 0)
                {
                    labSpecimen.ReviseTestNotCompletedReasonDescription(specimentSegment.GetSpecimenRejectReason().FirstOrDefault().Text.Value);
                }

                var testName = _labTestNameRepository.GetByCodedConceptCode(obRequest.UniversalServiceIdentifier.Identifier.Value);
                if (testName == null)
                {
                    testName = new LabTestName
                    {
                        CodedConceptCode   = obRequest.UniversalServiceIdentifier.Identifier.Value,
                        Name               = obRequest.UniversalServiceIdentifier.Text.Value,
                        EffectiveDateRange = new DateRange(DateTime.Now, null)
                    };
                    testName = _labTestNameRepository.MakePersistent(testName);
                }

                CodedConcept interpretationCodeCodedConcept = null;
                if (obResultSegment.ValueType.Value != "TX")
                {
                    var abnormalFlagIS = obResultSegment.GetAbnormalFlags().FirstOrDefault();
                    if (abnormalFlagIS != null)
                    {
                        var abnormalFlagCode = abnormalFlagIS.Value;
                        var abnormalFlag     = AbnormalFlag.GetAbnormalFlagByCode(abnormalFlagCode);
                        if (abnormalFlag != null)
                        {
                            interpretationCodeCodedConcept = new CodedConceptBuilder()
                                                             .WithCodedConceptCode(abnormalFlagCode)
                                                             .WithDisplayName(abnormalFlag.WellKnownName)
                                                             .WithCodeSystemIdentifier(AbnormalFlag.CodeSystemIdentifier)
                                                             .WithCodeSystemName(AbnormalFlag.CodeSystemName);
                        }
                    }
                }

                var labTest = labSpecimen.AddLabTest(
                    new LabTestInfoBuilder()
                    .WithLabTestName(testName)
                    .WithTestReportDate(obRequest.ObservationDateTime.Time.GetAsDate())
                    .WithNormalRangeDescription(obResultSegment.ReferencesRange.Value)
                    .WithInterpretationCodedConcept(interpretationCodeCodedConcept));

                var resultTestName = new CodedConceptBuilder()
                                     .WithCodedConceptCode(obResultSegment.ObservationIdentifier.Identifier.Value)
                                     .WithDisplayName(obResultSegment.ObservationIdentifier.Text.Value);

                double?value = null;
                double tempValue;
                if (double.TryParse(obResultSegment.GetObservationValue().FirstOrDefault().Data.ToString(), out tempValue))
                {
                    value = tempValue;
                }

                var labResult = new LabResultBuilder()
                                .WithLabTestResultNameCodedConcept(resultTestName)
                                .WithUnitOfMeasureCode(obResultSegment.Units.Identifier.Value)
                                .WithValue(value);

                labTest.AddLabResult(labResult);
            }
            else
            {
                response.ErrorMessages.Add(
                    string.Format(
                        "Visit not found for Patient id: {0} and Visit Date: {1}",
                        pidSegment.PatientID.IDNumber.Value,
                        obRequest.ObservationDateTime.Time.GetAsDate()));
            }

            if (response.ErrorMessages.Count > 0)
            {
                response.Exception     = new ExceptionInfo(new Exception("SaveLabResult failed, transaction is going to be rollback."));
                response.ExceptionType = ExceptionType.Unknown;
            }

            return(response);
        }