Skip to content

Commit

Permalink
Fix issues after first review
Browse files Browse the repository at this point in the history
  • Loading branch information
bmonjoie committed Jul 25, 2023
1 parent 2dcd53c commit 27aaf5a
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 74 deletions.
Expand Up @@ -169,8 +169,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
}));
}),
() -> {
},
() -> progressDialog.dismiss(),
500
);
});
Expand Down Expand Up @@ -447,7 +446,7 @@ private void fillClaimFromRestore(Claim claim) {
item.put("Name", medication.getName());
item.put("Code", medication.getCode());
item.put("Price", String.valueOf(medication.getPrice()));
item.put("Quantity", "item_qty"); // TODO item_qty
item.put("Quantity", medication.getQuantity());
lvItemList.add(item);
}

Expand All @@ -459,7 +458,7 @@ private void fillClaimFromRestore(Claim claim) {
item.put("Name", service.getName());
item.put("Code", service.getCode());
item.put("Price", String.valueOf(service.getPrice()));
item.put("Quantity", "item_qty"); // TODO item_qty
item.put("Quantity", service.getQuantity());
lvServiceList.add(item);
}
tvServiceTotal.setText(String.valueOf(lvServiceList.size()));
Expand Down
Expand Up @@ -11,7 +11,6 @@

public class ItemAdapter extends CursorAdapter {
SQLHandler sqlHandler;
SQLiteDatabase db;

public ItemAdapter(Context context, SQLHandler sqlHandler) {
super(context, null, 0);
Expand Down
Expand Up @@ -78,10 +78,10 @@ public void onBindViewHolder(Reportmsg holder, int position) {

holder.ItemCode.setText(medication.getCode());
holder.ItemName.setText(medication.getName());
holder.Quantity.setText(null); // TODO item_qty
holder.Quantity.setText(medication.getQuantity());
holder.Price.setText(String.valueOf(medication.getPrice()));
holder.Explanation.setText(medication.getExplanation());
holder.AppQty.setText(null); // TODO item_adjusted_qty
holder.AppQty.setText(medication.getQuantityApproved());
holder.AppPrice.setText(medication.getPriceAdjusted());
holder.Justification.setText(medication.getJustification());
holder.Status.setText(""); // previous code took the status from the claim then got commented out
Expand Down
Expand Up @@ -79,17 +79,15 @@ public void onBindViewHolder(Reportmsg holder, int position) {

holder.ServiceCode.setText(service.getCode());
holder.ServiceName.setText(service.getName());
holder.Quantity.setText(null); //TODO service_qty
holder.Quantity.setText(service.getQuantity());
holder.Price.setText(String.valueOf(service.getPrice()));
holder.Explanation.setText(service.getExplanation());
holder.AppQty.setText(null); // TODO service_adjusted_qty
holder.AppQty.setText(service.getQuantityApproved());
holder.AppPrice.setText(service.getPriceAdjusted());
holder.Justification.setText(service.getJustification());
holder.Status.setText(""); // previous code took the status from the claim then got commented out
holder.Valuated.setText(service.getPriceValuated());
holder.Result.setText(null); // TODO service_result


}

@Override
Expand Down
Expand Up @@ -113,6 +113,7 @@ private void handleUploadClaims() {
JSONArray claimStatus = processClaimResponse(results);
broadcastSyncSuccess(claimStatus);
} catch (Exception e) {
e.printStackTrace();
broadcastError(getResources().getString(R.string.ErrorOccurred) + ": " + e.getMessage(), ACTION_UPLOAD_CLAIMS);
}
}
Expand Down
Expand Up @@ -64,10 +64,6 @@ public class Claim implements Parcelable {

@Nullable
private final Double approved;

@Nullable
private final Double adjusted;

@Nullable
private final String explanation;

Expand Down Expand Up @@ -103,7 +99,6 @@ public Claim(
@Nullable String secDg4,
@Nullable Double claimed,
@Nullable Double approved,
@Nullable Double adjusted,
@Nullable String explanation,
@Nullable String adjustment,
@Nullable String guaranteeNumber,
Expand All @@ -128,7 +123,6 @@ public Claim(
this.secDg4 = secDg4;
this.claimed = claimed;
this.approved = approved;
this.adjusted = adjusted;
this.explanation = explanation;
this.adjustment = adjustment;
this.guaranteeNumber = guaranteeNumber;
Expand Down Expand Up @@ -159,11 +153,6 @@ protected Claim(Parcel in) {
} else {
approved = in.readDouble();
}
if (in.readByte() == 0) {
adjusted = null;
} else {
adjusted = in.readDouble();
}
explanation = in.readString();
adjustment = in.readString();
guaranteeNumber = in.readString();
Expand Down Expand Up @@ -218,12 +207,6 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) 1);
dest.writeDouble(approved);
}
if (adjusted == null) {
dest.writeByte((byte) 0);
} else {
dest.writeByte((byte) 1);
dest.writeDouble(adjusted);
}
dest.writeString(explanation);
dest.writeString(adjustment);
dest.writeString(guaranteeNumber);
Expand Down Expand Up @@ -353,7 +336,35 @@ public Double getApproved() {

@Nullable
public Double getAdjusted() {
return adjusted;
try {
double adjusted = -1.0;
for (Service service : services) {
if (service.priceAdjusted != null) {
double value = Double.parseDouble(service.priceAdjusted);
if (adjusted < 0) {
adjusted = value;
} else {
adjusted += value;
}
}
}
for (Medication medication : medications) {
if (medication.priceAdjusted != null) {
double value = Double.parseDouble(medication.priceAdjusted);
if (adjusted < 0) {
adjusted = value;
} else {
adjusted += value;
}
}
}
if (adjusted < 0) {
return null;
}
return adjusted;
} catch (NumberFormatException e) {
return null;
}
}

@Nullable
Expand Down Expand Up @@ -455,6 +466,11 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(justification);
}

@NonNull
public String getQuantity() {
return getQuantityApproved() == null ? getQuantityProvided() : getQuantityApproved();
}

@NonNull
public String getQuantityProvided() {
return quantityProvided;
Expand Down Expand Up @@ -560,6 +576,11 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(justification);
}

@NonNull
public String getQuantity() {
return getQuantityApproved() == null ? getQuantityProvided() : getQuantityApproved();
}

@NonNull
public String getQuantityProvided() {
return quantityProvided;
Expand Down
Expand Up @@ -42,11 +42,15 @@ public static List<PractitionerDto> fromJson(@NonNull JSONObject jsonObject) thr
}
}
}
Date birthDate = null;
if (entry.has("birthDate")) {
birthDate = DateUtils.dateFromString(entry.getString("birthDate"));
}
list.add(
new PractitionerDto(
/* id = */ entry.getString("id"),
/* identifiers = */ IdentifierDto.fromJson(entry.getJSONArray("identifier")),
/* birthDate = */ Objects.requireNonNull(DateUtils.dateFromString(entry.getString("birthDate"))),
/* birthDate = */ birthDate,
/* names = */ Name.fromJson(entry.getJSONArray("name")),
/* qualifications = */ qualifications,
/* healthFacilityCode = */ healthFacilityCode
Expand All @@ -60,7 +64,7 @@ public static List<PractitionerDto> fromJson(@NonNull JSONObject jsonObject) thr
private final String id;
@NonNull
private final List<IdentifierDto> identifiers;
@NonNull
@Nullable
private final Date birthDate;
@NonNull
private final List<Name> names;
Expand All @@ -72,7 +76,7 @@ public static List<PractitionerDto> fromJson(@NonNull JSONObject jsonObject) thr
public PractitionerDto(
@NonNull String id,
@NonNull List<IdentifierDto> identifiers,
@NonNull Date birthDate,
@Nullable Date birthDate,
@NonNull List<Name> names,
@NonNull List<CodeDto> qualifications,
@Nullable String healthFacilityCode
Expand All @@ -95,7 +99,7 @@ public List<IdentifierDto> getIdentifiers() {
return identifiers;
}

@NonNull
@Nullable
public Date getBirthDate() {
return birthDate;
}
Expand Down
Expand Up @@ -38,15 +38,15 @@ public U post(T object, @Nullable Map<String, String> queryParameters) throws Ex
JSONObject entity = toJson(object);
builder.post(RequestBody.create(entity.toString(), JSON));
try (Response response = okHttpClient.newCall(builder.build()).execute()) {
ResponseBody body = response.body();
String bodyString = body != null ? body.string() : null;
if (response.isSuccessful()) {
ResponseBody body = response.body();
String bodyString = body != null ? body.string() : null;
if (bodyString == null) {
throw new RuntimeException("Call was successful but body was null");
}
return fromJson(new JSONObject(bodyString));
} else {
throw new HttpException(response.code(), response.message(), null);
throw new HttpException(response.code(), response.message()+": "+bodyString, null);
}
}
}
Expand Down
Expand Up @@ -48,8 +48,8 @@ protected JSONObject toJson(PendingClaim object) throws JSONException {
JSONObject type = new JSONObject();
JSONObject coding = new JSONObject();
coding.put("system", "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem-claim-visit-type.html");
coding.put("code", getVisitTypeCode(object.getVisitType()));
coding.put("display", object.getVisitType());
coding.put("code", object.getVisitType());
coding.put("display", getVisitTypeCode(object.getVisitType()));
type.put("coding", wrapInArray(coding));
jsonObject.put("type", type);
JSONObject identifier = new JSONObject();
Expand All @@ -59,36 +59,36 @@ protected JSONObject toJson(PendingClaim object) throws JSONException {
typeIdentifierCoding.put("system", "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers");
typeIdentifierCoding.put("code", "Code");
typeIdentifierCodings.put(typeIdentifierCoding);
type.put("coding", typeIdentifierCodings);
typeIdentifier.put("coding", typeIdentifierCodings);
identifier.put("type", typeIdentifier);
identifier.put("value", object.getClaimCode());
jsonObject.put("identifier", wrapInArray(identifier));
JSONArray diagnoses = new JSONArray();
int sequence = 1;
diagnoses.put(getDiagnosisJson(object.getIcdCode(), sequence++));
if (object.getIcdCode1() != null) {
if (object.getIcdCode1() != null && !Objects.equals(object.getIcdCode1(), "")) {
diagnoses.put(getDiagnosisJson(object.getIcdCode1(), sequence++));
}
if (object.getIcdCode2() != null) {
if (object.getIcdCode2() != null && !Objects.equals(object.getIcdCode2(), "")) {
diagnoses.put(getDiagnosisJson(object.getIcdCode2(), sequence++));
}
if (object.getIcdCode3() != null) {
if (object.getIcdCode3() != null && !Objects.equals(object.getIcdCode3(), "")) {
diagnoses.put(getDiagnosisJson(object.getIcdCode3(), sequence++));
}
if (object.getIcdCode4() != null) {
if (object.getIcdCode4() != null && !Objects.equals(object.getIcdCode4(), "")) {
diagnoses.put(getDiagnosisJson(object.getIcdCode4(), sequence));
}
jsonObject.put("diagnosis", diagnoses);
JSONObject enterer = new JSONObject();
enterer.put("reference", "Practitioner/"+object.getClaimAdminCode());
jsonObject.put("enterer", enterer);
JSONObject insurance = new JSONObject();
JSONObject coverage = new JSONObject();
coverage.put("reference", "Coverage/"+object.getGuaranteeNumber());
insurance.put("coverage", coverage);
insurance.put( "focal",true);
insurance.put( "sequence", 1);
jsonObject.put("insurance", wrapInArray(insurance));
if (object.getClaimAdminCode() != null && !Objects.equals(object.getClaimAdminCode(), "")) {
jsonObject.put("enterer", code("Practitioner", object.getClaimAdminCode()));
}
if (object.getGuaranteeNumber() != null && !Objects.equals(object.getGuaranteeNumber(), "")) {
JSONObject insurance = new JSONObject();
insurance.put("coverage", code("Coverage", object.getGuaranteeNumber()));
insurance.put( "focal",true);
insurance.put( "sequence", 1);
jsonObject.put("insurance", wrapInArray(insurance));
}
JSONArray items = new JSONArray();
sequence = 1;
double total = 0;
Expand All @@ -101,17 +101,13 @@ protected JSONObject toJson(PendingClaim object) throws JSONException {
total += service.getPrice();
}
jsonObject.put("item", items);
JSONObject patient = new JSONObject();
patient.put("reference", "Patient/"+object.getChfId());
jsonObject.put("patient", patient);
jsonObject.put("patient", code("Patient", object.getChfId()));
JSONObject priority = new JSONObject();
JSONObject priorityCoding = new JSONObject();
priorityCoding.put("code", "normal");
priority.put("coding", wrapInArray(priorityCoding));
jsonObject.put("priority", priority);
JSONObject provider = new JSONObject();
provider.put("reference", "Organization/"+object.getHealthFacilityCode());
jsonObject.put("provider", provider);
jsonObject.put("provider", code("Organization", object.getHealthFacilityCode()));
jsonObject.put("status", "active");
JSONObject totalJson = new JSONObject();
totalJson.put("currency", "$");
Expand All @@ -124,12 +120,12 @@ protected JSONObject toJson(PendingClaim object) throws JSONException {
@NonNull
private String getVisitTypeCode(@NonNull String type) {
switch (type) {
case "Emergency":
return "E";
case "Referrals":
return "R";
case "Other":
return "O";
case "E":
return "Emergency";
case "R":
return "Referral";
case "O":
return "Other";
default:
throw new IllegalArgumentException("Type '" + type + "' is unknown");
}
Expand All @@ -156,9 +152,7 @@ private JSONObject toJson(@NonNull PendingClaim.Medication medication, int seque
object.put("category", category);
JSONObject extension = new JSONObject();
extension.put("url", "Medication");
JSONObject reference = new JSONObject();
reference.put("reference", "Medication/"+medication.getCode());
extension.put("valueReference", reference);
extension.put("valueReference", code("Medication", medication.getCode()));
object.put("extension", wrapInArray(extension));
JSONObject productOrService = new JSONObject();
productOrService.put("text", medication.getCode());
Expand All @@ -182,9 +176,7 @@ private JSONObject toJson(@NonNull PendingClaim.Service service, int sequence) t
object.put("category", category);
JSONObject extension = new JSONObject();
extension.put("url", "ActivityDefinition");
JSONObject reference = new JSONObject();
reference.put("reference", "ActivityDefinition/"+service.getCode());
extension.put("valueReference", reference);
extension.put("valueReference", code("ActivityDefinition", service.getCode()));
object.put("extension", wrapInArray(extension));
JSONObject productOrService = new JSONObject();
productOrService.put("text", service.getCode());
Expand All @@ -206,4 +198,20 @@ private JSONArray wrapInArray(@NonNull JSONObject jsonObject){
array.put(jsonObject);
return array;
}

@NonNull
private JSONObject code(@NonNull String type, @NonNull String code) throws JSONException {
JSONObject json = new JSONObject();
json.put("type", type);
JSONObject identifier = new JSONObject();
identifier.put("value", code);
JSONObject jsonType = new JSONObject();
JSONObject coding = new JSONObject();
coding.put("system", "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers");
coding.put("code", "Code");
jsonType.put("coding", wrapInArray(coding));
identifier.put("type", jsonType);
json.put("identifier", identifier);
return json;
}
}

0 comments on commit 27aaf5a

Please sign in to comment.