Thanks Ben and Mark, I finally managed to get this working using the shortened code.
Erick On Thu, Mar 29, 2012 at 8:09 PM, Ben Wolfe <[email protected]> wrote: > You need to put the name of the person onto the object you are saving. > > > import org.openmrs.PersonName > p=person.getPerson(1); > > // Create new person name > def pn =new PersonName(); > pn.setGivenName("Given Dummy "); > pn.setFamilyName("Family Dummy"); > // or def pn = new PersonName("Given", "middle name", "Family"); > > // not needed because the savePerson call sets these on the name if they > aren't there > //u=user.getUser(32565); > //pn.setCreator(u); > //pn.setDateCreated(new Date()); > > p.addName(pn); // this is the important step. > person.savePerson(p); > > > All this can be shortened to: > import org.openmrs.PersonName > p = person.getPerson(1); > p.addName(new PersonName("Given", "middle name", "Family")); > person.savePerson(p); > > > Ben > > > > On Thu, Mar 29, 2012 at 11:38 AM, Mark Goodrich <[email protected]> wrote: > >> ** ** >> >> So these are people who are currently Persons in the system, but not >> Patients?**** >> >> ** ** >> >> Looks like you should use the Patient getPatientOrPromotePerson(Integer >> patientOrPersonId) method instead of getPerson, ie:**** >> >> ** ** >> >> p = patient.getPatientOrPromotePerson(1);**** >> >> ** ** >> >> ... same code for adding a person name …**** >> >> ** ** >> >> patient.savePatient(p);**** >> >> ** ** >> >> ** ** >> >> Though this may fail if you don’t also give the patient a patient >> identifier… because I believe each patient requires at least one patient >> identifier.**** >> >> ** ** >> >> Mark**** >> >> ** ** >> >> ** ** >> >> *From:* [email protected] [mailto:[email protected]] *On >> Behalf Of *Erick Mugoma >> *Sent:* Thursday, March 29, 2012 11:03 AM >> *To:* [email protected] >> *Subject:* Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient >> Identifier**** >> >> ** ** >> >> Hi Ben, >> I've the following Groovy code to create person names to specific clients >> who don't have names. >> Here is the code but it is not creating the patient. Any help. Thanks >> >> import org.openmrs.PersonName >> p=person.getPerson(1); >> // Create new person name >> def pn =new PersonName(); >> new_given_name="Given Dummy "; >> new_family_name="Family Dummy"; >> new_middle_name="middle Dummy"; >> >> u=user.getUser(32565); >> pn.setCreator(u); >> pn.setDateCreated(new Date()); >> pn.setGivenName(new_given_name); >> pn.setFamilyName(new_family_name); >> >> person.savePerson(p); >> >> Thanks >> >> Erick >> >> **** >> >> On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[email protected]> >> wrote:**** >> >> Hi Ben, >> Thanks very much. It is important that I know these facts. This is the >> way we want to go since we already implementing Sync and most of our >> database patches and updates. >> >> Thanks >> >> Erick.**** >> >> ** ** >> >> On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[email protected]> wrote:**** >> >> No, you can't use sql there either. The point of using groovy is so that >> the PersonService, PatientService, etc methods are called. Sync uses >> hibernate to know what has changed. So all changes need to be persisted as >> hibernate objects and method calls. When you save a person with >> person.savePerson(px), "person" is the PersonService and "px" is a Person >> object that gets saved via hibernate. >> >> Ben**** >> >> ** ** >> >> On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[email protected]> >> wrote:**** >> >> Thanks Burk and Ben, >> Here is another quick question for you. >> I know it is possible to write direct sql statements in groovy to insert, >> delete or update specific records. When you write direct sql statements are >> these marked for sync or they will be ignored? >> >> Thanks >> >> Erick**** >> >> ** ** >> >> On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[email protected]> >> wrote:**** >> >> Does this work?**** >> >> ** ** >> >> p = person.getPersion(20384)**** >> >> person.unvoidPersion(p)**** >> >> Cheers,**** >> >> ** ** >> >> -Burke**** >> >> ** ** >> >> On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[email protected]> >> wrote:**** >> >> Thanks Ben and Mark. >> The guideline worked fine especially when using the uuid. However I also >> wrote the following code to unvoid the person but it failed. Maybe am using >> the wrong method call?? see the code below: >> >> org.openmrs.Person px = person.getPerson(20384); >> px.setVoided(false); >> px.setVoidReason(""); >> px.setVoidedBy(null); >> person.savePerson(px); >> >> The above code runs successfully but no changes are persisted to the >> database. >> >> Thanks >> >> Erick**** >> >> ** ** >> >> On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[email protected]> wrote:**** >> >> I was going to suggest that Mark, but then looked at the javadocs. Looks >> like there is a PatientService.voidPatientIdentfier(PI, String) method that >> makes this easier >> >> You could do: >> PatientIdentifier pi = >> patient.getPatientIdentifierByUuid("123wf9329349234"); >> patient.voidPatientIdentifier(pi, "because it smells like moldy cheese"); >> >> (assuming "patient" is still aliased to Context.getPatientService()) >> >> See http://api.openmrs.org for latest javadoc. (or >> http://resources.openmrs.org/doc-1.8/ for earlier) >> >> Ben**** >> >> ** ** >> >> On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[email protected]> >> wrote:**** >> >> Erick,**** >> >> **** >> >> I haven’t tested this, but if you know the id of the patient identifier, >> you should be able to do something like this:**** >> >> **** >> >> org.openmrs.PatientIdentifier identifier = >> patient.getPatientIdentifier(123);**** >> >> identifier.setVoided(false);**** >> >> identifier.setVoidReason("");**** >> >> identifier.setVoidedBy(null);**** >> >> patient.savePatientIdentifier(identifier);**** >> >> **** >> >> Take care,**** >> >> Mark**** >> >> **** >> >> *From:* [email protected] [mailto:[email protected]] *On >> Behalf Of *Erick Mugoma >> *Sent:* Monday, March 26, 2012 12:41 AM >> *To:* [email protected] >> *Subject:* [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient >> Identifier**** >> >> **** >> >> Hi >> Can someone show me how to write a simple groovy code that can be used to >> un-void a specific patient Identifier. I don't want to do this using SQL >> since we are running the sync module and I want the changes to be >> propagated to all the children. >> >> Any help will be greatly appreciated. >> >> Thanks >> >> Erick**** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> >> ** ** >> >> ** ** >> ------------------------------ >> >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> **** >> ------------------------------ >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from >> OpenMRS Implementers' mailing list >> > > ------------------------------ > Click here to > unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from > OpenMRS Implementers' mailing list > _________________________________________ To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [email protected] with "SIGNOFF openmrs-implement-l" in the body (not the subject) of your e-mail. [mailto:[email protected]?body=SIGNOFF%20openmrs-implement-l]

