/// <summary> /// Create NACK /// </summary> internal static IMessage CreateNack(IMessage request, List <IResultDetail> errors, IServiceProvider context, Type errType) { var config = context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; IMessage ack = errType.GetConstructor(Type.EmptyTypes).Invoke(null) as IMessage; Trace.TraceError("Validation Errors:"); errors.ForEach(o => Trace.TraceError("\t{0} : {1}", o.Type, o.Message)); Terser terser = new Terser(ack); MessageUtil.UpdateMSH(terser, request, config); int errLevel = 0; int ec = 0; foreach (var dtl in errors) { try { ISegment errSeg; if (ack.Version == "2.5") { errSeg = terser.getSegment(String.Format("/ERR({0})", ec++)); } else { errSeg = terser.getSegment(String.Format("/ERR", ec++)); } if (errSeg is NHapi.Model.V231.Segment.ERR) { var tErr = MessageUtil.UpdateERR(errSeg as NHapi.Model.V231.Segment.ERR, dtl, context); if (tErr > errLevel) { errLevel = tErr; } } else if (errSeg is NHapi.Model.V25.Segment.ERR) { var tErr = MessageUtil.UpdateERR(errSeg as NHapi.Model.V25.Segment.ERR, dtl, context); if (tErr > errLevel) { errLevel = tErr; } } } catch (Exception e) { Trace.TraceError(e.ToString()); } } terser.Set("/MSA-1", errLevel == 0 ? "AA" : errLevel == 1 ? "AE" : "AR"); return(ack); }
/// <summary> /// Create the RSP_K23 mesasge /// </summary> public NHapi.Model.V25.Message.RSP_K23 CreateRSP_K23(RegistryQueryResult result, List <Everest.Connectors.IResultDetail> dtls) { // Return value var retVal = new NHapi.Model.V25.Message.RSP_K23(); retVal.MSH.MessageType.MessageStructure.Value = "RSP_K23"; retVal.MSH.MessageType.TriggerEvent.Value = "K23"; var qak = retVal.QAK; var msa = retVal.MSA; qak.QueryTag.Value = result.QueryTag; msa.AcknowledgmentCode.Value = "AA"; if (dtls.Exists(o => o.Type == Everest.Connectors.ResultDetailType.Error)) { qak.QueryResponseStatus.Value = "AE"; msa.AcknowledgmentCode.Value = "AE"; foreach (var dtl in dtls) { var err = retVal.GetStructure("ERR", retVal.currentReps("ERR")) as NHapi.Model.V25.Segment.ERR; MessageUtil.UpdateERR(err, dtl, Context); } } else if (result.Results == null || result.Results.Count == 0) { qak.QueryResponseStatus.Value = "NF"; } else { // Create the pid qak.QueryResponseStatus.Value = "OK"; UpdatePID(result.Results[0] as RegistrationEvent, retVal.QUERY_RESPONSE.PID, true); } return(retVal); }
/// <summary> /// Create RSP_K21 message /// </summary> internal NHapi.Base.Model.IMessage CreateRSP_K21(RegistryQueryResult result, RegistryQueryRequest filter, List <Everest.Connectors.IResultDetail> dtls) { // Return value var retVal = new NHapi.Model.V25.Message.RSP_K21(); retVal.MSH.MessageType.MessageStructure.Value = "RSP_K21"; var qak = retVal.QAK; var msa = retVal.MSA; var dsc = retVal.DSC; var qpd = retVal.QPD; qak.QueryTag.Value = result.QueryTag; msa.AcknowledgmentCode.Value = "AA"; if (dtls.Exists(o => o.Type == Everest.Connectors.ResultDetailType.Error)) { qak.QueryResponseStatus.Value = "AE"; msa.AcknowledgmentCode.Value = "AE"; foreach (var dtl in dtls) { var err = retVal.GetStructure("ERR", retVal.currentReps("ERR")) as NHapi.Model.V25.Segment.ERR; MessageUtil.UpdateERR(err, dtl, Context); } } else if (result.Results == null || result.Results.Count == 0) { qak.QueryResponseStatus.Value = "NF"; } else { // Create the pid qak.QueryResponseStatus.Value = "OK"; qak.HitCount.Value = result.TotalResults.ToString(); qak.ThisPayload.Value = result.Results.Count.ToString(); //qak.HitsRemaining.Value = (result.TotalResults - result.StartRecordNumber).ToString(); foreach (RegistrationEvent res in result.Results) { var pid = retVal.GetQUERY_RESPONSE(retVal.QUERY_RESPONSERepetitionsUsed); UpdatePID(res, pid.PID, false); UpdateQRI(res, pid.QRI); pid.PID.SetIDPID.Value = retVal.QUERY_RESPONSERepetitionsUsed.ToString(); } // DSC segment? if (result.TotalResults > result.Results.Count) { retVal.DSC.ContinuationPointer.Value = result.ContinuationPtr; retVal.DSC.ContinuationStyle.Value = "I"; } } // Actual query paramaeters var regFilter = filter.QueryRequest.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as RegistrationEvent; var personFilter = regFilter.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as Person; qpd.QueryTag.Value = filter.QueryTag; qpd.MessageQueryName.Identifier.Value = "IHE PDQ Query"; var terser = new Terser(retVal); int qpdRep = 0; if (personFilter.GenderCode != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.8"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), personFilter.GenderCode); } if (personFilter.AlternateIdentifiers != null && personFilter.AlternateIdentifiers.Count > 0) { var altId = personFilter.AlternateIdentifiers[0]; if (altId.Domain != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.2"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Domain); terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.3"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), "ISO"); } if (altId.Identifier != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Identifier); } if (altId.AssigningAuthority != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.3.4.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.AssigningAuthority); } } if (personFilter.Names != null && personFilter.Names.Count > 0) { var name = personFilter.Names[0]; foreach (var pt in name.Parts) { string pidNo = ComponentUtility.XPN_MAP.First(o => o.Value == pt.Type).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.5.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.Value); } if (name.Use != NameSet.NameSetUse.Search) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.5.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), ComponentUtility.XPN_USE_MAP.First(o => o.Value == name.Use).Key); } } if (personFilter.BirthTime != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), new TS(personFilter.BirthTime.Value).Value); } if (personFilter.Addresses != null && personFilter.Addresses.Count > 0) { var addr = personFilter.Addresses[0]; foreach (var pt in addr.Parts) { string pidNo = ComponentUtility.AD_MAP.First(o => o.Value == pt.PartType).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.11.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.AddressValue); } if (addr.Use != AddressSet.AddressSetUse.Search) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.11.7"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), ComponentUtility.AD_USE_MAP.First(o => o.Value == addr.Use).Key); } } var ma = personFilter.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.RepresentitiveOf) as PersonalRelationship; if (ma != null) { if (ma.LegalName != null) { foreach (var pt in ma.LegalName.Parts) { string pidNo = ComponentUtility.XPN_MAP.First(o => o.Value == pt.Type).Key; terser.Set(String.Format("/QPD-3({0})-1", qpdRep), String.Format("@PID.6.{0}", pidNo)); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), pt.Value); } } if (ma.AlternateIdentifiers != null && ma.AlternateIdentifiers.Count > 0) { var altId = ma.AlternateIdentifiers[0]; if (altId.Domain != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.2"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Domain); terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.3"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), "ISO"); } if (altId.Identifier != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.Identifier); } if (altId.AssigningAuthority != null) { terser.Set(String.Format("/QPD-3({0})-1", qpdRep), "@PID.21.4.1"); terser.Set(String.Format("/QPD-3({0})-2", qpdRep++), altId.AssigningAuthority); } } } return(retVal); }