Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BahmniPatientProfileResourceTest#updatePatient() fails when actually adding relationships #68

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -47,14 +55,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* Controller for REST web service access to
* the Search resource.
Expand Down Expand Up @@ -154,18 +154,18 @@ private ResponseEntity<Object> getIdentifierErrorMessageResponseEntity() throws
@RequestMapping(method = RequestMethod.POST, value = "/{uuid}")
@ResponseBody
public ResponseEntity<Object> update(@PathVariable("uuid") String uuid, @RequestBody SimpleObject propertiesToUpdate) throws Exception {
PatientProfile delegate = null;
PatientProfile patientProfile = null;
try {
delegate = mapForUpdatePatient(uuid, propertiesToUpdate);
patientProfile = mapForUpdatePatient(uuid, propertiesToUpdate);
} catch (APIAuthenticationException e) {
return new ResponseEntity<Object>(RestUtil.wrapErrorResponse(e, "User is logged in but doesn't have the relevant privilege "), HttpStatus.FORBIDDEN);
}
setConvertedProperties(delegate, propertiesToUpdate, getUpdatableProperties(), true);
delegate.setRelationships(getRelationships(propertiesToUpdate, delegate.getPatient()));
setConvertedProperties(patientProfile, propertiesToUpdate, getUpdatableProperties(), true);
patientProfile.setRelationships(getRelationships(propertiesToUpdate, patientProfile.getPatient()));
try {
delegate = emrPatientProfileService.save(delegate);
setRelationships(delegate);
return new ResponseEntity<>(ConversionUtil.convertToRepresentation(delegate, Representation.FULL), HttpStatus.OK);
patientProfile = emrPatientProfileService.save(patientProfile);
setRelationships(patientProfile);
return new ResponseEntity<>(ConversionUtil.convertToRepresentation(patientProfile, Representation.FULL), HttpStatus.OK);
} catch (ContextAuthenticationException e) {
return new ResponseEntity<Object>(RestUtil.wrapErrorResponse(e, e.getMessage()), HttpStatus.FORBIDDEN);
} catch (ValidationException e) {
Expand Down Expand Up @@ -203,11 +203,11 @@ private PatientProfile mapForCreatePatient(SimpleObject propertiesToCreate) {
}

private PatientProfile mapForUpdatePatient(String uuid, SimpleObject propertiesToUpdate) {
if (propertiesToUpdate.get("patient") == null || !(propertiesToUpdate.get("patient") instanceof Map)) {
if (propertiesToUpdate.get("patient") == null || !(propertiesToUpdate.get("patient") instanceof Map)) {
throw new ConversionException("The patient property is missing");
}

PatientProfile delegate = new PatientProfile();
PatientProfile patientProfile = new PatientProfile();

PatientResource1_8 patientResource1_9 = (PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass(Patient.class);
Patient patient = patientResource1_9.getPatientForUpdate(uuid, (Map<String, Object>) propertiesToUpdate.get("patient"));
Expand All @@ -219,10 +219,10 @@ private PatientProfile mapForUpdatePatient(String uuid, SimpleObject propertiesT
PatientIdentifier patientIdentifier = (PatientIdentifier) ConversionUtil.convert(identifierProperties, PatientIdentifier.class);
patient.addIdentifier(patientIdentifier);
}
delegate.setPatient(patient);
patientProfile.setPatient(patient);

propertiesToUpdate.removeProperty("patient");
return delegate;
return patientProfile;
}

private List<Relationship> getRelationships(SimpleObject propertiesToCreate, Person currentPerson) {
Expand Down
Loading