public MedicationMapData InsertMedicationMap(PostMedicationMapRequest request) { try { MedicationMapData result = null; IRestClient client = new JsonServiceClient(); //[Route("/{Context}/{Version}/{ContractNumber}/MedicationMap/Insert", "POST")] var url = Common.Helper.BuildURL(string.Format("{0}/{1}/{2}/{3}/MedicationMap/Insert", DDMedicationUrl, "NG", request.Version, request.ContractNumber), request.UserId); if (request.MedicationMap != null) { MedicationMapData data = new MedicationMapData(); data = Mapper.Map <MedicationMapData>(request.MedicationMap); PostMedicationMapDataResponse dataDomainResponse = client.Post <PostMedicationMapDataResponse>(url, new PostMedicationMapDataRequest { Context = "NG", ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version, MedicationMapData = data } as object); if (dataDomainResponse != null) { result = dataDomainResponse.MedMapData; } } return(result); } catch (Exception ex) { throw ex; } }
public PatientMedSupp SavePatientMedSupp(PostPatientMedSuppRequest request) { PatientMedSupp patientMedSupp = null; try { if (request.PatientMedSupp != null) { string name = string.IsNullOrEmpty(request.PatientMedSupp.Name) ? string.Empty : request.PatientMedSupp.Name.ToUpper(); string form = string.IsNullOrEmpty(request.PatientMedSupp.Form) ? string.Empty : request.PatientMedSupp.Form.ToUpper(); string route = string.IsNullOrEmpty(request.PatientMedSupp.Route) ? string.Empty : request.PatientMedSupp.Route.ToUpper(); string strength = string.IsNullOrEmpty(request.PatientMedSupp.Strength) ? string.Empty : request.PatientMedSupp.Strength; #region Search MedicationMap // Search if any record exists with the given combination of name, strength, route and form. GetMedicationMapsRequest mmRequest = new GetMedicationMapsRequest { Name = name, Route = route, Form = form, Strength = strength, ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version }; List <MedicationMapData> list = EndpointUtil.SearchMedicationMap(mmRequest); #endregion if (list == null) { MedicationMapData medData = null; if (string.IsNullOrEmpty(request.PatientMedSupp.FamilyId)) { #region Insert MedicationMap PostMedicationMapRequest insertReq = new PostMedicationMapRequest { MedicationMap = new DTO.MedicationMap { FullName = name, SubstanceName = string.Empty, Strength = strength, Route = route, Form = form, Custom = true, Verified = false }, ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version }; medData = EndpointUtil.InsertMedicationMap(insertReq); #endregion } else { #region Update MedicationMap // This saves the initialized medicine map PutMedicationMapRequest req = new PutMedicationMapRequest { MedicationMap = new DTO.MedicationMap { Id = request.PatientMedSupp.FamilyId, FullName = name, SubstanceName = string.Empty, Strength = strength, Route = route, Form = form, Custom = true, Verified = false }, ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version }; medData = EndpointUtil.UpdateMedicationMap(req); #endregion } RegisterMedication(request, medData); } #region Calculate NDC codes. bool calculateNDC = false; if (request.Insert) { calculateNDC = true; request.PatientMedSupp.SystemName = Constants.SystemName; } else { // On update, check for ReCalculateNDC flag. if (request.RecalculateNDC) { calculateNDC = true; } } if (calculateNDC) { request.PatientMedSupp.NDCs = EndpointUtil.GetMedicationNDCs(request); } #endregion string sigCode = CalculateSigCode(request); if (!string.IsNullOrEmpty(sigCode)) { request.PatientMedSupp.SigCode = sigCode; } PatientMedSuppData data = EndpointUtil.SavePatientMedSupp(request); if (data != null) { patientMedSupp = Mapper.Map <PatientMedSupp>(data); } } return(patientMedSupp); } catch (Exception ex) { throw ex; } }