///<summary>Converts the value in the MedLab HL7 message field to its corresponding AbnormalFlag enumeration. ///Supported values are 'L', 'H', 'LL', 'HH', '<', '>', 'A', 'AA', 'S', 'R', 'I', 'NEG', and 'POS'. ///If parsing the value into an enum fails, defaults to AbnormalFlag.None, but this won't likely ever be displayed to the user.</summary> public static AbnormalFlag AbnormalFlagParse(string fieldVal) { AbnormalFlag flagVal = AbnormalFlag.None; switch (fieldVal) { case "<": flagVal = AbnormalFlag._lt; break; case ">": flagVal = AbnormalFlag._gt; break; default: try { flagVal = (AbnormalFlag)Enum.Parse(typeof(AbnormalFlag), fieldVal, true); } catch (Exception ex) { ex.DoNothing(); //do nothing, will remain AbnormalFlag.None } break; } return(flagVal); }
public static string GetAbnormalFlagDescript(AbnormalFlag abnormalFlag) { //No need to check RemotingRole; no call to db. switch (abnormalFlag) { case AbnormalFlag._gt: return("Panic High"); case AbnormalFlag._lt: return("Panic Low"); case AbnormalFlag.A: return("Abnormal"); case AbnormalFlag.AA: return("Critical Abnormal"); case AbnormalFlag.H: return("Above High Normal"); case AbnormalFlag.HH: return("Alert High"); case AbnormalFlag.I: return("Intermediate"); case AbnormalFlag.L: return("Below Low Normal"); case AbnormalFlag.LL: return("Alert Low"); case AbnormalFlag.NEG: return("Negative"); case AbnormalFlag.POS: return("Positive"); case AbnormalFlag.R: return("Resistant"); case AbnormalFlag.S: return("Susceptible"); case AbnormalFlag.None: default: return(""); } }
/// <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); }
public static string GetAbnormalFlagDescript(AbnormalFlag abnormalFlag) { //No need to check RemotingRole; no call to db. switch(abnormalFlag) { case AbnormalFlag._gt: return "Panic High"; case AbnormalFlag._lt: return "Panic Low"; case AbnormalFlag.A: return "Abnormal"; case AbnormalFlag.AA: return "Critical Abnormal"; case AbnormalFlag.H: return "Above High Normal"; case AbnormalFlag.HH: return "Alert High"; case AbnormalFlag.I: return "Intermediate"; case AbnormalFlag.L: return "Below Low Normal"; case AbnormalFlag.LL: return "Alert Low"; case AbnormalFlag.NEG: return "Negative"; case AbnormalFlag.POS: return "Positive"; case AbnormalFlag.R: return "Resistant"; case AbnormalFlag.S: return "Susceptible"; case AbnormalFlag.None: default: return ""; } }