public async Task <bool> Handle(RevokePrescriptionCommand command, CancellationToken token) { SAMLAssertion assertion; try { assertion = SAMLAssertion.Deserialize(command.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } await _recipeService.RevokePrescription(command.Rid, command.Reason, assertion); return(true); }
public async Task <bool> Handle(DeleteMessageCommand request, CancellationToken cancellationToken) { SAMLAssertion assertion; try { assertion = SAMLAssertion.Deserialize(request.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } await _ehealthBoxService.DeleteMessage(new EHealthBoxDeleteMessageRequest { MessageIdLst = request.MessageIds.ToList(), Source = request.Source }, assertion); return(true); }
public async Task <SearchPharmaceuticalPrescriptionResult> Handle(GetOpenedPharmaceuticalPrescriptionsQuery query, CancellationToken token) { SAMLAssertion assertion; var medicalfile = await _medicalFileQueryRepository.Get(query.MedicalfileId, token); if (medicalfile == null) { throw new UnknownPrescriptionException(query.MedicalfileId, string.Format(Global.UnknownMedicalFile, query.MedicalfileId)); } try { assertion = SAMLAssertion.Deserialize(query.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } var result = await _prescriptionService.GetOpenedPrescriptions(new GetPrescriptionsParameter { PatientNiss = medicalfile.PatientNiss, Page = new Page { PageNumber = 0 }, Assertion = assertion }, token); return(new SearchPharmaceuticalPrescriptionResult { HasMoreResults = result.HasMoreResults, Prescriptions = result.Prescriptions.Select(_ => new SearchPharmaceuticalPrescriptionResult.PharmaceuticalPrescriptionResult { RID = _, Status = "opened" }).ToList() }); }
public async Task <IEnumerable <MessageResult> > Handle(GetMessagesQuery request, CancellationToken cancellationToken) { SAMLAssertion assertion; try { assertion = SAMLAssertion.Deserialize(request.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } var messagesResult = await _ehealthBoxService.GetMessagesList(new EHealthBoxGetMessagesListRequest { StartIndex = request.StartIndex, EndIndex = request.EndIndex, Source = request.Source }, assertion); return(messagesResult.Body.GetMessagesListResponse.MessageLst.Select(_ => _.ToResult())); }
public async Task <GetPharmaceuticalPrescriptionResult> Handle(GetPharmaceuticalPrescriptionQuery query, CancellationToken token) { SAMLAssertion assertion = null; try { assertion = SAMLAssertion.Deserialize(query.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } var prescription = await _prescriptionService.GetPrescription(new GetPrescriptionParameter { PrescriptionId = query.PrescriptionId, Assertion = assertion }, token); if (prescription == null) { throw new UnknownPrescriptionException(query.PrescriptionId, string.Format(Global.UnknownPrescription, query.PrescriptionId)); } var patient = await _patientQueryRepository.GetByNiss(prescription.PatientNiss, token); var cnkCodes = prescription.Medications.Select(m => m.PackageCode); var lst = new List <Task <AmpResult> >(); foreach (var cnkCode in cnkCodes) { lst.Add(_ampService.SearchByCnkCode(DeliveryEnvironments.Public.Code, cnkCode, token)); } var ampLst = await Task.WhenAll(lst); return(prescription.ToResult(patient, ampLst.ToList())); }
public async Task <string> Handle(AddPharmaceuticalPrescriptionCommand command, CancellationToken token) { SAMLAssertion assertion; var medicalfile = await _medicalfileQueryRepository.Get(command.MedicalfileId, token); if (medicalfile == null) { throw new UnknownPatientException(command.MedicalfileId, string.Format(Global.UnknownMedicalFile, command.MedicalfileId)); } try { assertion = SAMLAssertion.Deserialize(command.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } var createDateTime = DateTime.UtcNow; if (command.CreateDateTime != null) { createDateTime = command.CreateDateTime.Value; } var niss = assertion.AttributeStatement.Attribute.First(_ => _.AttributeNamespace == EHealth.Constants.AttributeStatementNamespaces.Identification).AttributeValue; var profession = assertion.AttributeStatement.Attribute.First(_ => _.AttributeNamespace == EHealth.Constants.AttributeStatementNamespaces.Certified).AttributeName; var cbe = _keyStoreManager.GetOrgAuthCertificate().Certificate.ExtractCBE(); var msgType = new KmehrMessageBuilder() .AddSender((_) => { _.AddHealthCareParty((_) => { _.AddOrganization(cbe, "application", _options.ProductName); }); _.AddHealthCareParty((_) => { _.AddPerson(niss, MAPPING_CLAIM_TO_HCPARTY[profession], string.Empty, string.Empty); }); }) .AddRecipient((_) => { _.AddHealthCareParty((s) => { s.AddOrganization("RECIPE", "orgpublichealth", "Recip-e"); }); }) .AddFolder("1", (_) => { _.New(medicalfile.PatientNiss, medicalfile.PatientLastname, new string[] { medicalfile.PatientFirstname }); }, (_) => { _.AddTransaction((tr) => { tr.NewPharmaceuticalPrescriptionTransaction("1", createDateTime, true, true, command.ExpirationDateTime) .AddAuthor(niss, MAPPING_CLAIM_TO_HCPARTY[profession], string.Empty, string.Empty) .AddTransactionHeading((h) => { h.NewPrescriptionHeading("1"); foreach (var pharmaPrescription in command.Medications) { h.AddMedicationTransactionItem((ti) => { ti.SetMedicinalProduct(pharmaPrescription.PackageCode, string.Empty); if (pharmaPrescription.Posology.Type.Code == PosologyTypes.FreeText.Code) { var freeText = pharmaPrescription.Posology as AddPosologyFreeTextCommand; ti.SetPosologyFreeText(freeText.Content, DEFAULT_LANGUAGE); } else { // TODO : MANAGE STRUCTURED POSOLOGY. } if (pharmaPrescription.BeginMoment != null) { ti.SetBeginMoment(pharmaPrescription.BeginMoment.Value); } if (!string.IsNullOrWhiteSpace(pharmaPrescription.InstructionForPatient)) { ti.SetInstructionForPatient(pharmaPrescription.InstructionForPatient, DEFAULT_LANGUAGE); } if (!string.IsNullOrWhiteSpace(pharmaPrescription.InstructionForReimbursement)) { ti.SetInstructionForReimbursement(pharmaPrescription.InstructionForReimbursement, DEFAULT_LANGUAGE); } }); } }); }); }) .Build(createDateTime); var result = await _recipeService.CreatePrescription(Enum.GetName(typeof(PrescriptionTypes), command.PrescriptionType), medicalfile.PatientNiss, command.ExpirationDateTime.Value, msgType, assertion); return(result.RID); }