@Override public Patient savePatient(Patient patient) { final org.openmrs.Patient openMRSPatient = patientHelper.buildOpenMrsPatient( patient, userService.generateSystemId(), getPatientIdentifierType(IdentifierType.IDENTIFIER_MOTECH_ID), facilityAdaptor.getLocation(patient.getFacility().getId()), getAllPersonAttributeTypes()); return getMrsPatient(patientService.savePatient(openMRSPatient)); }
private Patient getMrsPatient(org.openmrs.Patient savedPatient) { final List<Attribute> attributes = project( savedPatient.getAttributes(), Attribute.class, on(PersonAttribute.class).getAttributeType().toString(), on(PersonAttribute.class).getValue()); PersonName firstName = patientHelper.getFirstName(savedPatient); final PatientIdentifier patientIdentifier = savedPatient.getPatientIdentifier(); return new Patient( String.valueOf(savedPatient.getId()), firstName.getGivenName(), firstName.getMiddleName(), firstName.getFamilyName(), patientHelper.getPreferredName(savedPatient), savedPatient.getBirthdate(), savedPatient.getBirthdateEstimated(), savedPatient.getGender(), patientHelper.getAddress(savedPatient), attributes, (patientIdentifier != null) ? facilityAdaptor.convertLocationToFacility(patientIdentifier.getLocation()) : null); }