Skip to content

Commit

Permalink
Merge pull request #36 from ProjectEKA/PHR-761
Browse files Browse the repository at this point in the history
PHR-761 | Mahendra | Storing orgType as list
  • Loading branch information
tw-mahendra authored Aug 26, 2020
2 parents 6717ce5 + 5dff63c commit ca78ce9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> orgAlias;
@Default
private Boolean active=true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Organization {
private List<Identifier> identifier;
private String name;
private boolean active;
private List<OrganizationType> type;
private List<OrganizationType> orgType;
private List<Telecom> telecom;
private List<Address> address;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -91,6 +88,16 @@ private Organization mapRow(ResultSet rs, int rowNum) {
return null;
}

private List<Coding> createList(String orgType) {
String[] stringArr = orgType.split(",");
List<Coding> 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<Organization> organizations = jdbcTemplate.query(
"SELECT org_id, org_name, org_type, active, org_alias, phone, city, state " +
Expand All @@ -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 ";
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@
<column name="state" value="Karnataka"/>
</insert>
</changeSet>
<changeSet id="202024081055" author="mahendra" context="v1">
<update tableName="organization">
<column name="org_type" value="PROV,HIP"/>
</update>
</changeSet>
</databaseChangeLog>

0 comments on commit ca78ce9

Please sign in to comment.