public void WhenMedicationRequestTransformedToHealthVault_ThenDosageInstructionIsCopiedToInstructions() { MedicationRequest medicationRequest = GetSampleRequest(); var dosage = new Dosage(); medicationRequest.DosageInstruction = new System.Collections.Generic.List <Dosage> { dosage }; var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsNull(hvMedication.Prescription?.Instructions); var dosageInstructions = new CodeableConcept { Text = "3 tablets/day, have it after dinner." }; dosage.AdditionalInstruction = new System.Collections.Generic.List <CodeableConcept> { dosageInstructions }; hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsNotNull(hvMedication.Prescription?.Instructions); }
public ActionResult EditMedicationRequest(string id, string type, string patientID) { //POŁĄCZENIE Z KLIENTEM var client = new FhirClient("http://localhost:8080/baseR4"); client.PreferredFormat = ResourceFormat.Json; ViewBag.ID = patientID; if (type == "MedicationRequest") { //WYSZUKANIE ZASOBU MedicationRequest request = client.Read <MedicationRequest>("MedicationRequest/" + id); EditMedicationRequest mrequest = new EditMedicationRequest(); //PRZEKAZANIE DANYCH mrequest.Reason = (request.Medication as CodeableConcept).Text; if (request.DosageInstruction.Count() > 0) { mrequest.Instruction = request.DosageInstruction[0].Text; } else { mrequest.Instruction = ""; } mrequest.ID = request.Id; return(View(mrequest)); } ViewBag.Message = "Some Error until Redirect"; return(View()); }
public ActionResult EditMedicationRequest([Bind] EditMedicationRequest request, string patientID) { bool status = false; string Message = ""; //SPRAWDZENIE DANYCH if (ModelState.IsValid) { //PODŁĄCZENIE KLIENTA var client = new FhirClient("http://localhost:8080/baseR4"); client.PreferredFormat = ResourceFormat.Json; //PRZEKAZANIE DANYCH MedicationRequest original = client.Read <MedicationRequest>("MedicationRequest/" + request.ID); (original.Medication as CodeableConcept).Text = request.Reason; Dosage dosage = new Dosage(); dosage.Text = request.Instruction; original.DosageInstruction.Add(dosage); //UPDATE client.Update(original); Message = "Your item successfully UPDATE"; status = true; } else { Message = "You haven't got right model"; } ViewBag.ID = patientID; ViewBag.Status = status; ViewBag.Message = Message; return(View(request)); }
private static void DoResponsiblePractitioner(MedicationRequest m, ParticipantMaker a) { Extension e = FhirHelper.MakeExtension(null, "https://fhir.nhs.uk/R4/StructureDefinition/Extension-DM-ResponsiblePractitioner", FhirHelper.MakeInternalReference(a.Role)); m.Extension.Add(e); }
internal static MedicationStatement ToFhirInternal(HVMedication hvMedication, MedicationStatement medicationStatement) { var embeddedMedication = new FhirMedication(); embeddedMedication.Id = "med" + Guid.NewGuid(); medicationStatement.Contained.Add(ToFhirInternal(hvMedication, embeddedMedication)); medicationStatement.Medication = embeddedMedication.GetContainerReference(); medicationStatement.SetStatusAsActive(); medicationStatement.SetTakenAsNotApplicable(); medicationStatement.Dosage = AddDosage(hvMedication.Dose, hvMedication.Frequency, hvMedication.Route); if (hvMedication.Prescription != null) { var embeddedMedicationRequest = new MedicationRequest(); embeddedMedicationRequest.Id = "medReq" + Guid.NewGuid(); Practitioner prescribedBy = hvMedication.Prescription.PrescribedBy.ToFhir(); prescribedBy.Id = "prac" + Guid.NewGuid(); medicationStatement.Contained.Add(prescribedBy); MedicationRequest request = ToFhirInternal(hvMedication.Prescription, embeddedMedicationRequest); request.Medication = embeddedMedication.GetContainerReference(); request.Requester = new MedicationRequest.RequesterComponent { Agent = prescribedBy.GetContainerReference() }; medicationStatement.Contained.Add(request); medicationStatement.BasedOn.Add(embeddedMedicationRequest.GetContainerReference()); } return(medicationStatement); }
public void WhenMedicationRequestTransformedToHealthVault_ThenPractitionerIsCopiedToPrescription() { MedicationRequest medicationRequest = GetSampleRequest(); var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsNotNull(hvMedication.Prescription.PrescribedBy); }
private Boolean isRequestAnAcutePlan(MedicationRequest request) { CodeableConcept prescriptionType = (CodeableConcept)request.GetExtension(FhirConst.StructureDefinitionSystems.kMedicationPrescriptionType).Value; if (prescriptionType.Coding.First().Display.Contains("Acute")) { return(request.Intent.Equals(MedicationRequest.MedicationRequestIntent.Plan)); } return(false); }
public void WhenMedicationRequestTransformedToHealthVault_ThenAuthoredOnIsCopiedToDatePrescribed() { var prescribedOn = new LocalDate(2017, 08, 10); MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.AuthoredOnElement = new FhirDateTime(prescribedOn.ToDateTimeUnspecified()); var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsTrue(hvMedication.Prescription?.DatePrescribed.ApproximateDate.CompareTo(prescribedOn) == 0); }
public static Bundle MapFromCDRToFHirModelBundle(string uri) { Bundle bundle = new Bundle(); MedicationRequest medicationStatement = MapFromCDRToFHirModel(); //bundle.AddResourceEntry(medicationStatement, $"{uri}/{medicationStatement.Id}"); bundle.AddResourceEntry(medicationStatement, string.Format("{0}/{1}", uri, medicationStatement.Id)); return(bundle); }
public void WhenMedicationRequestTransformedToHealthVault_ThenPractitionerIsRequired() { var medicationRequest = new MedicationRequest { Medication = new CodeableConcept { Text = "Amoxicillin 250mg/5ml Suspension" }, }; Assert.ThrowsException <NotSupportedException>(() => medicationRequest.ToHealthVault()); }
private static void DoPrescriptionType(MedicationRequest m, System.Collections.Generic.List <string> rx) { Coding ptc = FhirHelper.MakeCoding("https://fhir.nhs.uk/R4/CodeSystem/prescription-type", rx[EMUData.PRESCRIPTIONTYPE], null); if (rx[EMUData.PRESCRIPTIONTYPE].Equals("0001")) { ptc.Display = "General Practitioner Prescribing"; } Extension e = FhirHelper.MakeExtension(null, "https://fhir.nhs.uk/R4/StructureDefinition/Extension-prescriptionType", ptc); m.Extension.Add(e); }
public void WhenMedicationRequestTransformedToHealthVault_ThenSubstitutionIsCopiedToSubstitution() { MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.Substitution = new MedicationRequest.SubstitutionComponent { Allowed = true }; var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.AreEqual(HealthVaultMedicationSubstitutionCodes.SubstitutionPermittedCode , hvMedication.Prescription?.Substitution.First().Value); }
public void WhenMedicationRequestTransformedToHealthVault_ThenDispenseRequestQuantityIsCopiedToAmountPrescribed() { const int amountPrescribed = 15; MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent { Quantity = new Quantity(amountPrescribed, "tablets").CopyTo(new SimpleQuantity()) as SimpleQuantity }; var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.AreEqual(amountPrescribed, hvMedication.Prescription?.AmountPrescribed?.Structured.First()?.Value); }
private static CodableValue GetSubstitutionCode(MedicationRequest medicationRequest, Prescription prescription) { if (medicationRequest.Substitution.Allowed.HasValue) { switch (medicationRequest.Substitution.Allowed.Value) { case true: return(HealthVaultMedicationSubstitutionCodes.SubstitutionPermitted); case false: return(HealthVaultMedicationSubstitutionCodes.DispenseAsWritten); } } return(null); }
public async Task <HttpResponseMessage> SaveMedication(MedicationRequest medicationRequest) { httpResponseMessage = new HttpResponseMessage(); if (medicationRequest != null && ModelState.IsValid) { var saveMedication = await _IMedicationService.SaveMedication(medicationRequest); httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, saveMedication); } else { httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, new { Message = CustomErrorMessages.INVALID_INPUTS, Success = false }); } return(httpResponseMessage); }
public System.Collections.Generic.List <Hl7.Fhir.Model.MedicationRequest> FHIR_SearchMedications(string PatientId) { System.Collections.Generic.List <Hl7.Fhir.Model.MedicationRequest> Ms = new System.Collections.Generic.List <Hl7.Fhir.Model.MedicationRequest>(); var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint_PatientInfo); client.PreferredFormat = ResourceFormat.Json; Bundle bu = client.Search <Hl7.Fhir.Model.MedicationRequest> (new string[] { "patient=" + PatientId }); foreach (Bundle.EntryComponent ent in bu.Entry) { MedicationRequest m = (MedicationRequest)ent.Resource; Ms.Add(m); } return(Ms); }
public void WhenMedicationRequestTransformedToHealthVault_ThenValidityPeriodEndIsCopiedToPrescriptionExpiration() { var expiration = new LocalDate(2017, 12, 12); MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent { ValidityPeriod = new Hl7.Fhir.Model.Period { EndElement = new FhirDateTime(expiration.ToDateTimeUnspecified()) } }; var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsTrue(hvMedication.Prescription?.PrescriptionExpiration.CompareTo(expiration) == 0); }
internal static MedicationRequest ToFhirInternal(Prescription prescription, MedicationRequest medicationRequest) { medicationRequest.SetIntentAsInstanceOrder(); medicationRequest.AuthoredOnElement = prescription.DatePrescribed?.ToFhir(); if (prescription.AmountPrescribed != null || prescription.Refills.HasValue || prescription.DaysSupply.HasValue || prescription.PrescriptionExpiration != null) { medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent { Quantity = HealthVaultCodesToFhir.GetSimpleQuantity(prescription.AmountPrescribed), NumberOfRepeatsAllowed = prescription.Refills, ExpectedSupplyDuration = new Duration() { Value = prescription.DaysSupply, Code = nameof(UnitsNet.Units.DurationUnit.Day) }, ValidityPeriod = new Period { EndElement = prescription.PrescriptionExpiration?.ToFhir() } }; } if (prescription.Substitution != null) { bool?isAllowed = IsAllowed(prescription.Substitution); if (isAllowed.HasValue) { medicationRequest.Substitution = new MedicationRequest.SubstitutionComponent { Allowed = isAllowed }; } } if (prescription.Instructions != null) { var dosage = new Dosage(); dosage.AdditionalInstruction.Add(prescription.Instructions.ToFhir()); medicationRequest.DosageInstruction.Add(dosage); } return(medicationRequest); }
private MedicationModel GetMappedMedication(MedicationRequest medication) { var resultMedicationRequest = new MedicationModel { Id = medication.Id }; resultMedicationRequest.VersionId = medication.VersionId ?? ""; var meds = medication.Medication as CodeableConcept; resultMedicationRequest.Text = meds.Text; resultMedicationRequest.DosageInstructions = medication.DosageInstruction; resultMedicationRequest.SubjectId = medication.Subject.Reference.Split('/')[1]; resultMedicationRequest.Status = medication.Status; resultMedicationRequest.AuthoredOn = medication.AuthoredOnElement.ToDateTimeOffset(); resultMedicationRequest.Practitioner = medication.Requester.Display; resultMedicationRequest.Intent = medication.Intent; return(resultMedicationRequest); }
public async Task <string> AddMedicinesToPatientAsync(string emrPatientId, List <MedicationEntity> medicineList) { // emrPatientId = "1795445"; if (medicineList == null) { return(null); } if (string.IsNullOrEmpty(emrPatientId)) { throw new Exception("EMR Patient Id is invalid or not found."); } try { var patientMedicine = new MedicationRequest { Status = MedicationRequestStatus.Active, Intent = MedicationRequestIntent.Order, Subject = new ResourceReference { Reference = $"Patient/{emrPatientId}", }, Category = new CodeableConcept { Coding = GetMedicineNames(medicineList) }, DosageInstruction = GetDosageInstructions(medicineList) }; var fhirClient = new FhirClient("http://hapi.fhir.org/baseDstu3"); var result = await fhirClient.CreateAsync <MedicationRequest>(patientMedicine); return(result.Id); } catch (System.Exception ex) { throw; } }
public void WhenMedicationRequestTransformedToHealthVault_ThenNumberOfRepeatsAllowedIsCopiedToRefills() { MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent(); var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.IsNull(hvMedication.Prescription?.Refills); const int refillsAllowed = 3; medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent { NumberOfRepeatsAllowed = refillsAllowed }; hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.AreEqual(refillsAllowed, hvMedication.Prescription.Refills); }
private static Practitioner ExtractEmbeddedPractitioner(MedicationRequest medicationRequest) { var agentReference = medicationRequest.Requester?.Agent; if (agentReference == null) { return(null); } return(medicationRequest.GetReferencedResource(agentReference, (reference) => new Practitioner { Name = new System.Collections.Generic.List <HumanName> { new HumanName { Text = agentReference.Display } } })); }
private static MedicationRequest MakeMedicationRequest(Patient p, System.Collections.Generic.List <string> rx, System.Collections.Generic.List <string> item, ResourceReference nom, ParticipantMaker a) { MedicationRequest m = new MedicationRequest { Id = FhirHelper.MakeId() }; m.Status = MedicationRequest.medicationrequestStatus.Active; m.Intent = MedicationRequest.medicationRequestIntent.Order; m.Subject = FhirHelper.MakeInternalReference(p); m.Identifier.Add(FhirHelper.MakeIdentifier("https://fhir.nhs.uk/Id/prescription-line-id", item[EMUData.LINEITEMID])); ResourceReference rq = FhirHelper.MakeInternalReference(a.Role); rq.Display = a.Practitioner.Name[0].Text; m.Requester = rq; m.AuthoredOn = rx[EMUData.AUTHORPARTICIPATIONTIME]; m.GroupIdentifier = MakeGroupIdentifier(rx); DoPrescriptionType(m, rx); DoResponsiblePractitioner(m, a); m.Medication = DoMedication(item); m.CourseOfTherapyType = MakeCourseOfTherapyType(rx); if (item[EMUData.DOSAGEINTRUCTIONS].Trim().Length > 0) { Dosage di = new Dosage { Text = item[EMUData.DOSAGEINTRUCTIONS] }; m.DosageInstruction.Add(di); if (item[EMUData.ADDITIONALINSTRUCTIONS].Trim().Length > 0) { di.PatientInstruction = item[EMUData.ADDITIONALINSTRUCTIONS]; } } m.DispenseRequest = MakeDispenseRequest(nom, rx, item); return(m); }
public void WhenMedicationRequestTransformedToHealthVault_ThenExpectedSupplyDurationIsCopiedToDaysSupply() { var daysSupply = 12; MedicationRequest medicationRequest = GetSampleRequest(); medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent { ExpectedSupplyDuration = new Quantity(daysSupply, "day") .CopyTo(new Hl7.Fhir.Model.Duration()) as Hl7.Fhir.Model.Duration }; var hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.AreEqual(daysSupply, hvMedication.Prescription?.DaysSupply); medicationRequest.DispenseRequest.ExpectedSupplyDuration = new Quantity(1, "month") .CopyTo(new Hl7.Fhir.Model.Duration()) as Hl7.Fhir.Model.Duration; hvMedication = medicationRequest.ToHealthVault() as HVMedication; Assert.AreEqual(30, hvMedication.Prescription?.DaysSupply); }
public async Task <BaseResponse> SaveMedication(MedicationRequest medicationRequest) { try { _BaseResponse = new BaseResponse(); using (ClinicalHealthCareEntities db = new ClinicalHealthCareEntities()) { Medication Medication = new Medication(); Medication.Name = medicationRequest.Name; Medication.Quantity = medicationRequest.Quantity; Medication.Dosage = medicationRequest.Dosage; Medication.Unit = medicationRequest.Unit; Medication.Form = medicationRequest.Form; Medication.Method = medicationRequest.Method; Medication.Indication = medicationRequest.Indication; Medication.Frequency = medicationRequest.Frequency; Medication.Duration = medicationRequest.Duration; Medication.StartDate = medicationRequest.StartDate; Medication.EndDate = medicationRequest.EndDate; Medication.Prescriber = medicationRequest.Prescriber; Medication.RXNumber = medicationRequest.RXNumber; Medication.Notes = medicationRequest.Notes; Medication.Active = Convert.ToBoolean(medicationRequest.Active); Medication.CreatedDate = DateTime.Now; db.Medications.Add(Medication); await db.SaveChangesAsync(); } } catch (Exception ex) { _BaseResponse.Success = false; _BaseResponse.Message = ex.Message; } return(_BaseResponse); }
public static MedicationRequest MapFromCDRToFHirModel() { Random gen = new Random(); int range = 5 * 365; //5 years DateTime randomDate = DateTime.Today.AddDays(-gen.Next(range)); MedicationRequest medicationRequest = new MedicationRequest { Medication = new CodeableConcept { Coding = new List <Coding> { new Coding { Code = "197884", Display = "Lisinopril 40 MG Oral Tablet", System = "http://www.nlm.nih.gov/research/umls/rxnorm", }, }, Text = "Lisinopril 40 MG Oral Tablet" }, AuthoredOn = new FhirDateTime("2017-08-01").ToString(), DosageInstruction = new List <Dosage>() { new Dosage { Text = "Take Lisinopril 40mg tablet once a day for high blood pressure.", Timing = new Timing() { Code = new CodeableConcept() { }, Repeat = new Timing.RepeatComponent() { Count = 0, Period = 1, PeriodUnit = Timing.UnitsOfTime.D, Frequency = 1, Bounds = new Period { Start = "2017-08-01", End = "2018-06-30", } } }, AsNeeded = new FhirBoolean(false), Route = new CodeableConcept { Coding = new List <Coding> { new Coding { System = "http://snomed.info/sct", Display = "Oral route", Code = "26643006" } } }, Rate = new Quantity { Value = 40, Unit = "mG" } }, }, Requester = new MedicationRequest.RequesterComponent { Agent = new ResourceReference { Reference = "Practitioner/cc-prac-carlson-john", Display = "Dr. John Carlson, MD" } }, Subject = new ResourceReference { Reference = "Patient/6", Display = "Betsy" }, ReasonReference = new List <ResourceReference> { new ResourceReference { Reference = "Condition/cc-cond-betsy-hypertension" } }, }; return(medicationRequest); }
public ViewResult ShowInfo(string id, DateTime?after, DateTime?before, int?page) { //POKAZYWANIE WSZYSTKICH INFORMACJI O PACJENCIE //ŁĄCZENIE Z SERWEREM var client = new FhirClient("http://localhost:8080/baseR4"); //second parameter - check standard version client.PreferredFormat = ResourceFormat.Json; Patient myPatient = client.Read <Patient>("Patient/" + id); UriBuilder UriBuilderx = new UriBuilder("http://localhost:8080/baseR4"); UriBuilderx.Path = "Patient/" + myPatient.Id; Resource ReturnedResource = client.InstanceOperation(UriBuilderx.Uri, "everything"); //DANE OSOBOWE PACJENTA ViewBag.Surname = myPatient.Name[0].Family; ViewBag.ID = myPatient.Id; ViewBag.Name = myPatient.Name[0].Given.FirstOrDefault(); ViewBag.birthDate = new Date(myPatient.BirthDate.ToString()); //WYSZUKIWANIE "EVERYTHING" var myElemList = new List <ShowInfo>(); if (ReturnedResource is Bundle) { Bundle ReturnedBundle = ReturnedResource as Bundle; while (ReturnedBundle != null) { foreach (var Entry in ReturnedBundle.Entry) { ShowInfo myElem = new ShowInfo(); //DANE DO OSI CZASU if (Entry.Resource.TypeName == "Observation") { //LISTA OBSERVATION Observation observation = (Observation)Entry.Resource; myElem.elemID = observation.Id; myElem.originalModel = "Observation"; var amount = observation.Value as Quantity; if (amount != null) { myElem.amount = amount.Value + " " + amount.Unit; } myElem.date = Convert.ToDateTime(observation.Effective.ToString()); myElem.reason = observation.Code.Text; myElemList.Add(myElem); } else if (Entry.Resource.TypeName == "MedicationRequest") { //LISTA MEDICATIONSTATEMENT MedicationRequest mrequest = (MedicationRequest)Entry.Resource; myElem.elemID = mrequest.Id; myElem.originalModel = "MedicationRequest"; myElem.date = Convert.ToDateTime(mrequest.AuthoredOn.ToString()); myElem.reason += (mrequest.Medication as CodeableConcept).Text; myElemList.Add(myElem); } } ReturnedBundle = client.Continue(ReturnedBundle, PageDirection.Next); } } else { throw new Exception("Operation call must return a bundle resource"); } //OKREŚLENIE SZUKANEJ DATY if (before != null) { DateTime date = before.GetValueOrDefault(); myElemList = myElemList.FindAll(s => s.date.Date.CompareTo(date.Date) < 0); ViewBag.Before = date; } if (after != null) { DateTime date = after.GetValueOrDefault(); myElemList = myElemList.FindAll(s => s.date.Date.CompareTo(date.Date) > 0); ViewBag.After = date; } myElemList.Reverse(); //żeby daty były odpowiednio od najwyższej int pageSize = 10; int pageNumber = (page ?? 1); return(View(myElemList.ToPagedList(pageNumber, pageSize))); }
public ActionResult HistoryMedicationRequest(string id, string type, string patientID) { bool status = false; string Message = ""; List <HistoryMedicationRequest> fullVersion = new List <HistoryMedicationRequest>(); //SPRAWDZENIE MODELU if (ModelState.IsValid) { //PODŁĄCZENIE KLIENTA var client = new FhirClient("http://localhost:8080/baseR4"); client.PreferredFormat = ResourceFormat.Json; //WYSZUKANIE HISTORII Bundle history = client.History("MedicationRequest/" + id); while (history != null) { foreach (var e in history.Entry) { if (e.Resource.TypeName == "MedicationRequest") { //POBRANIE POTRZBNYCH DANYCH HistoryMedicationRequest request = new HistoryMedicationRequest(); request.LastUpdate = e.Resource.Meta.LastUpdated; request.VersionId = int.Parse(e.Resource.VersionId); MedicationRequest medication = (MedicationRequest)e.Resource; request.Reason += (medication.Medication as CodeableConcept).Text; foreach (var elem in medication.DosageInstruction) { request.Instruction += elem.Text + " "; } fullVersion.Add(request); } } history = client.Continue(history, PageDirection.Next); } status = true; } else { Message = "You haven't got right model"; } for (int i = 0; i < fullVersion.Count - 1; i++) { if (fullVersion[i].Reason != fullVersion[i + 1].Reason) { fullVersion[i].color[0] = "green"; } if (fullVersion[i].Instruction != fullVersion[i + 1].Instruction) { fullVersion[i].color[1] = "green"; } } ViewBag.ID = patientID; ViewBag.Status = status; ViewBag.Message = Message; return(View(fullVersion)); }
public static ThingBase ToHealthVault(this MedicationRequest medicationRequest) { var fhirMedication = MedicationRequestHelper.ExtractEmbeddedMedication(medicationRequest); if (fhirMedication == null) { return(null); } var hvMedication = fhirMedication.ToHealthVault() as HVMedication; var practitioner = ExtractEmbeddedPractitioner(medicationRequest); if (practitioner == null) { throw new NotSupportedException($"{nameof(MedicationRequest)} needs to have an embedded Requester Agent"); } var prescription = new Prescription(practitioner.ToHealthVault()); if (medicationRequest.AuthoredOnElement != null) { var dt = medicationRequest.AuthoredOnElement.ToDateTimeOffset(); prescription.DatePrescribed = new ApproximateDateTime( new ApproximateDate(dt.Year, dt.Month, dt.Day), new ApproximateTime(dt.Hour, dt.Minute, dt.Second, dt.Millisecond)); } MedicationRequest.DispenseRequestComponent dispenseRequest = medicationRequest.DispenseRequest; if (dispenseRequest != null) { var numerator = dispenseRequest.Quantity; if (numerator != null) { var structuredMeasurement = new StructuredMeasurement { Value = (double)numerator.Value, Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(numerator.System, numerator.Code, numerator.Unit) }; prescription.AmountPrescribed = new GeneralMeasurement(); prescription.AmountPrescribed.Structured.Add(structuredMeasurement); } prescription.Refills = dispenseRequest.NumberOfRepeatsAllowed; prescription.DaysSupply = GetDaysFromDuration(dispenseRequest.ExpectedSupplyDuration); FhirDateTime end = dispenseRequest.ValidityPeriod?.EndElement; if (end != null) { var endDate = end.ToDateTimeOffset(); prescription.PrescriptionExpiration = new HealthServiceDate(endDate.Year , endDate.Month, endDate.Day); } } if (medicationRequest.DosageInstruction.Any()) { var dosageInstruction = medicationRequest.DosageInstruction .FirstOrDefault(dosage => dosage.AdditionalInstruction.Any()); if (dosageInstruction != null) { var instruction = dosageInstruction.AdditionalInstruction.First(); prescription.Instructions = instruction.ToCodableValue(); } } if (medicationRequest.Substitution != null) { prescription.Substitution = GetSubstitutionCode(medicationRequest, prescription); } hvMedication.Prescription = prescription; return(hvMedication); }
private static void SetIntentAsInstanceOrder(this MedicationRequest medicationRequest) { medicationRequest.Intent = MedicationRequest.MedicationRequestIntent.InstanceOrder; }