public void NrlsPointerRequest_Delete_Valid() { var viewModel = NrlsPointerRequest.Delete("id001", "0001", "org1"); var expectedViewModel = new NrlsPointerRequest { Asid = "0001", PointerId = "id001", JwtOrgCode = "org1" }; Assert.Equal(expectedViewModel, viewModel, Comparers.ModelComparer <NrlsPointerRequest>()); }
public async SystemTasks.Task <bool> DeletePlan(RequestViewModel request) { try { //Find and delete Medical Record var update = new UpdateDefinitionBuilder <CrisisPlan>().Set(n => n.Active, false); var previous = _context.CrisisPlans.UpdateOne(item => item.Id == new ObjectId(request.Id) && item.RecordType == RecordType.MentalHealthCrisisPlan.ToString(), update); //Find pointer id from local map var pointerMap = await _pointerMapService.FindPointerMap(request.Id, RecordType.MentalHealthCrisisPlan); //Delete pointer from NRLS var deletedPointer = true; if (pointerMap != null && !string.IsNullOrEmpty(pointerMap.NrlsPointerId)) { var pointerRequest = NrlsPointerRequest.Delete(pointerMap.NrlsPointerId, request.Asid, request.OrgCode); var outcome = await _documentReferenceServices.DeletePointer(pointerRequest); deletedPointer = (outcome != null && outcome.Success); if (deletedPointer) { var delMap = _pointerMapService.DeletePointerMap(pointerMap.Id); } } return(await SystemTasks.Task.Run(() => previous.IsAcknowledged && previous.ModifiedCount > 0 && deletedPointer)); } catch (Exception ex) { // log or manage the exception throw ex; } }
public async Task<CommandResult<string>> RunCommand() { var jsonSerializer = new FhirJsonSerializer(); var jsonResponse = string.Empty; NrlsPointerRequest pointerRequest; var idParam = _parameters?.FirstOrDefault(n => n.Key.Equals("_id")); var asid = _headers.FirstOrDefault(n => n.Key.Equals("fromasid")); var orgCode = _headers.FirstOrDefault(n => n.Key.Equals("orgcode")); //Massive Try/catch try { if (_method == "get") { var patientParam = _parameters.FirstOrDefault(n => n.Key.Equals("subject")); var custodianParam = _parameters.FirstOrDefault(n => n.Key.Equals("custodian")); var typeParam = _parameters.FirstOrDefault(n => n.Key.Equals("type")); if (!string.IsNullOrEmpty(idParam.Value.Value)) { pointerRequest = NrlsPointerRequest.Read(idParam.Value.Value, asid.Value, orgCode.Value); } else { pointerRequest = NrlsPointerRequest.Search(orgCode.Value, patientParam.Value, typeParam.Value, asid.Value, custodianParam.Value); } var pointers = await _docRefService.GetPointersBundle(pointerRequest); jsonResponse = jsonSerializer.SerializeToString(pointers); } if (_method == "post") { OperationOutcome documentOutcome; if (_pointerBody != null) { pointerRequest = NrlsPointerRequest.Create(orgCode.Value, _pointerBody.OrgCode, _pointerBody.NhsNumber, _pointerBody.Url, _pointerBody.ContentType, _pointerBody.TypeCode, _pointerBody.TypeDisplay, asid.Value); var response = await _docRefService.GenerateAndCreatePointer(pointerRequest); documentOutcome = response.Resource as OperationOutcome; } else { pointerRequest = NrlsPointerRequest.Create(orgCode.Value, null, null, null, null, null, null, asid.Value); var response = await _docRefService.CreatePointer(pointerRequest, _pointer); documentOutcome = response.Resource as OperationOutcome; } jsonResponse = jsonSerializer.SerializeToString(documentOutcome); } if (_method == "put") { //not implemented } if (_method == "delete") { pointerRequest = NrlsPointerRequest.Delete(idParam.Value.Value, asid.Value, orgCode.Value); var outcome = await _docRefService.DeletePointer(pointerRequest); jsonResponse = jsonSerializer.SerializeToString(outcome); } } catch(Exception ex) { jsonResponse = ex.Message; } return CommandResult<string>.Set(true, "Success", jsonResponse.ToString()); }