public static AddPharmaceuticalPrescriptionCommand BuildAddPharmaceuticalPrescription(this JObject jObj, string medicalfileId)
        {
            var values = jObj.ToObject <Dictionary <string, object> >();
            var result = new AddPharmaceuticalPrescriptionCommand {
                MedicalfileId = medicalfileId
            };

            if (values.TryGet(MedikitApiConstants.SearchNames.AssertionToken, out string assertionToken))
            {
                result.AssertionToken = assertionToken;
            }

            if (values.TryGet(MedikitApiConstants.PrescriptionNames.MedicalfileId, out string medicalfileid))
            {
                result.MedicalfileId = medicalfileid;
            }

            if (values.TryGet(MedikitApiConstants.PrescriptionNames.CreateDateTime, out DateTime createDateTime))
            {
                result.CreateDateTime = createDateTime;
            }

            if (values.TryGet(MedikitApiConstants.PrescriptionNames.ExpirationDateTime, out DateTime expirationDateTime))
            {
                result.ExpirationDateTime = expirationDateTime;
            }

            if (values.TryGet(MedikitApiConstants.PrescriptionNames.PrescriptionType, out PrescriptionTypes prescriptionType))
            {
                result.PrescriptionType = prescriptionType;
            }

            var medications = jObj.SelectToken(MedikitApiConstants.PrescriptionNames.Medications) as JArray;

            if (medications != null)
            {
                foreach (JObject medication in medications)
                {
                    var medicationDic = medication.ToObject <Dictionary <string, object> >();
                    var newMedication = new AddMedicationCommand();
                    if (medicationDic.TryGet(MedikitApiConstants.MedicationNames.PackageCode, out string packageCode))
                    {
                        newMedication.PackageCode = packageCode;
                    }

                    if (medicationDic.TryGet(MedikitApiConstants.MedicationNames.InstructionForPatient, out string instructionForPatient))
                    {
                        newMedication.InstructionForPatient = instructionForPatient;
                    }

                    if (medicationDic.TryGet(MedikitApiConstants.MedicationNames.InstructionForReimbursement, out string instructionForReimbursement))
                    {
                        newMedication.InstructionForReimbursement = instructionForReimbursement;
                    }

                    if (medicationDic.TryGet(MedikitApiConstants.MedicationNames.BeginMoment, out DateTime beginMoment))
                    {
                        newMedication.BeginMoment = beginMoment;
                    }

                    var posology = medication.SelectToken(MedikitApiConstants.MedicationNames.Posology) as JObject;
                    if (posology != null)
                    {
                        var posologyType = posology.SelectToken(MedikitApiConstants.PosologyNames.Type).ToString();
                        if (posologyType != null)
                        {
                            if (posologyType == "freetext")
                            {
                                newMedication.Posology = new AddPosologyFreeTextCommand
                                {
                                    Content = posology.SelectToken(MedikitApiConstants.PosologyNames.Value).ToString()
                                };
                            }
                        }
                    }

                    result.Medications.Add(newMedication);
                }
            }

            return(result);
        }
 public Task <string> AddPrescription(AddPharmaceuticalPrescriptionCommand query, CancellationToken token)
 {
     return(_mediator.Send(query, token));
 }