/// <summary>
        /// 2.5.3 5 System should ignore the following MDS alerts when suppress flag is true:
        ///Drug allergy alert
        ///G6PD deficiency contraindication alert
        ///ignore the G6PD deficiency contraindication alert when the severityLevelCode  is 2 or 3
        /// </summary>
        /// <param name="mdsResult"></param>
        public static void FilterMdsResult(this MDSCheckResult mdsResult)
        {
            var mdsResultForCheck = mdsResult;

            if (mdsResultForCheck.drugAllergyCheckingResults != null && mdsResultForCheck.drugAllergyCheckingResults.hasDrugAllergyAlert)
            {
                for (int a = (mdsResultForCheck.drugAllergyCheckingResults.drugAllergyAlerts.Count() - 1); a >= 0; a--)
                {
                    //System should ignore the allergy alerts when suppress flag is true
                    if (mdsResultForCheck.drugAllergyCheckingResults.drugAllergyAlerts[a].suppress == true)
                    {
                        mdsResult.drugAllergyCheckingResults.drugAllergyAlerts.Remove(mdsResultForCheck.drugAllergyCheckingResults.drugAllergyAlerts[a]);
                    }
                }
            }

            if (mdsResultForCheck.ddcmCheckingResults != null && mdsResultForCheck.ddcmCheckingResults.hasDdcmAlert && mdsResultForCheck.ddcmCheckingResults.hasG6PdDeficiencyAlert)
            {
                for (int d = (mdsResultForCheck.ddcmCheckingResults.ddcmAlerts.Count() - 1); d >= 0; d--)
                {
                    //System should ignore the G6PD alerts when suppress flag is true
                    //System should ignore the G6PD deficiency contraindication alert when the severityLevelCode is 2 or 3
                    if (mdsResultForCheck.ddcmCheckingResults.ddcmAlerts[d].suppress = true || (new string[] { "2", "3" }.Contains(mdsResultForCheck.ddcmCheckingResults.ddcmAlerts[d].severityLevelCode)))
                    {
                        mdsResult.ddcmCheckingResults.ddcmAlerts.Remove(mdsResultForCheck.ddcmCheckingResults.ddcmAlerts[d]);
                    }
                }
            }
        }
Exemple #2
0
        public MdsCheckFinalResult MDSCheck(InventoryObj drugItem, string caseNumber, PatientDemoEnquiry patientEnquiry, AlertProfileResult alertProfileRes)
        {
            MDSCheckResult resultBeforeMDS = new MDSCheckResult()
            {
                hasMdsAlert = false
            };

            if (alertProfileRes == null ||
                (alertProfileRes.AdrProfile.Count == 0 &&
                 alertProfileRes.AlertProfile.Count == 0 &&
                 alertProfileRes.AllergyProfile.Count == 0)
                )
            {
                /*ErrorMessage = "System cannot perform Allergy, ADR and G6PD Deficiency Contraindication checking.
                 * Please exercise your professional judgement during the downtime period and contact [vendor contact information].*/
                resultBeforeMDS.errorCode = "8520001001";
                //system error, hasMdsAlert = false, only medication alert, hasMdsAlert = true

                resultBeforeMDS.errorDesc = "System cannot perform Allergy, AlertProfile is empty.";
                //here should use drug name, not drugItemCode
                return(resultBeforeMDS.ToConvert(drugItem.CommonName));
            }

            #region check if need MDS check

            /****2.5.3 3:System should not perform MDS checking on a drug item if its itemCode starts with “PDF”,
             * e.g. “PDF 2Q “, “PDF 48”. no prompt message *****/
            if (mdsChecker.CheckDrugCodeIfNoNeedMDSCheck(drugItem.Billnum))
            {
                //here should use drug name, not drugItemCode
                return(resultBeforeMDS.ToConvert(drugItem.CommonName));
            }
            /*****2.5.3 2: ADR record (1.4.2) if its severity is “Mild”, not perform MDS checking for current ADR profile*****/
            mdsChecker.CheckADRProfileForMDSCheck(ref alertProfileRes, caseNumber);

            #endregion

            var CASE_NUMBER  = patientEnquiry.CaseList[0].Number.Trim().ToUpper();
            var patientCache = FullCacheHK.PataientCache[CASE_NUMBER];

            var getDrugMdsPropertyHqReq = new GetDrugMdsPropertyHqRequest
            {
                Arg0 = new Arg {
                    ItemCode = new List <string> {
                        drugItem.Billnum
                    }
                }
            };
            var getDrugMdsPropertyHqRes = soapSvc.GetDrugMdsPropertyHq(getDrugMdsPropertyHqReq);

            #region JUST FOR SIMULATOR
            if (patientCache != null)
            {
                patientCache.MDSCache.Register(drugItem.Billnum, new MDSCheckResultCache
                {
                    DrugMdsPropertyHqReq = getDrugMdsPropertyHqReq,
                    DrugMdsPropertyHqRes = getDrugMdsPropertyHqRes
                });
            }
            #endregion

            if (getDrugMdsPropertyHqRes == null || getDrugMdsPropertyHqRes.Return.Count == 0)
            {
                resultBeforeMDS.errorCode = "8520001002";
                resultBeforeMDS.errorDesc = "System cannot perform Allergy, Drug Master Response is empty.";

                return(resultBeforeMDS.ToConvert(drugItem.CommonName));
            }

            var drugProperty      = getDrugMdsPropertyHqRes.Return[0].DrugProperty;
            var getPreparationReq = new GetPreparationRequest
            {
                Arg0 = new Arg0
                {
                    DispHospCode    = "",
                    DispWorkstore   = "",
                    ItemCode        = drugItem.Billnum,
                    TrueDisplayname = drugProperty.Displayname,
                    FormCode        = drugProperty.FormCode,
                    SaltProperty    = drugProperty.SaltProperty,
                    DrugScope       = "I",
                    SpecialtyType   = "I",
                    PasSpecialty    = "",
                    PasSubSpecialty = "",
                    CostIncluded    = true,
                    HqFlag          = true
                }
            };
            var getPreparationRes = soapSvc.GetPreparation(getPreparationReq);
            if (getPreparationRes == null || getPreparationRes.Return == null)
            {
                resultBeforeMDS.errorCode = "8520001003";
                resultBeforeMDS.errorDesc = "System cannot perform Allergy, Drug Preparation Response is empty.";

                return(resultBeforeMDS.ToConvert(drugItem.CommonName));
            }

            #region JUST FOR SIMULATOR
            if (patientCache != null)
            {
                patientCache.MDSCache[drugItem.Billnum].PreparationReq = getPreparationReq;
                patientCache.MDSCache[drugItem.Billnum].PreparationRes = getPreparationRes;
            }
            #endregion

            string drugName = drugProperty.Displayname;

            /*if  hasG6pdDeficiency is true or  hasPregnancy is true, then “true”, else “false”*/
            bool hasG6pdDeficiency = mdsChecker.CheckIsG6PD(alertProfileRes.AlertProfile);

            bool checkDdcm = hasG6pdDeficiency;
            bool checkDam  = alertProfileRes.AllergyProfile.Count() > 0;
            bool checkAdr  = alertProfileRes.AdrProfile.Count() > 0;

            //if no ddcm, no allergy, no adr, then no need do MDS check
            if (!checkDdcm && !checkDam && !checkAdr)
            {
                return(new MdsCheckFinalResult());
            }

            MDSCheckInputParm mdsRequest = new MDSCreater().CreateMDSRequest(patientEnquiry,
                                                                             alertProfileRes,
                                                                             getDrugMdsPropertyHqRes,
                                                                             getPreparationRes,
                                                                             ref drugName
                                                                             );
            /************do Final MDS Check*********************/
            MDSCheckResult mdsCheckResult = restSvc.CheckMDS(mdsRequest);
            //filter final MDS check result
            mdsCheckResult.FilterMdsResult();

            #region JUST FOR SIMULATOR
            if (patientCache != null)
            {
                patientCache.MDSCache[drugItem.Billnum].Req = mdsRequest;
                patientCache.MDSCache[drugItem.Billnum].Res = mdsCheckResult;
            }
            #endregion

            //convert mds result to message object to show
            return(mdsCheckResult.ToConvert(drugName));
        }
        /// <summary>
        /// to generate final MDS check message
        /// </summary>
        /// <param name="mdsResult"></param>
        /// <param name="drugName"></param>
        /// <returns></returns>
        public static MdsCheckFinalResult ToConvert(this MDSCheckResult mdsResult, string drugName)
        {
            MdsCheckFinalResult resultForShow = new MdsCheckFinalResult();

            resultForShow.DrugName = drugName;
            #region system error
            if (false == string.IsNullOrEmpty(mdsResult.errorDesc))
            {
                resultForShow.SystemErrorMessage += mdsResult.errorDesc + Environment.NewLine;
            }
            if (mdsResult.allergyError != null && mdsResult.allergyError.hasAllergyError)
            {
                resultForShow.SystemErrorMessage += ResultBuilder(resultForShow, mdsResult.allergyError);
            }
            if (mdsResult.adrError != null && mdsResult.adrError.hasAdrError)
            {
                resultForShow.SystemErrorMessage += ResultBuilder(resultForShow, mdsResult.adrError);
            }
            if (mdsResult.drugError != null && mdsResult.drugError.hasDrugError)
            {
                resultForShow.SystemErrorMessage += ResultBuilder(resultForShow, mdsResult.drugError);
            }
            #endregion

            #region allergy alert message
            if (mdsResult.drugAllergyCheckingResults != null && mdsResult.drugAllergyCheckingResults.hasDrugAllergyAlert)
            {
                resultForShow.HasMdsAlert = true;
                foreach (var allergyMsg in mdsResult.drugAllergyCheckingResults.drugAllergyAlerts)
                {
                    /*
                     * 1 Clinical Manifestations will be delimited by semicolon ";", if the last clinical manifestation is equal to additional information, system should hide the additional information field.
                     * 2 System should reconstruct the alert message if the following keyword is found in the message:
                     * Sequence of keyword matching	If the following keywords found in [drugAllergyAlertMessages]	Replace the message by the following message
                     * 1	an allergic/a cross-sensitivity	Use of uppercase[drugDdimDisplayName from 2.5.1] may result in allergic/cross-sensitivity reaction.
                     * 2	an idiosyncratic	Use of uppercase[drugDdimDisplayName from 2.5.1] may result in idiosyncratic reaction.
                     * 3	an allergic	Use of uppercase[drugDdimDisplayName from 2.5.1] may result in allergic reaction.
                     * 4	a cross-sensitivity	Use of uppercase[drugDdimDisplayName from 2.5.1] may result in cross-sensitivity reaction.
                     */

                    allergyMsg.drugAllergyAlertMessage = WrapperAllergyCheckResultMessage(drugName, allergyMsg.drugAllergyAlertMessage);

                    allergyMsg.manifestation.TrimEnd(new char[] { ';' });

                    StringBuilder sbuilder = new StringBuilder();
                    sbuilder.AppendLine(string.Format("{0} - Allergy history reported", allergyMsg.allergen));
                    sbuilder.AppendLine(string.Format("Clinical Manifestation: {0}", allergyMsg.manifestation));
                    sbuilder.AppendLine(string.Format("Additional Information: {0}", allergyMsg.remark));
                    sbuilder.AppendLine(string.Format("Level of Certainty: {0}", allergyMsg.certainty));
                    sbuilder.AppendLine(allergyMsg.drugAllergyAlertMessage);

                    //   resultForShow.MdsCheckAlertDetails.Add(new MdsCheckAlert("Allergy Checking", sbuilder.ToString()));
                }
            }
            #endregion

            #region ddcm alert (G6PD alert)
            if (mdsResult.ddcmCheckingResults != null && mdsResult.ddcmCheckingResults.hasDdcmAlert)
            {
                foreach (string ddcmAlert in mdsResult.ddcmCheckingResults.ddcmAlertMessages)
                {
                    //  resultForShow.MdsCheckAlertDetails.Add(new MdsCheckAlert("G6PD Deficiency Contraindication Checking", ddcmAlert));
                }
            }
            #endregion

            #region adr alert
            if (mdsResult.drugAdrCheckingResults != null && mdsResult.drugAdrCheckingResults.hasDrugAdrAlert)
            {
                foreach (DrugAdrAlert adrAlert in mdsResult.drugAdrCheckingResults.drugAdrAlerts)
                {
                    adrAlert.reaction.TrimEnd(new char[] { ';' });

                    adrAlert.drugAdrAlertMessage = WrapperAdrCheckResultAlertMessage(drugName, adrAlert.drugAdrAlertMessage);

                    StringBuilder sbuilder = new StringBuilder();
                    sbuilder.AppendLine(string.Format("{0} - Adverse drug reaction history reported", drugName));
                    sbuilder.AppendLine(string.Format("Adverse Drug Reaction: {0}", adrAlert.reaction));
                    sbuilder.AppendLine(string.Format("Additional Information: {0}", adrAlert.remark));
                    sbuilder.AppendLine(string.Format("Level of Certainty: {0}", adrAlert.severity));
                    sbuilder.AppendLine(adrAlert.drugAdrAlertMessage);

                    //  resultForShow.MdsCheckAlertDetails.Add(new MdsCheckAlert("Adverse Drug Reaction Checking", sbuilder.ToString()));
                }
            }
            #endregion

            return(resultForShow);
        }