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

Khp3 5332 nupi endpoint 3.x #1853

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added CORS fix
  • Loading branch information
PatrickWaweru committed Apr 5, 2024
commit 9ba7046917d7b0487548a4f591143c9fd39fac8c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
@Component
public class CommonMetadata extends AbstractMetadataBundle {

public static final String GP_CLIENT_VERIFICATION_USE_EMR_PROXY = "kenyaemr.client.registry.use.emr.proxy";
public static final String GP_CLIENT_VERIFICATION_EMR_VERIFICATION_PROXY_URL = "kenyaemr.client.registry.emr.verification.proxy.url";
public static final String GP_CLIENT_VERIFICATION_GET_END_POINT = "kenyaemr.client.registry.get.api";
public static final String GP_CLIENT_VERIFICATION_POST_END_POINT = "kenyaemr.client.registry.post.api";
public static final String GP_CLIENT_VERIFICATION_API_TOKEN = "kenyaemr.client.registry.api.token";
Expand Down Expand Up @@ -230,6 +232,12 @@ public void install() {
install(globalProperty("client_number_label", "Label for Client Number", "Client Number"));
install(globalProperty("clientNumber.enabled", "Switch to show client number", "false"));

if(Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_USE_EMR_PROXY) == null) {
install(globalProperty(GP_CLIENT_VERIFICATION_USE_EMR_PROXY, "Use the EMR backend to proxy NUPI requests (true or false)", "false"));
}
if(Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_EMR_VERIFICATION_PROXY_URL) == null) {
install(globalProperty(GP_CLIENT_VERIFICATION_EMR_VERIFICATION_PROXY_URL, "The local EMR URL to proxy NUPI verification requests", "http:https://127.0.0.1:8080/openmrs/ws/rest/v1/kenyaemr/verifynupi"));
}
if(Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_GET_END_POINT) == null) {
install(globalProperty(GP_CLIENT_VERIFICATION_GET_END_POINT, "A GET API for getting client information at the client registry", "https://afyakenyaapi.health.go.ke/partners/registry/search"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.xml.sax.SAXException;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -2687,6 +2688,7 @@ public List<org.openmrs.module.webservices.rest.SimpleObject> search(@RequestPar
* Verify NUPI exists (EndPoint)
* @return
*/
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS})
@RequestMapping(method = RequestMethod.GET, value = "/verifynupi/{country}/{identifierType}/{identifier}")
@ResponseBody
public Object verifyNUPI(@PathVariable String country, @PathVariable String identifierType, @PathVariable String identifier) {
Expand Down Expand Up @@ -2764,8 +2766,8 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden
} else {
headers.setContentType(MediaType.TEXT_PLAIN);
}
return new ResponseEntity<>(errorBody, headers, responseCode);
// return ResponseEntity.badRequest().body("{\"status\": \"Error\"}");

return ResponseEntity.status(responseCode).headers(headers).body(errorBody);
}
} catch(Exception ex) {
System.err.println("NUPI verification: ERROR: " + ex.getMessage());
Expand All @@ -2779,6 +2781,7 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden
* Search for NUPI (EndPoint)
* @return
*/
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS})
@RequestMapping(method = RequestMethod.GET, value = "/searchnupi/{searchkey}/{searchvalue}")
@ResponseBody
public Object searchNUPI(@PathVariable String searchkey, @PathVariable String searchvalue) {
Expand Down Expand Up @@ -2855,7 +2858,8 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se
} else {
headers.setContentType(MediaType.TEXT_PLAIN);
}
return new ResponseEntity<>(errorBody, headers, responseCode);

return ResponseEntity.status(responseCode).headers(headers).body(errorBody);
}
} catch(Exception ex) {
System.err.println("NUPI search: ERROR: " + ex.getMessage());
Expand All @@ -2870,6 +2874,7 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se
* @param request
* @return
*/
@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.OPTIONS})
@RequestMapping(method = RequestMethod.POST, value = "/newnupi")
@ResponseBody
public Object newNUPI(HttpServletRequest request) {
Expand Down Expand Up @@ -2963,7 +2968,8 @@ public Object newNUPI(HttpServletRequest request) {
} else {
headers.setContentType(MediaType.TEXT_PLAIN);
}
return new ResponseEntity<>(errorBody, headers, responseCode);

return ResponseEntity.status(responseCode).headers(headers).body(errorBody);
}
} catch(Exception ex) {
System.err.println("New NUPI: ERROR: " + ex.getMessage());
Expand All @@ -2978,6 +2984,7 @@ public Object newNUPI(HttpServletRequest request) {
* @param request
* @return
*/
@CrossOrigin(origins = "*", methods = {RequestMethod.PUT, RequestMethod.OPTIONS})
@RequestMapping(method = RequestMethod.PUT, value = "/modifynupi/{nupinumber}/{searchtype}")
@ResponseBody
public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinumber, @PathVariable String searchtype) {
Expand Down Expand Up @@ -3072,7 +3079,8 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu
} else {
headers.setContentType(MediaType.TEXT_PLAIN);
}
return new ResponseEntity<>(errorBody, headers, responseCode);

return ResponseEntity.status(responseCode).headers(headers).body(errorBody);
}
} catch(Exception ex) {
System.err.println("Modify NUPI: ERROR: " + ex.getMessage());
Expand Down