public AddPatientResponse add(AddPatientRequest request) { try { var response = new AddPatientResponse(); var bc = new PatientComponent(); response.Result = bc.Add(request.Patient); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
// JR: this method won't compile anymore since the reconciliation service was moved to the Extended plugins... do we really need it? ///// <summary> ///// Creates a new patient with multiple profiles. ///// </summary> ///// <returns></returns> //public static PatientProfileSummary CreatePatient(String[] InfoAuth) //{ // var result=new List<PatientProfileSummary>(); // if (InfoAuth.Length==0) // result.Add(CreatePatient()); // else // { // var timespan = new TimeSpan(GetRandomInteger(0,100 * 365 * 24), 0, 0); // InitReferenceDataCacheOnce(); // var birthDate = Platform.Time - timespan; // var profile = new PatientProfileDetail // { // Healthcard = new HealthcardDetail( // GenerateRandomIntegerString(10), // ChooseRandom(_patientEditorFormData.HealthcardAssigningAuthorityChoices), // "", null), // DateOfBirth = birthDate, // Sex = ChooseRandom(_patientEditorFormData.SexChoices), // PrimaryLanguage = ChooseRandom(_patientEditorFormData.PrimaryLanguageChoices), // Religion = ChooseRandom(_patientEditorFormData.ReligionChoices), // DeathIndicator = false, // TimeOfDeath = null // }; // profile.Name = new PersonNameDetail // { // FamilyName = GetRandomNameFromFile(RandomUtilsSettings.Default.FamilyNameDictionary), // GivenName = profile.Sex.Code == "F" // ? GetRandomNameFromFile(RandomUtilsSettings.Default.FemaleNameDictionary) + " Anonymous" // : GetRandomNameFromFile(RandomUtilsSettings.Default.MaleNameDictionary) + " Anonymous" // }; // AddPatientResponse addResponse = null; // for(var i=0; i<InfoAuth.Length; i++) // { // profile.Mrn = new CompositeIdentifierDetail( // GenerateRandomIntegerString(10), // CollectionUtils.SelectFirst(_patientEditorFormData.MrnAssigningAuthorityChoices, MAAC => MAAC.Code == InfoAuth[i])); // Platform.GetService( // delegate(IPatientAdminService service) // { // addResponse = service.AddPatient(new AddPatientRequest(profile)); // }); // result.Add(addResponse.PatientProfile); // } // if (InfoAuth.Length > 1) // { // //reconcile patients // var checkedPatients = new List<EntityRef>(); // foreach (var pps in result) // { // checkedPatients.Add(pps.PatientRef); // } // // reconcile // Platform.GetService<IPatientReconciliationService>( // service => service.ReconcilePatients(new ReconcilePatientsRequest(checkedPatients))); // } // } // return result[0]; //} /// <summary> /// Creates a new patient with a single profile. /// </summary> /// <returns></returns> public static PatientProfileSummary CreatePatient() { var timespan = new TimeSpan(GetRandomInteger(0, 100 * 365 * 24), 0, 0); InitReferenceDataCacheOnce(); var birthDate = Platform.Time - timespan; var profile = new PatientProfileDetail { Mrn = new CompositeIdentifierDetail( GenerateRandomIntegerString(10), ChooseRandom(_patientEditorFormData.MrnAssigningAuthorityChoices)), Healthcard = new HealthcardDetail( GenerateRandomIntegerString(10), ChooseRandom(_patientEditorFormData.HealthcardAssigningAuthorityChoices), "", null), DateOfBirth = birthDate, Sex = ChooseRandom(_patientEditorFormData.SexChoices), PrimaryLanguage = ChooseRandom(_patientEditorFormData.PrimaryLanguageChoices), Religion = ChooseRandom(_patientEditorFormData.ReligionChoices), DeathIndicator = false, TimeOfDeath = null }; // Randomly create 0-2 allergies for (var i = 0; i < GetRandomInteger(0, 2); i++) { var allergy = new PatientAllergyDetail( ChooseRandom(_patientEditorFormData.AllergenTypeChoices), string.Format("description {0}", GenerateRandomString(3)), ChooseRandom(_patientEditorFormData.AllergySeverityChoices), string.Format("reaction {0}", GenerateRandomString(3)), ChooseRandom(_patientEditorFormData.AllergySensitivityTypeChoices), Platform.Time, Platform.Time, new PersonNameDetail { FamilyName = GetRandomNameFromFile(RandomUtilsSettings.Default.FamilyNameDictionary), GivenName = GetRandomNameFromFile(RandomUtilsSettings.Default.MaleNameDictionary) + " Anonymous" }, ChooseRandom(_patientEditorFormData.PersonRelationshipTypeChoices)); profile.Allergies.Add(allergy); } profile.Name = new PersonNameDetail { FamilyName = GetRandomNameFromFile(RandomUtilsSettings.Default.FamilyNameDictionary), GivenName = profile.Sex.Code == "F" ? GetRandomNameFromFile(RandomUtilsSettings.Default.FemaleNameDictionary) + " Anonymous" : GetRandomNameFromFile(RandomUtilsSettings.Default.MaleNameDictionary) + " Anonymous" }; AddPatientResponse addResponse = null; Platform.GetService( delegate(IPatientAdminService service) { addResponse = service.AddPatient(new AddPatientRequest(profile)); }); return(addResponse.PatientProfile); }