コード例 #1
0
        public int PatientCheckin()
        {
            int result = 0;

            try
            {
                int patientId = Convert.ToInt32(Session["PatientPK"]);
                int userId    = Convert.ToInt32(Session["AppUserId"]);
                PatientMasterVisitManager patientMasterVisit = new PatientMasterVisitManager();
                LookupLogic lookupLogic     = new LookupLogic();
                var         currentfacility = lookupLogic.GetFacility(Session["AppPosID"].ToString());
                if (currentfacility == null)
                {
                    currentfacility = lookupLogic.GetFacility();
                }
                result = patientMasterVisit.PatientMasterVisitCheckin(patientId, userId, currentfacility.FacilityID);

                /* Assign to patientMsterVisitId session*/
                Session["EncounterStatusId"]    = 1;
                Session["PatientMasterVisitId"] = result;
                Session["PatientEditId"]        = patientId;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(result);
        }
コード例 #2
0
        public string addHIVEDucation(int patientId, string visitdate, int councellingTypeId, string councellingType, int councellingTopicId, string councellingTopic, string comments, string other)
        {
            try
            {
                PatientManager patientManager = new PatientManager();
                LookupLogic    lookupLogic    = new LookupLogic();
                PatientEntity  patient        = patientManager.GetPatientEntity(patientId);
                int            ptn_pk         = patient.ptn_pk.HasValue ? patient.ptn_pk.Value : 0;
                int            posID          = Convert.ToInt32(Session["AppPosID"]);
                var            facility       = lookupLogic.GetFacility(posID.ToString());
                int            facilityId     = 0;
                if (facility != null)
                {
                    facilityId = facility.FacilityID;
                }
                var mstPatientLogic = new MstPatientLogic();
                int userId          = Convert.ToInt32(Session["AppUserId"]);

                int visit_Pk = mstPatientLogic.AddOrdVisit(ptn_pk, facilityId, DateTime.Parse(visitdate), 10, userId, DateTime.Now, 203);
                var HEF      = new HIVEducationLogic();
                Result = HEF.AddPatientHIVEducation(ptn_pk, facilityId, userId, visit_Pk, DateTime.Parse(visitdate), councellingTypeId, councellingType, councellingTopicId, councellingTopic, comments, other);
                if (Result > 0)
                {
                    Msg = "Notes Added";
                }
            }
            catch (Exception e)
            {
                Msg = e.Message;
            }
            return(Msg);
        }
コード例 #3
0
        public static string Add(string firstName, string middleName, string lastName, int sex, int userId, DateTime dob, bool dobPrecision, int facilityId,
                                 int patientType, string nationalId, int visitType, DateTime dateOfEnrollment, string cccNumber, int entryPointId, string godsNumber, int matStatusId,
                                 string village, int wardId, int subCountyId, int countyId, string nearestLandMark, string postalAdress, string phoneNumber, DateTime?deathDate,
                                 List <NEXTOFKIN> nextofkin)
        {
            try
            {
                PersonManager              personManager             = new PersonManager();
                PatientManager             patientManager            = new PatientManager();
                PatientMasterVisitManager  patientMasterVisitManager = new PatientMasterVisitManager();
                PatientEnrollmentManager   patientEnrollmentManager  = new PatientEnrollmentManager();
                PatientEntryPointManager   patientEntryPointManager  = new PatientEntryPointManager();
                PersonLookUpManager        personLookUp = new PersonLookUpManager();
                PersonContactLookUpManager personContactLookUpManager = new PersonContactLookUpManager();
                MstPatientLogic            mstPatientLogic            = new MstPatientLogic();
                PatientIdentifierManager   patientIdentifierManager   = new PatientIdentifierManager();
                PersonMaritalStatusManager personMaritalStatusManager = new PersonMaritalStatusManager();
                PersonLocationManager      locationManager            = new PersonLocationManager();
                PersonContactManager       contactManager             = new PersonContactManager();
                var         treatmentSupporterManager = new PatientTreatmentSupporterManager();
                LookupLogic lookupLogic = new LookupLogic();

                var personIdentifierManager = new PersonIdentifierManager();
                //todo: fetch assigning facility from the message
                string assigning_Facility = "";
                var    personContacts     = new List <PersonContactLookUp>();
                int    ptn_Pk             = 0;

                //Start Saving
                int personId = personManager.AddPersonUiLogic(firstName, middleName, lastName, sex, userId, dob, dobPrecision);
                if (matStatusId > 0)
                {
                    personMaritalStatusManager.AddPatientMaritalStatus(personId, matStatusId, userId);
                }
                if (wardId > 0 && subCountyId > 0 && countyId > 0)
                {
                    locationManager.AddPersonLocation(personId, countyId, subCountyId, wardId, village, "", "", nearestLandMark, nearestLandMark, userId);
                }
                if (postalAdress != null || phoneNumber != null)
                {
                    contactManager.AddPersonContact(personId, postalAdress, phoneNumber, "", "", userId);
                }

                String   sDate        = DateTime.Now.ToString();
                DateTime datevalue    = Convert.ToDateTime(sDate);
                var      patientIndex = datevalue.Year.ToString() + '-' + personId;

                if (!string.IsNullOrWhiteSpace(godsNumber))
                {
                    IdentifierManager identifierManager = new IdentifierManager();
                    Identifier        identifier        = identifierManager.GetIdentifierByCode("GODS_NUMBER");
                    var personIdentifiers = personIdentifierManager.GetPersonIdentifiers(personId, identifier.Id);
                    if (personIdentifiers.Count == 0)
                    {
                        personIdentifierManager.AddPersonIdentifier(personId, identifier.Id, godsNumber, userId, assigning_Facility);
                    }
                }

                if (nextofkin.Count > 0)
                {
                    foreach (var kin in nextofkin)
                    {
                        if (kin.CONTACT_ROLE == "T")
                        {
                            //Get Gender
                            string gender = kin.SEX == "F" ? "Female" : "Male";
                            //IQCare Sex
                            int sexT = lookupLogic.GetItemIdByGroupAndItemName("Gender", gender)[0].ItemId;

                            int supporterId = personManager.AddPersonTreatmentSupporterUiLogic(kin.NOK_NAME.FIRST_NAME, kin.NOK_NAME.MIDDLE_NAME, kin.NOK_NAME.LAST_NAME, sexT, 1);

                            if (supporterId > 0)
                            {
                                treatmentSupporterManager.AddPatientTreatmentSupporter(personId, supporterId, kin.PHONE_NUMBER, userId);
                            }
                        }
                    }
                }

                PatientEntity patientEntity = new PatientEntity();
                patientEntity.PersonId     = personId;
                patientEntity.ptn_pk       = 0;
                patientEntity.FacilityId   = facilityId;
                patientEntity.PatientType  = patientType;
                patientEntity.PatientIndex = patientIndex;
                patientEntity.DateOfBirth  = dob;
                patientEntity.NationalId   = (nationalId);
                patientEntity.Active       = true;
                patientEntity.CreatedBy    = 1;
                patientEntity.CreateDate   = DateTime.Now;
                patientEntity.DeleteFlag   = false;
                patientEntity.DobPrecision = dobPrecision;

                int patientId = patientManager.AddPatient(patientEntity);

                var facility = lookupLogic.GetFacility();
                //Add enrollment visit
                int patientMasterVisitId = patientMasterVisitManager.AddPatientMasterVisit(patientId, userId, visitType, facility.FacilityID);
                //Enroll Patient to service
                int patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, dateOfEnrollment.ToString(), userId);
                //Add enrollment entry point
                int patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);

                if (deathDate.HasValue)
                {
                    PatientCareEndingManager careEndingManager = new PatientCareEndingManager();
                    int itemId = lookupLogic.GetItemIdByGroupAndItemName("CareEnded", "Death")[0].ItemId;
                    careEndingManager.AddPatientCareEndingDeath(patientId, patientMasterVisitId, patientEnrollmentId, itemId, deathDate.Value, deathDate.Value, "", null, null);

                    PatientEntityEnrollment entityEnrollment = patientEnrollmentManager.GetPatientEntityEnrollment(patientEnrollmentId);
                    entityEnrollment.CareEnded = true;
                    patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);
                }
                //Get User Details to be used in BLUE CARD
                var patient_person_details = personLookUp.GetPersonById(personId);
                var greencardlookup        = new PersonGreenCardLookupManager();
                var greencardptnpk         = greencardlookup.GetPtnPkByPersonId(personId);

                if (patient_person_details != null)
                {
                    var maritalStatus = new PersonMaritalStatusManager().GetCurrentPatientMaritalStatus(personId);
                    personContacts = personContactLookUpManager.GetPersonContactByPersonId(personId);
                    var address = "";
                    var phone   = "";

                    if (personContacts.Count > 0)
                    {
                        address = personContacts[0].PhysicalAddress;
                        phone   = personContacts[0].MobileNumber;
                    }

                    var MaritalStatusId = 0;
                    if (maritalStatus != null)
                    {
                        MaritalStatusId = maritalStatus.MaritalStatusId;
                    }

                    var sexBluecard          = 0;
                    var enrollmentBlueCardId = "";

                    if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Male")
                    {
                        sexBluecard = 16;
                    }
                    else if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Female")
                    {
                        sexBluecard = 17;
                    }

                    enrollmentBlueCardId = cccNumber;

                    if (greencardptnpk.Count == 0)
                    {
                        ptn_Pk = mstPatientLogic.InsertMstPatient((patient_person_details.FirstName), (patient_person_details.LastName), (patient_person_details.MiddleName), facilityId, enrollmentBlueCardId, entryPointId, dateOfEnrollment, sexBluecard, dob, 1, MaritalStatusId, address, phone, 1, facilityId.ToString(), 203, dateOfEnrollment, DateTime.Now);

                        patientEntity.ptn_pk = ptn_Pk;
                        patientManager.UpdatePatient(patientEntity, patientId);
                    }
                    else
                    {
                        ptn_Pk = greencardptnpk[0].Ptn_Pk;
                        patientEntity.ptn_pk = greencardptnpk[0].Ptn_Pk;
                        patientManager.UpdatePatient(patientEntity, patientId);
                    }
                }

                if (patientMasterVisitId > 0)
                {
                    var assigningFacility   = cccNumber.Substring(0, 5);
                    int patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patientId, patientEnrollmentId, 1, cccNumber, facilityId, assigningFacility, false);

                    if (greencardptnpk.Count == 0)
                    {
                        mstPatientLogic.AddOrdVisit(ptn_Pk, facilityId, DateTime.Now, 110, userId, DateTime.Now, 203);
                    }
                }

                return("successfully saved");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #4
0
        public string Process(DtoDrugDispensed drugDispensed)
        {
            try
            {
                LookupLogic facilityLookup           = new LookupLogic();
                string      receivingFacilityMflCode = drugDispensed.MESSAGE_HEADER.RECEIVING_FACILITY;
                string      sendingFacilityMflCode   = drugDispensed.MESSAGE_HEADER.SENDING_FACILITY;
                //check if facility exists
                LookupFacility recieverfacility = facilityLookup.GetFacility(receivingFacilityMflCode);
                LookupFacility senderfacility   = facilityLookup.GetFacility(sendingFacilityMflCode);
                if (recieverfacility == null)
                {
                    return(Msg = $"The facility {receivingFacilityMflCode} does not exist");
                }
                if (senderfacility == null)
                {
                    return(Msg = $"The facility {sendingFacilityMflCode} does not exist");
                }

                if (recieverfacility.FacilityID != senderfacility.FacilityID)
                {
                    return(Msg = "The sending facility is not the same as the receiving facility!");
                }

                //check if it is the right facility
                LookupFacility thisFacility = facilityLookup.GetFacility();
                if (thisFacility == null)
                {
                    return(Msg = "Facility not found");
                }
                if (recieverfacility.FacilityID != thisFacility.FacilityID)
                {
                    return(Msg = $"This message belongs to {receivingFacilityMflCode}, not this facility {thisFacility.MFLCode}!");
                }
                var patientLookup = new PatientLookupManager();
                //check patient
                var identifier = drugDispensed.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID.FirstOrDefault(n => n.IDENTIFIER_TYPE == "CCC_NUMBER");
                if (identifier == null)
                {
                    return(Msg = "Message does not contain a CCC number!");
                }
                var patient = patientLookup.GetPatientByCccNumber(identifier.ID);
                if (patient == null)
                {
                    return(Msg = "Patient could not be found!");
                }
                //check pharmacy order exists
                int orderId       = Convert.ToInt32(drugDispensed.COMMON_ORDER_DETAILS.PLACER_ORDER_NUMBER.NUMBER);
                var pharmacyOrder = _pharmacyOrderManager.GetPharmacyOrder(orderId);
                if (pharmacyOrder == null)
                {
                    return(Msg = "Pharmacy Order could not be found!");
                }
                var orderedDrugs = _pharmacyDispenseManager.GetByPharmacyOrderId(pharmacyOrder.ptn_pharmacy_pk);
                if (orderedDrugs != null)
                {
                    var newDispensedDrugs = orderedDrugs;
                    foreach (var drug in newDispensedDrugs)
                    {
                        //todo refactor to use drug codes and possibly drug ids to be included in the message
                        var               drugFind         = _drugManager.GetDrug(drug.Drug_Pk);
                        string            drugname         = drugFind.DrugName;
                        PHARMACY_DISPENSE messageDispensed = null;
                        messageDispensed = drugDispensed.PHARMACY_DISPENSE.FirstOrDefault(x => drugname.Contains(x.ACTUAL_DRUGS));
                        if (messageDispensed != null)
                        {
                            drug.DispensedQuantity = messageDispensed.QUANTITY_DISPENSED;
                            //todo get frequencyId
                            //drug.FrequencyID = messageDispensed.FREQUENCY;
                            drug.PatientInstructions = messageDispensed.DISPENSING_NOTES;
                            //todo get strength ids
                            //drug.StrengthID = messageDispensed.STRENGTH;
                            drug.Duration   = messageDispensed.DURATION;
                            drug.UpdateDate = DateTime.Now;
                            drug.UserID     = InteropUser.UserId;
                            //drug.SingleDose = Convert.ToDecimal(Regex.Replace(messageDispensed.DOSAGE, @"^[A-Za-z]+", ""));
                        }
                        try
                        {
                            _pharmacyDispenseManager.UpdatePatientPharmacyDispense(drug);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            return(Msg = "error " + e.Message);
                        }
                    }
                }
                else
                {
                    PatientPharmacyDispense newlyDispensedDrugs = new PatientPharmacyDispense();
                    foreach (var drug in drugDispensed.PHARMACY_DISPENSE)
                    {
                        string drugNameQuery = "%" + drug.ACTUAL_DRUGS + "%";
                        var    drugFind      = _drugManager.GetDrugsByName(drugNameQuery).FirstOrDefault();
                        newlyDispensedDrugs.Drug_Pk           = drugFind.Drug_pk;
                        newlyDispensedDrugs.DispensedQuantity = drug.QUANTITY_DISPENSED;
                        newlyDispensedDrugs.Duration          = drug.DURATION;
                        //todo get frequencyId
                        //newlyDispensedDrugs.FrequencyID = drug.FREQUENCY;
                        //newlyDispensedDrugs.SingleDose = Convert.ToDecimal(Regex.Replace(drug.DOSAGE, @"^[A-Za-z]+", ""));
                        //todo get strength ids
                        //newlyDispensedDrugs.StrengthID = drug.STRENGTH;
                        newlyDispensedDrugs.PatientInstructions = drug.DISPENSING_NOTES;
                        newlyDispensedDrugs.Prophylaxis         = 0;
                    }
                    foreach (var order in drugDispensed.PHARMACY_ENCODED_ORDER)
                    {
                        newlyDispensedDrugs.OrderedQuantity     = Convert.ToInt32(order.QUANTITY_PRESCRIBED);
                        newlyDispensedDrugs.PatientInstructions = order.PRESCRIPTION_NOTES;
                    }
                    try
                    {
                        _pharmacyDispenseManager.AddPatientPharmacyDispense(newlyDispensedDrugs);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        return(Msg = "error " + e.Message);
                    }
                }
                var updatedPharmacyOrder = pharmacyOrder;
                var orderingPhysician    = drugDispensed.COMMON_ORDER_DETAILS.ORDERING_PHYSICIAN;
                updatedPharmacyOrder.OrderedByName = orderingPhysician.PREFIX + " " + orderingPhysician.FIRST_NAME +
                                                     " " + orderingPhysician.LAST_NAME;
                //todo harmonise users
                updatedPharmacyOrder.DispensedBy     = InteropUser.UserId;
                updatedPharmacyOrder.DispensedByDate = drugDispensed.MESSAGE_HEADER.MESSAGE_DATETIME;
                updatedPharmacyOrder.OrderStatus     = 2;
                string str = updatedPharmacyOrder.PharmacyNotes;
                if (str != null)
                {
                    str += " Dispensed from IL";
                }
                updatedPharmacyOrder.PharmacyNotes = str;
                try
                {
                    _pharmacyOrderManager.UpdatePharmacyOrder(updatedPharmacyOrder);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(Msg = "error " + e.Message);
                }
                Msg = "Success";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Msg = "error " + e.Message;
            }
            return(Msg);
        }
コード例 #5
0
        public string GetPatientMasterVisitId(int PatientId, DateTime visitDate, string EncounterType, int ServiceAreaId, int UserId)
        {
            PatientMasterVisitManager pmvManager       = new PatientMasterVisitManager();
            List <PatientMasterVisit> pmv              = new List <PatientMasterVisit>();
            PatientEncounterLogic     patientEncounter = new PatientEncounterLogic();
            OutCome ResultOutcome = new OutCome();

            pmv = pmvManager.GetPatientMasterVisitBasedonVisitDate(PatientId, visitDate);
            if (pmv != null)
            {
                if (pmv.Count > 0)
                {
                    MasterVisitId = pmv[0].Id;
                }
            }


            if (MasterVisitId > 0)
            {
                Result = patientEncounter.SavePatientPreviousEncounter(PatientId, MasterVisitId, EncounterType, ServiceAreaId, Convert.ToInt32(Session["AppUserId"]), visitDate);
                if (Result > 0)
                {
                    ResultOutcome.Result = MasterVisitId;
                    ResultOutcome.Msg    = EncounterType + " Encounter Saved";
                }
            }
            else
            {
                var lookupLogic = new LookupLogic();
                var facility    = lookupLogic.GetFacility(Session["AppPosID"].ToString());
                if (facility == null)
                {
                    facility = lookupLogic.GetFacility();
                }

                PatientMasterVisit pm = new PatientMasterVisit();
                pm.ServiceId  = 1;
                pm.VisitDate  = visitDate;
                pm.VisitBy    = UserId;
                pm.Start      = visitDate;
                pm.End        = visitDate;
                pm.PatientId  = PatientId;
                pm.CreatedBy  = UserId;
                pm.Active     = true;
                pm.Status     = 2;
                pm.FacilityId = facility.FacilityID;

                int PatientMasterVisitId = pmvManager.AddPatientMasterVisit(pm);

                int res = patientEncounter.SavePatientPreviousEncounter(PatientId, PatientMasterVisitId, EncounterType, ServiceAreaId, Convert.ToInt32(Session["AppUserId"]), visitDate);
                if (res > 0)
                {
                    Result = PatientMasterVisitId;
                    ResultOutcome.Result = Result;
                    ResultOutcome.Msg    = EncounterType + "Encounter Saved";
                }
            }
            string jsonScreeningObject = "[]";

            jsonScreeningObject = new JavaScriptSerializer().Serialize(ResultOutcome);
            return(jsonScreeningObject);
        }
コード例 #6
0
        //int _userId = Convert.ToInt32(HttpContext.Current.Session["AppUserId"]);
        //int _facilityId = Convert.ToInt32(HttpContext.Current.Session["AppLocationId"]);
        public string Save(ViralLoadResultsDto viralLoadResults)
        {
            LabOrderEntity          labOrder   = null;
            List <LabDetailsEntity> labDetails = null;
            var results = viralLoadResults.ViralLoadResult;

            if (results != null)
            {
                try
                {
                    var            patientLookup            = new PatientLookupManager();
                    var            labOrderManager          = new PatientLabOrderManager();
                    var            patientCcc               = viralLoadResults.PatientIdentification.INTERNAL_PATIENT_ID.FirstOrDefault(n => n.IdentifierType == "CCC_NUMBER").IdentifierValue;
                    var            patient                  = patientLookup.GetPatientByCccNumber(patientCcc);
                    string         receivingFacilityMFLCode = viralLoadResults.MesssageHeader.ReceivingFacility;
                    LookupLogic    flm           = new LookupLogic();
                    LookupFacility thisFacility  = flm.GetFacility(receivingFacilityMFLCode);
                    int            interopUserId = InteropUser.UserId;
                    if (thisFacility == null)
                    {
                        Msg = $"The facility {receivingFacilityMFLCode} does not exist";
                        throw new Exception(Msg);
                    }
                    if (patient == null)
                    {
                        Msg = $"Patient {patientCcc} does not exist ";
                        throw new Exception(Msg);
                    }
                    if (results.Count(r => string.IsNullOrWhiteSpace(r.VlResult.Trim())) > 0)
                    {
                        Msg = $"Viral load message has no results indicated ";
                        throw new Exception(Msg);
                    }
                    int invalidResult = 0;
                    foreach (var result in results)
                    {
                        if (result.VlResult.Contains("LDL"))
                        {
                        }
                        else if (Regex.Split(result.VlResult, @"[^0-9\.]+").Length > 0)
                        {
                        }
                        else
                        {
                            invalidResult++;
                        }
                    }

                    if (invalidResult > 0)
                    {
                        Msg = $"Viral load message has invalid results indicated ";
                        throw new Exception(Msg);
                    }
                    if (patient != null && thisFacility != null)
                    {
                        //todo brian check
                        labOrder = labOrderManager.GetPatientLabOrdersByDate((int)patient.ptn_pk, results.FirstOrDefault().DateSampleCollected).DefaultIfEmpty(null).FirstOrDefault();
                        DateTime sampleCollectionDate = results.FirstOrDefault().DateSampleCollected;
                        if (labOrder == null)
                        {
                            var patientMasterVisitManager = new PatientMasterVisitManager();

                            //var visitType = flm.GetItemIdByGroupAndItemName("VisitType", "Enrollment")[0]
                            //    .ItemId;
                            int patientMasterVisitId =
                                patientMasterVisitManager.AddPatientMasterVisit(patient.Id, interopUserId, 316);
                            var listOfTestsOrdered = new List <ListLabOrder>();
                            var order = new ListLabOrder()
                            {
                                FacilityId   = Convert.ToInt32(viralLoadResults.MesssageHeader.ReceivingFacility),
                                LabName      = "Viral Load",// results.FirstOrDefault().LabTestedIn,
                                LabNameId    = 3,
                                LabNotes     = results.FirstOrDefault().Regimen + " " + results.FirstOrDefault().SampleType,
                                LabOrderDate = sampleCollectionDate,
                                LabOrderId   = 0,
                                OrderReason  = "",
                                Results      = results.FirstOrDefault().VlResult,
                                VisitId      = patientMasterVisitId,
                                ResultDate   = viralLoadResults.MesssageHeader.MessageDatetime
                            };
                            listOfTestsOrdered.Add(order);
                            var    jss             = new JavaScriptSerializer();
                            string patientLabOrder = jss.Serialize(listOfTestsOrdered);
                            //include userid and facility ID
                            int orderId = labOrderManager.savePatientLabOrder(patient.Id, (int)patient.ptn_pk, interopUserId, thisFacility.FacilityID, 203, patientMasterVisitId, sampleCollectionDate.ToString(), "IL lab order", patientLabOrder, "Complete");

                            labOrder   = labOrderManager.GetLabOrdersById(orderId);
                            labDetails = labOrderManager.GetLabTestsOrderedById(labOrder.Id);
                        }
                        else
                        {
                            labDetails = labOrderManager.GetLabTestsOrderedById(labOrder.Id);
                        }

                        if (labOrder != null)
                        {
                            bool    isUndetectable = false;
                            string  resultText     = "";
                            decimal?resultValue    = null;
                            foreach (var result in results)
                            {
                                if (result.VlResult.Contains("LDL"))
                                {
                                    isUndetectable = true;
                                    resultText     = result.VlResult;
                                }
                                else
                                {
                                    var      resultString = result.VlResult.Replace("copies/ml", "");
                                    string[] numbers      = Regex.Split(resultString, @"[^0-9\.]+");
                                    //bool isSuccess = decimal.TryParse(resultString, out decimalValue);
                                    //if (isSuccess) resultValue = decimalValue;
                                    for (int i = 0; i < numbers.Length; i++)
                                    {
                                        if (Regex.IsMatch(numbers[i], @"^\d+$"))
                                        {
                                            resultValue = Convert.ToDecimal(numbers[i]);
                                            break;
                                        }
                                    }
                                }

                                if (labOrder != null)
                                {
                                    var labResults = new LabResultsEntity()
                                    {
                                        //todo remove hard coding
                                        LabOrderId     = labOrder.Id,
                                        LabOrderTestId = labDetails.FirstOrDefault().Id,
                                        ParameterId    = 3,
                                        LabTestId      = 3,
                                        ResultText     = resultText,
                                        ResultValue    = resultValue,
                                        ResultUnit     = "copies/ml",
                                        ResultUnitId   = 129,
                                        Undetectable   = isUndetectable,
                                        StatusDate     = result.DateSampleTested,
                                        HasResult      = true
                                    };
                                    labOrderManager.AddPatientLabResults(labResults);
                                    labOrder.OrderStatus = "Complete";
                                    labOrderManager.savePatientLabOrder(labOrder);
                                }
                            }
                            Msg = "Success";
                        }
                    }
                    else
                    {
                        Msg = "Patient does not exist";
                        return(Msg);
                    }
                }
                catch (Exception e)
                {
                    Msg = "error " + e.Message;
                    throw e;
                }
            }
            else
            {
                Msg = "Message does not contain results";
                throw new Exception(Msg);
            }
            return(Msg);
        }
コード例 #7
0
        public string AddPatient(int facilityId, int entryPointId, string enrollmentDate, string personDateOfBirth, string nationalId, int patientType, string dobPrecision, string identifiersList)
        {
            ExMessage message = new ExMessage();

            try
            {
                PersonId = int.Parse(Session["PersonId"].ToString());
                int userId = Convert.ToInt32(Session["AppUserId"]);

                var patientManager             = new PatientManager();
                var patientMasterVisitManager  = new PatientMasterVisitManager();
                var patientEnrollmentManager   = new PatientEnrollmentManager();
                var patientIdentifierManager   = new PatientIdentifierManager();
                var patientEntryPointManager   = new PatientEntryPointManager();
                var patientLookUpManager       = new PatientLookupManager();
                var mstPatientLogic            = new MstPatientLogic();
                var personContactLookUpManager = new PersonContactLookUpManager();
                var personContacts             = new List <PersonContactLookUp>();
                var personLookUp = new PersonLookUpManager();
                var lookupLogic  = new LookupLogic();

                //var identifiersObjects = JsonConvert.DeserializeObject<Dictionary<int, string>>(identifiersList);
                var           identifiersObjects = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(identifiersList);
                String        sDate            = DateTime.Now.ToString();
                DateTime      datevalue        = Convert.ToDateTime(sDate);
                PatientLookup isPersonEnrolled = patientLookUpManager.GetPatientByPersonId(PersonId);
                dobPrecision = String.IsNullOrWhiteSpace(dobPrecision) ? "false" : "true";

                foreach (var item in identifiersObjects)
                {
                    var identifiers = patientIdentifierManager.CheckIfIdentifierNumberIsUsed(item.Value, Convert.ToInt32(item.Key));
                    if (identifiers.Count > 0)
                    {
                        foreach (var items in identifiers)
                        {
                            if (isPersonEnrolled != null)
                            {
                                if (items.PatientId == isPersonEnrolled.Id)
                                {
                                }
                                else
                                {
                                    var exception = new SoapException("No: " + item.Value + " already exists", SoapException.ClientFaultCode);
                                    throw exception;
                                }
                            }
                            else
                            {
                                var exception = new SoapException("No: " + item.Value + " already exists", SoapException.ClientFaultCode);
                                throw exception;
                            }
                        }
                    }
                }

                if (isPersonEnrolled != null)
                {
                    List <PatientRegistrationLookup> patientsByPersonId = patientManager.GetPatientIdByPersonId(PersonId);
                    var           patientIndex = datevalue.Year.ToString() + '-' + PersonId;
                    PatientEntity patient      = new PatientEntity();
                    if (patientsByPersonId.Count > 0)
                    {
                        patient.FacilityId  = facilityId;
                        patient.DateOfBirth = DateTime.Parse(personDateOfBirth);
                        patient.NationalId  = nationalId;
                        patient.ptn_pk      = patientsByPersonId[0].ptn_pk > 0 ? patientsByPersonId[0].ptn_pk : 0;

                        patientManager.UpdatePatient(patient, patientsByPersonId[0].Id);
                        patientId = patientsByPersonId[0].Id;
                    }
                    else
                    {
                        patient.PersonId     = PersonId;
                        patient.ptn_pk       = 0;
                        patient.FacilityId   = facilityId;
                        patient.PatientType  = patientType;
                        patient.PatientIndex = patientIndex;
                        patient.DateOfBirth  = DateTime.Parse(personDateOfBirth);
                        patient.NationalId   = (nationalId);
                        patient.Active       = true;
                        patient.CreatedBy    = userId;
                        patient.CreateDate   = DateTime.Now;
                        patient.DeleteFlag   = false;
                        patient.DobPrecision = bool.Parse(dobPrecision);

                        patientId = patientManager.AddPatient(patient);
                    }
                    Session["PatientPK"] = patientId;

                    if (patientId > 0)
                    {
                        var visitTypes = lookupLogic.GetItemIdByGroupAndItemName("VisitType", "Enrollment");
                        var visitType  = 0;
                        if (visitTypes.Count > 0)
                        {
                            visitType = visitTypes[0].ItemId;
                        }

                        //Add enrollment visit
                        patientMasterVisitId =
                            patientMasterVisitManager.AddPatientMasterVisit(patientId, userId, visitType);
                        //Enroll Patient to service
                        patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, enrollmentDate, userId);
                        //Add enrollment entry point
                        patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);

                        //Get User Details to be used in BLUE CARD
                        var patient_person_details = personLookUp.GetPersonById(PersonId);
                        var greencardlookup        = new PersonGreenCardLookupManager();
                        var greencardptnpk         = greencardlookup.GetPtnPkByPersonId(PersonId);

                        if (patient_person_details != null)
                        {
                            var maritalStatus =
                                new PersonMaritalStatusManager().GetCurrentPatientMaritalStatus(PersonId);
                            personContacts = personContactLookUpManager.GetPersonContactByPersonId(PersonId);
                            var address  = "";
                            var phone    = "";
                            var facility = lookupLogic.GetFacility();

                            if (personContacts.Count > 0)
                            {
                                address = personContacts[0].PhysicalAddress;
                                phone   = personContacts[0].MobileNumber;
                            }

                            var MaritalStatusId = 0;
                            if (maritalStatus != null)
                            {
                                MaritalStatusId = maritalStatus.MaritalStatusId;
                            }

                            var sex = 0;
                            var enrollmentBlueCardId = "";

                            if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Male")
                            {
                                sex = 16;
                            }
                            else if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Female")
                            {
                                sex = 17;
                            }

                            foreach (var item in identifiersObjects)
                            {
                                if (Convert.ToInt32(item.Key) == 1)
                                {
                                    enrollmentBlueCardId = item.Value;
                                }
                            }


                            if (greencardptnpk.Count == 0)
                            {
                                ptn_Pk = mstPatientLogic.InsertMstPatient(
                                    (patient_person_details.FirstName),
                                    (patient_person_details.LastName),
                                    (patient_person_details.MiddleName),
                                    facility.FacilityID, enrollmentBlueCardId, entryPointId,
                                    DateTime.Parse(enrollmentDate), sex,
                                    DateTime.Parse(personDateOfBirth),
                                    1, MaritalStatusId,
                                    address, phone, userId, Session["AppPosID"].ToString(),
                                    203, DateTime.Parse(enrollmentDate), DateTime.Now);

                                patient.ptn_pk = ptn_Pk;
                                patientManager.UpdatePatient(patient, patientId);
                            }
                            else
                            {
                                ptn_Pk         = greencardptnpk[0].Ptn_Pk;
                                patient.ptn_pk = greencardptnpk[0].Ptn_Pk;
                                patientManager.UpdatePatient(patient, patientId);
                            }
                        }

                        Session["PatientMasterVisitId"] = patientMasterVisitId;

                        if (patientMasterVisitId > 0)
                        {
                            foreach (var item in identifiersObjects)
                            {
                                patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patientId,
                                                                                                    patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, facilityId);

                                var identifierManager = new IdentifierManager();
                                var identifierList    = identifierManager.GetIdentifiersById(Convert.ToInt32(item.Key));
                                var hivtesting        = _hivTestingManager.GetAll().OrderByDescending(y => y.Id).FirstOrDefault(n => n.PersonId == PersonId);
                                if (identifierList.Count > 0)
                                {
                                    if (identifierList[0].Code == "CCCNumber")
                                    {
                                        if (hivtesting != null)
                                        {
                                            hivtesting.ReferredToCare = true;
                                            _hivTestingManager.UpdatePatientHivTesting(hivtesting);

                                            PatientLinkage patLinkage = new PatientLinkage();
                                            patLinkage.LinkageDate = DateTime.Parse(enrollmentDate);
                                            patLinkage.CCCNumber   = item.Value;
                                            patLinkage.PersonId    = PersonId;
                                            patLinkage.CreatedBy   = userId;
                                            patLinkage.Enrolled    = true;
                                            patLinkage.PatientId   = patientId;

                                            linkageManager.AddPatientLinkage(patLinkage);
                                        }
                                    }
                                }
                            }

                            if (greencardptnpk.Count == 0)
                            {
                                mstPatientLogic.AddOrdVisit(ptn_Pk, facilityId, DateTime.Now, 110,
                                                            userId, DateTime.Now, 203);
                            }


                            message.errorcode = 0;
                            message.msg      += "<p>Successfully enrolled patient.</p>";
                        }
                    }
                }
                else
                {
                    var                  patientLookManager = new PatientLookupManager();
                    PatientLookup        patient            = patientLookManager.GetPatientByPersonId(PersonId);
                    List <PatientLookup> pk = new List <PatientLookup>();
                    pk.Add(patient);
                    if (patient != null)
                    {
                        Session["PatientPK"] = patient.Id;

                        List <PatientEntity> listPatient = new List <PatientEntity>();
                        var entity = pk.ConvertAll(x => new PatientEntity {
                            Id         = x.Id, Active = x.Active, DateOfBirth = x.DateOfBirth,
                            ptn_pk     = x.ptn_pk, PatientType = x.PatientType, PatientIndex = x.PatientIndex, NationalId = x.NationalId,
                            FacilityId = x.FacilityId
                        });

                        var patientAuditData = AuditDataUtility.Serializer(entity);

                        PatientEntity updatePatient = new PatientEntity();
                        updatePatient.ptn_pk      = patient.ptn_pk;
                        updatePatient.DateOfBirth = patient.DateOfBirth;
                        updatePatient.NationalId  = nationalId;
                        updatePatient.FacilityId  = patient.FacilityId;


                        //listPatient.Add(entity);
                        updatePatient.AuditData = patientAuditData;
                        //var enrollmentAuditData = AuditDataUtility.Serializer(patient);

                        patientManager.UpdatePatient(updatePatient, patient.Id);

                        int patientMasterVisitId = patientMasterVisitManager.PatientMasterVisitCheckin(patient.Id, userId);
                        Session["PatientMasterVisitId"] = patientMasterVisitId;

                        List <PatientEntryPoint> entryPoints = patientEntryPointManager.GetPatientEntryPoints(patient.Id);

                        if (entryPoints.Count > 0)
                        {
                            var entryPointAuditData = AuditDataUtility.Serializer(entryPoints);

                            entryPoints[0].EntryPointId = entryPointId;
                            entryPoints[0].AuditData    = entryPointAuditData;

                            patientEntryPointManager.UpdatePatientEntryPoint(entryPoints[0]);
                        }
                        foreach (var item in identifiersObjects)
                        {
                            var identifiersByPatientId = patientIdentifierManager
                                                         .GetPatientEntityIdentifiersByPatientId(patient.Id, Convert.ToInt32(item.Key));

                            if (identifiersByPatientId.Count > 0)
                            {
                                foreach (var entityIdentifier in identifiersByPatientId)
                                {
                                    int enrollmentId = entityIdentifier.PatientEnrollmentId;

                                    PatientEntityEnrollment entityEnrollment =
                                        patientEnrollmentManager.GetPatientEntityEnrollment(enrollmentId);
                                    List <PatientEntityEnrollment> listEnrollment = new List <PatientEntityEnrollment>();
                                    listEnrollment.Add(entityEnrollment);
                                    var enrollmentAuditData = AuditDataUtility.Serializer(listEnrollment);

                                    entityEnrollment.EnrollmentDate = DateTime.Parse(enrollmentDate);
                                    entityEnrollment.AuditData      = enrollmentAuditData;

                                    patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);

                                    var entityIdentifierAuditData = AuditDataUtility.Serializer(identifiersByPatientId);
                                    entityIdentifier.IdentifierValue = item.Value;
                                    entityIdentifier.AuditData       = entityIdentifierAuditData;
                                    patientIdentifierManager.UpdatePatientIdentifier(entityIdentifier, facilityId);
                                }
                            }
                            else
                            {
                                patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patient.Id, enrollmentDate, userId);
                                patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patient.Id, entryPointId, userId);
                                patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patient.Id,
                                                                                                    patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, facilityId);
                            }
                        }
                    }
                }
            }
            catch (SoapException ex)
            {
                message.errorcode = 1;
                message.msg       = ex.Message;
            }

            return(Msg = new JavaScriptSerializer().Serialize(message));
        }
コード例 #8
0
        public string saveTracingData(int PatientId, int PersonId, string tracingdate, int tracingmethod, int tracingoutcome, string othertracingoutcome, string tracingdateofdeath,
                                      string tracingdateoftransfer, string transferfacility, string tracingnotes, string tracingstatus, int?visitid)
        {
            ILookupManager mgr     = (ILookupManager)ObjectFactory.CreateInstance("BusinessProcess.CCC.BLookupManager, BusinessProcess.CCC");
            var            tracing = new ReportingResultsManager();
            int            userId  = Convert.ToInt32(Session["AppUserId"]);
            int            patientmastervisitresult = 0;
            int            EncounterResult          = 0;
            string         savestatus       = "";
            DateTime?      deathTracingDate = new DateTime();
            int            CheckoutResult   = 0;

            //save tracing data
            if (tracingdateofdeath == "")
            {
                deathTracingDate = null;
            }
            else
            {
                deathTracingDate = Convert.ToDateTime(tracingdateofdeath);
            }

            DateTime?transferTracingDate = new DateTime();

            if (tracingdateoftransfer == "")
            {
                transferTracingDate = null;
            }
            else
            {
                transferTracingDate = Convert.ToDateTime(tracingdateoftransfer);
            }

            try
            {
                //create patient master visit id
                PatientMasterVisitManager patientMasterVisit = new PatientMasterVisitManager();
                LookupLogic lookupLogic     = new LookupLogic();
                var         currentfacility = lookupLogic.GetFacility(Session["AppPosID"].ToString());
                if (currentfacility == null)
                {
                    currentfacility = lookupLogic.GetFacility();
                }

                if (visitid.HasValue && visitid.Value > 0)
                {
                    Tracing[] patientTracingData = tracing.getTracingData(visitid.Value).ToArray();
                    if (patientTracingData.Length > 0)
                    {
                        patientTracingData[0].Mode                    = tracingmethod;
                        patientTracingData[0].Outcome                 = tracingoutcome;
                        patientTracingData[0].DateTracingDone         = Convert.ToDateTime(tracingdate);
                        patientTracingData[0].TracingDateOfDeath      = deathTracingDate;
                        patientTracingData[0].TracingTransferFacility = transferfacility;
                        patientTracingData[0].TracingTransferDate     = transferTracingDate;
                        patientTracingData[0].Remarks                 = tracingnotes;

                        tracing.UpdatePatientTracing(patientTracingData[0]);
                        Session["PatientTrace"] = "";
                    }
                }
                else
                {
                    patientmastervisitresult = patientMasterVisit.PatientMasterVisitCheckin(PatientId, userId, currentfacility.FacilityID);

                    //create encounter
                    PatientEncounterManager patientEncounterManager = new PatientEncounterManager();
                    EncounterResult = patientEncounterManager.AddpatientEncounterTracing(Convert.ToInt32(PatientId), Convert.ToInt32(patientmastervisitresult),
                                                                                         patientEncounterManager.GetPatientEncounterId("EncounterType", "Patient-Tracing"), 203, userId, Convert.ToDateTime(tracingdate), Convert.ToDateTime(tracingdate));
                    int tracingType = Convert.ToInt32(mgr.GetLookupItemId("DefaulterTracing"));
                    //save tracing data
                    Tracing patientTracing = new Tracing()
                    {
                        PersonID             = PersonId,
                        TracingType          = tracingType,
                        PatientMasterVisitId = patientmastervisitresult,
                        DateTracingDone      = Convert.ToDateTime(tracingdate),
                        Mode                    = tracingmethod,
                        Outcome                 = tracingoutcome,
                        TracingDateOfDeath      = deathTracingDate,
                        TracingTransferFacility = transferfacility,
                        TracingTransferDate     = transferTracingDate,
                        Remarks                 = tracingnotes,
                        CreateDate              = DateTime.Now,
                        CreatedBy               = Convert.ToInt32(Session["AppUserId"])
                    };

                    Result = tracing.AddPatientTracing(patientTracing);

                    //checkout patient master visit
                    PatientMasterVisitManager patientMasterVisitcheckout = new PatientMasterVisitManager();
                    CheckoutResult = patientMasterVisit.PatientMasterVisitCheckout(patientmastervisitresult, PatientId, 0, 0, 0, Convert.ToDateTime(tracingdate));

                    Session["EncounterStatusId"] = 0;
                    Session["PatientEditId"]     = 0;
                    Session["PatientPK"]         = 0;
                    Session["PatientTrace"]      = "";

                    if (Result > 0 && CheckoutResult > 0)
                    {
                        Msg = "Patient appointment Added Successfully!";
                    }
                }
            }
            catch (Exception e)
            {
                Msg = e.Message;
            }
            return(savestatus);
        }