diff --git a/src/main/java/in/org/projecteka/clientregistry/model/BridgeServiceRequest.java b/src/main/java/in/org/projecteka/clientregistry/model/BridgeServiceRequest.java index a8105d7..0b6fb12 100644 --- a/src/main/java/in/org/projecteka/clientregistry/model/BridgeServiceRequest.java +++ b/src/main/java/in/org/projecteka/clientregistry/model/BridgeServiceRequest.java @@ -1,5 +1,6 @@ package in.org.projecteka.clientregistry.model; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Builder.Default; @@ -15,8 +16,8 @@ public class BridgeServiceRequest { private String id; private String name; - @Default - private String type="prov"; + @JsonProperty("serviceType") + private String orgType; private List orgAlias; @Default private Boolean active=true; diff --git a/src/main/java/in/org/projecteka/clientregistry/model/Organization.java b/src/main/java/in/org/projecteka/clientregistry/model/Organization.java index d26df42..ac8c413 100644 --- a/src/main/java/in/org/projecteka/clientregistry/model/Organization.java +++ b/src/main/java/in/org/projecteka/clientregistry/model/Organization.java @@ -16,7 +16,7 @@ public class Organization { private List identifier; private String name; private boolean active; - private List type; + private List orgType; private List telecom; private List
address; } diff --git a/src/main/java/in/org/projecteka/clientregistry/repository/OrganizationRepository.java b/src/main/java/in/org/projecteka/clientregistry/repository/OrganizationRepository.java index 0bc7552..3a7bcb2 100644 --- a/src/main/java/in/org/projecteka/clientregistry/repository/OrganizationRepository.java +++ b/src/main/java/in/org/projecteka/clientregistry/repository/OrganizationRepository.java @@ -13,8 +13,10 @@ import java.sql.ResultSet; import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; @Repository public class OrganizationRepository { @@ -48,13 +50,8 @@ private Organization mapRow(ResultSet rs, int rowNum) { .value(orgId) .use("official") .build(); - Coding orgTypeCode = Coding.builder() - .system("http://hl7.org/fhir/ValueSet/organization-type") - .code(orgType) - .display("Healthcare Provider") - .build(); OrganizationType organizationType = OrganizationType.builder() - .coding(Collections.singletonList(orgTypeCode)) + .coding(createList(orgType)) .build(); Telecom tele = null; @@ -81,7 +78,7 @@ private Organization mapRow(ResultSet rs, int rowNum) { .id(orgId) .identifier(Collections.singletonList(identifier)) .active(active) - .type(Collections.singletonList(organizationType)) + .orgType(Collections.singletonList(organizationType)) .telecom(tele != null ? Collections.singletonList(tele) : null) .address(addr != null ? Collections.singletonList(addr) : null) .build(); @@ -91,6 +88,16 @@ private Organization mapRow(ResultSet rs, int rowNum) { return null; } + private List createList(String orgType) { + String[] stringArr = orgType.split(","); + List codingList = new ArrayList<>(); + for (String code: stringArr) { + codingList.add(Coding.builder().code(code.toUpperCase()).display("Healthcare Provider") + .system("http://hl7.org/fhir/ValueSet/organization-type").build()); + } + return codingList; + } + public Organization find(String id) { List organizations = jdbcTemplate.query( "SELECT org_id, org_name, org_type, active, org_alias, phone, city, state " + @@ -111,7 +118,7 @@ public int addOrUpdateOrganization(BridgeServiceRequest organization) { " date_created, date_modified)" + " VALUES(?,?,?,?,?,?,?,?,?,?)" , organization.getId(), organization.getName(), String.join(",", organization.getOrgAlias()), - organization.getType(), organization.getActive(), organization.getPhone(), organization.getCity(), + organization.getOrgType(), organization.getActive(), organization.getPhone(), organization.getCity(), organization.getState(), LocalDateTime.now(ZoneOffset.UTC), LocalDateTime.now(ZoneOffset.UTC)); } else { String updateOrganizationQuery = "UPDATE organization SET "; @@ -133,6 +140,20 @@ public int addOrUpdateOrganization(BridgeServiceRequest organization) { if (organization.getState() != null) { updateOrganizationQuery += "state = '" + organization.getState() + "', "; } + if (organization.getOrgType() != null) { + var orgList = org.getOrgType() + .stream() + .flatMap(type -> type.getCoding().stream()) + .map(coding -> coding.getCode().toUpperCase()) + .filter(code -> !code.equals(organization.getOrgType())) + .collect(Collectors.joining(",")); + + orgList = !orgList.isEmpty() + ? orgList.concat(",").concat(organization.getOrgType()) + : organization.getOrgType().concat(","); + + updateOrganizationQuery += "org_type = '" +orgList+"', "; + } updateOrganizationQuery += "date_modified = '" + LocalDateTime.now(ZoneOffset.UTC) + "' WHERE org_id = '" + organization.getId() + "'"; return jdbcTemplate.update(updateOrganizationQuery); } diff --git a/src/main/resources/liquibase.xml b/src/main/resources/liquibase.xml index 25290f9..6875763 100644 --- a/src/main/resources/liquibase.xml +++ b/src/main/resources/liquibase.xml @@ -119,4 +119,9 @@ + + + + +